Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
jpeng-ms committed Dec 5, 2022
1 parent c435948 commit a71ca30
Show file tree
Hide file tree
Showing 21 changed files with 747 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

FluentTest/.DS_Store
.DS_Store
422 changes: 422 additions & 0 deletions FluentTest.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>FluentTest.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>3</integer>
</dict>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>FluentTest.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>3</integer>
</dict>
</dict>
</dict>
</plist>
10 changes: 10 additions & 0 deletions FluentTest.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions FluentTest.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "0A82325C-1245-4E22-8070-570F90885062"
type = "0"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.SwiftErrorBreakpoint">
<BreakpointContent
uuid = "441D8BB3-2971-41DF-A898-48E3F6929C65"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.ExceptionBreakpoint">
<BreakpointContent
uuid = "C1D25B71-501D-48C5-B42A-F6638160ED76"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
breakpointStackSelectionBehavior = "1"
scope = "1"
stopOnStyle = "0">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.ExceptionBreakpoint">
<BreakpointContent
uuid = "856736C2-2F65-41E3-BD8F-CDEB32A8EC7D"
shouldBeEnabled = "Yes"
condition = "-[NSObject(NSObject) doesNotRecognizeSelector:]"
ignoreCount = "0"
continueAfterRunningActions = "No"
breakpointStackSelectionBehavior = "1"
scope = "1"
stopOnStyle = "0">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "23658206-1476-4583-8EA1-4FCFC79290EC"
type = "0"
version = "2.0">
</Bucket>
11 changes: 11 additions & 0 deletions FluentTest/Assets.xcassets/AccentColor.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
13 changes: 13 additions & 0 deletions FluentTest/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions FluentTest/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
25 changes: 25 additions & 0 deletions FluentTest/AvatarGroupContainer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
//  Copyright (c) Microsoft Corporation. All rights reserved.
//  Licensed under the MIT License.
//

import SwiftUI

struct AvatarGroupContainer: UIViewRepresentable {

var participantList: [ParticipantInfoModel]
var avatarGroup: ParticipantAvatarGroup

func makeUIView(context: Context) -> ParticipantAvatarGroup {
avatarGroup.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
return avatarGroup
}

func updateUIView(_ uiView: ParticipantAvatarGroup, context: Context) {
avatarGroup.setAvatars(to: participantList)
}
}

struct ParticipantInfoModel {
var displayName: String
}
64 changes: 64 additions & 0 deletions FluentTest/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// ContentView.swift
// FluentTest
//
// Created by Emlyn Bolton-Maggs on 2022-11-08.
//

import SwiftUI

struct ContentView: View {
@ObservedObject var viewmodel = ViewModel()

var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundColor(.accentColor)
Text("Hello, world!")
AvatarGroupContainer(participantList: viewmodel.participants,
avatarGroup: viewmodel.avatarGroup)
}
.padding()
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 1.9, execute: {
viewmodel.participants = [
ParticipantInfoModel(displayName: "pp"),
ParticipantInfoModel(displayName: "sd"),
ParticipantInfoModel(displayName: "jj"),
ParticipantInfoModel(displayName: "jm"),
ParticipantInfoModel(displayName: "jd"),
ParticipantInfoModel(displayName: "jq")
]
})
DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
viewmodel.participants = [
ParticipantInfoModel(displayName: "jj"),
ParticipantInfoModel(displayName: "jm"),
ParticipantInfoModel(displayName: "jd"),
ParticipantInfoModel(displayName: "jq")
]
})
DispatchQueue.main.asyncAfter(deadline: .now() + 2.1, execute: {
viewmodel.participants = [
ParticipantInfoModel(displayName: "oo"),
ParticipantInfoModel(displayName: "oo"),
]
})
}
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}

class ViewModel: ObservableObject {
var avatarGroup = ParticipantAvatarGroup()
@Published var participants: [ParticipantInfoModel] = [
ParticipantInfoModel(displayName: "oo"),
ParticipantInfoModel(displayName: "oo"),
]
}
17 changes: 17 additions & 0 deletions FluentTest/FluentTestApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// FluentTestApp.swift
// FluentTest
//
// Created by Emlyn Bolton-Maggs on 2022-11-08.
//

import SwiftUI

@main
struct FluentTestApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
71 changes: 71 additions & 0 deletions FluentTest/ParticipantAvatarGroup.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
//  Copyright (c) Microsoft Corporation. All rights reserved.
//  Licensed under the MIT License.
//

import FluentUI
import UIKit

class ParticipantAvatarGroup: UIView {

private var group: MSFAvatarGroup?
private var lastSeen: [ParticipantInfoModel]?
private var avatarCount: Int = 0

private enum Constants {
static let avatarWidth: CGFloat = 16.0
static let maxAvatarAllowed: Int = 2
static let overflowCount: Int = 0
}

override init(frame: CGRect) {
super.init(frame: frame)
initAvatarGroup()
}

required init?(coder: NSCoder) {
super.init(coder: coder)
initAvatarGroup()
}

}

extension ParticipantAvatarGroup {
private func initAvatarGroup() {
group = MSFAvatarGroup(style: .stack, size: .xsmall)
guard let group = group else {
return
}
group.state.overflowCount = Constants.overflowCount
// total avatar shown would be 3
// (max allowed 2 + 1 to show number of remaining participants)
group.state.maxDisplayedAvatars = Constants.maxAvatarAllowed
group.isAccessibilityElement = false
addSubview(group)
group.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
group.leftAnchor.constraint(equalTo: self.leftAnchor),
group.rightAnchor.constraint(equalTo: self.rightAnchor),
group.topAnchor.constraint(equalTo: self.topAnchor),
group.bottomAnchor.constraint(equalTo: self.bottomAnchor)
])
}

func setAvatars(to newData: [ParticipantInfoModel]) {
guard let group = group else {
return
}
for _ in 0..<avatarCount {
group.state.removeAvatar(at: 0)
}
avatarCount = 0
for participant in newData {
avatarCount += 1
let newAvatar = group.state.createAvatar()
newAvatar.primaryText = participant.displayName
newAvatar.isTransparent = false
newAvatar.isRingVisible = false
}
lastSeen = newData
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}

0 comments on commit a71ca30

Please sign in to comment.