-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Add Chat Typing Indicator (#399)
- Loading branch information
Showing
30 changed files
with
592 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...municationUIChat/Sources/Presentation/FluentUI/Wrapper/TypingParticipantAvatarGroup.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
// | ||
|
||
import FluentUI | ||
import UIKit | ||
|
||
class TypingParticipantAvatarGroup: UIView { | ||
|
||
private var group = MSFAvatarGroup(style: .stack, size: .xsmall) | ||
|
||
var avatars: [ParticipantInfoModel] = [] { | ||
didSet { | ||
setAvatars(data: avatars) | ||
} | ||
} | ||
|
||
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 TypingParticipantAvatarGroup { | ||
private func initAvatarGroup() { | ||
group.state.overflowCount = Constants.overflowCount | ||
group.state.style = .stack | ||
// Max avatar shown would be 3 | ||
group.state.maxDisplayedAvatars = Constants.maxAvatarAllowed | ||
group.isAccessibilityElement = false | ||
addSubview(group.view) | ||
group.view.translatesAutoresizingMaskIntoConstraints = false | ||
NSLayoutConstraint.activate([ | ||
group.view.leftAnchor.constraint(equalTo: self.leftAnchor), | ||
group.view.rightAnchor.constraint(equalTo: self.rightAnchor), | ||
group.view.topAnchor.constraint(equalTo: self.topAnchor), | ||
group.view.bottomAnchor.constraint(equalTo: self.bottomAnchor) | ||
]) | ||
} | ||
|
||
private func setAvatars(data: [ParticipantInfoModel]) { | ||
for participant in data { | ||
let newAvatar = group.state.createAvatar() | ||
newAvatar.primaryText = participant.displayName | ||
newAvatar.isTransparent = false | ||
newAvatar.isRingVisible = false | ||
} | ||
} | ||
} |
Oops, something went wrong.