metatext-app-ios-iphone-ipad/Extensions/PickerEmoji+Extensions.swift

45 lines
1.4 KiB
Swift
Raw Normal View History

2021-01-15 11:13:10 +01:00
// Copyright © 2021 Metabolist. All rights reserved.
import UIKit
import ViewModels
2021-02-15 09:47:30 +01:00
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
}
}
}
2021-01-15 11:13:10 +01:00
extension Dictionary where Key == PickerEmoji.Category, Value == [PickerEmoji] {
func snapshot() -> NSDiffableDataSourceSnapshot<PickerEmoji.Category, PickerEmoji> {
var snapshot = NSDiffableDataSourceSnapshot<PickerEmoji.Category, PickerEmoji>()
snapshot.appendSections(keys.sorted())
for (key, value) in self {
snapshot.appendItems(value, toSection: key)
}
return snapshot
}
}
extension PickerEmoji.Category {
var displayName: String {
switch self {
case .frequentlyUsed:
return NSLocalizedString("emoji.frequently-used", comment: "")
case .custom:
return NSLocalizedString("emoji.custom", comment: "")
case let .customNamed(name):
return name
case let .systemGroup(group):
2021-01-15 22:43:46 +01:00
return NSLocalizedString(group.localizedStringKey, comment: "")
2021-01-15 11:13:10 +01:00
}
}
}