mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-21 15:50:59 +00:00
Apply emoji animation preference in picker
This commit is contained in:
parent
97bd008ea3
commit
e5d8a4d132
8 changed files with 60 additions and 31 deletions
|
@ -36,7 +36,7 @@ final class AutocompleteDataSource: UICollectionViewDiffableDataSource<Autocompl
|
||||||
}
|
}
|
||||||
|
|
||||||
let emojiRegistration = UICollectionView.CellRegistration<EmojiCollectionViewCell, PickerEmoji> {
|
let emojiRegistration = UICollectionView.CellRegistration<EmojiCollectionViewCell, PickerEmoji> {
|
||||||
$0.emoji = $2.applyingDefaultSkinTone(identityContext: parentViewModel.identityContext)
|
$0.viewModel = EmojiViewModel(emoji: $2, identityContext: parentViewModel.identityContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
super.init(collectionView: collectionView) {
|
super.init(collectionView: collectionView) {
|
||||||
|
|
|
@ -3,17 +3,6 @@
|
||||||
import UIKit
|
import UIKit
|
||||||
import ViewModels
|
import ViewModels
|
||||||
|
|
||||||
extension PickerEmoji {
|
|
||||||
func applyingDefaultSkinTone(identityContext: IdentityContext) -> PickerEmoji {
|
|
||||||
if case let .system(systemEmoji, inFrequentlyUsed) = self,
|
|
||||||
let defaultEmojiSkinTone = identityContext.appPreferences.defaultEmojiSkinTone {
|
|
||||||
return .system(systemEmoji.applying(skinTone: defaultEmojiSkinTone), inFrequentlyUsed: inFrequentlyUsed)
|
|
||||||
} else {
|
|
||||||
return self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extension Dictionary where Key == PickerEmoji.Category, Value == [PickerEmoji] {
|
extension Dictionary where Key == PickerEmoji.Category, Value == [PickerEmoji] {
|
||||||
func snapshot() -> NSDiffableDataSourceSnapshot<PickerEmoji.Category, PickerEmoji> {
|
func snapshot() -> NSDiffableDataSourceSnapshot<PickerEmoji.Category, PickerEmoji> {
|
||||||
var snapshot = NSDiffableDataSourceSnapshot<PickerEmoji.Category, PickerEmoji>()
|
var snapshot = NSDiffableDataSourceSnapshot<PickerEmoji.Category, PickerEmoji>()
|
||||||
|
|
|
@ -22,7 +22,7 @@ final class EmojiPickerViewController: UICollectionViewController {
|
||||||
<EmojiCollectionViewCell, PickerEmoji> { [weak self] in
|
<EmojiCollectionViewCell, PickerEmoji> { [weak self] in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
|
|
||||||
$0.emoji = $2.applyingDefaultSkinTone(identityContext: self.viewModel.identityContext)
|
$0.viewModel = EmojiViewModel(emoji: $2, identityContext: self.viewModel.identityContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
let headerRegistration = UICollectionView.SupplementaryRegistration
|
let headerRegistration = UICollectionView.SupplementaryRegistration
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright © 2021 Metabolist. All rights reserved.
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
public extension PickerEmoji {
|
||||||
|
func applyingDefaultSkinTone(identityContext: IdentityContext) -> PickerEmoji {
|
||||||
|
if case let .system(systemEmoji, inFrequentlyUsed) = self,
|
||||||
|
let defaultEmojiSkinTone = identityContext.appPreferences.defaultEmojiSkinTone {
|
||||||
|
return .system(systemEmoji.applying(skinTone: defaultEmojiSkinTone), inFrequentlyUsed: inFrequentlyUsed)
|
||||||
|
} else {
|
||||||
|
return self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
// Copyright © 2021 Metabolist. All rights reserved.
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
public struct EmojiViewModel {
|
||||||
|
let identityContext: IdentityContext
|
||||||
|
|
||||||
|
private let emoji: PickerEmoji
|
||||||
|
|
||||||
|
public init(emoji: PickerEmoji, identityContext: IdentityContext) {
|
||||||
|
self.emoji = emoji.applyingDefaultSkinTone(identityContext: identityContext)
|
||||||
|
self.identityContext = identityContext
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public extension EmojiViewModel {
|
||||||
|
var name: String { emoji.name }
|
||||||
|
|
||||||
|
var system: Bool { emoji.system }
|
||||||
|
|
||||||
|
var url: URL? {
|
||||||
|
guard case let .custom(emoji, _) = emoji else { return nil }
|
||||||
|
|
||||||
|
if identityContext.appPreferences.animateCustomEmojis {
|
||||||
|
return emoji.url
|
||||||
|
} else {
|
||||||
|
return emoji.staticUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,12 +4,12 @@ import UIKit
|
||||||
import ViewModels
|
import ViewModels
|
||||||
|
|
||||||
final class EmojiCollectionViewCell: UICollectionViewCell {
|
final class EmojiCollectionViewCell: UICollectionViewCell {
|
||||||
var emoji: PickerEmoji?
|
var viewModel: EmojiViewModel?
|
||||||
|
|
||||||
override func updateConfiguration(using state: UICellConfigurationState) {
|
override func updateConfiguration(using state: UICellConfigurationState) {
|
||||||
guard let emoji = emoji else { return }
|
guard let viewModel = viewModel else { return }
|
||||||
|
|
||||||
contentConfiguration = EmojiContentConfiguration(emoji: emoji)
|
contentConfiguration = EmojiContentConfiguration(viewModel: viewModel)
|
||||||
|
|
||||||
var backgroundConfiguration = UIBackgroundConfiguration.listPlainCell().updated(for: state)
|
var backgroundConfiguration = UIBackgroundConfiguration.listPlainCell().updated(for: state)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import UIKit
|
||||||
import ViewModels
|
import ViewModels
|
||||||
|
|
||||||
struct EmojiContentConfiguration {
|
struct EmojiContentConfiguration {
|
||||||
let emoji: PickerEmoji
|
let viewModel: EmojiViewModel
|
||||||
}
|
}
|
||||||
|
|
||||||
extension EmojiContentConfiguration: UIContentConfiguration {
|
extension EmojiContentConfiguration: UIContentConfiguration {
|
||||||
|
|
|
@ -68,22 +68,18 @@ private extension EmojiView {
|
||||||
}
|
}
|
||||||
|
|
||||||
func applyEmojiConfiguration() {
|
func applyEmojiConfiguration() {
|
||||||
imageView.isHidden = emojiConfiguration.emoji.system
|
if emojiConfiguration.viewModel.system {
|
||||||
|
|
||||||
if case let .custom(emoji, _) = emojiConfiguration.emoji {
|
|
||||||
imageView.isHidden = false
|
|
||||||
emojiLabel.isHidden = true
|
|
||||||
|
|
||||||
// TODO: Use static URL if emoji animation preference is false
|
|
||||||
imageView.sd_setImage(with: emoji.url)
|
|
||||||
accessibilityLabel = emoji.shortcode
|
|
||||||
} else {
|
|
||||||
imageView.isHidden = true
|
|
||||||
emojiLabel.isHidden = false
|
emojiLabel.isHidden = false
|
||||||
|
emojiLabel.text = emojiConfiguration.viewModel.name
|
||||||
emojiLabel.text = emojiConfiguration.emoji.name
|
imageView.isHidden = true
|
||||||
accessibilityLabel = emojiConfiguration.emoji.name
|
} else {
|
||||||
|
emojiLabel.isHidden = true
|
||||||
|
emojiLabel.text = nil
|
||||||
|
imageView.isHidden = false
|
||||||
|
imageView.sd_setImage(with: emojiConfiguration.viewModel.url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
accessibilityLabel = emojiConfiguration.viewModel.name
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupAccessibility() {
|
func setupAccessibility() {
|
||||||
|
|
Loading…
Reference in a new issue