mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Timeline Reactions: Emoji picker (#350)
* Screens template * Loading and parsing * Gridview * New json * Search method * Unit tests * Added emoji provider state * Removed containsIgnoringCase * Added plus icon, added double tap gesture, dismiss sheet after selecting emoji * Renamed EmojisProvider to EmojiProvider * Renamed EmojiPickerScreenScreen * Extra padding * Renamed EmojisLoaderProtocol * Category names * Moved method into public section of the class * Return all categories when search string is empty * Added cancel button and tittle * Removed empty lines * Removed swiftlint warning
This commit is contained in:
committed by
GitHub
parent
dcedb3fb98
commit
7f91852291
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// Copyright 2022 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
typealias EmojiPickerScreenViewModelType = StateStoreViewModel<EmojiPickerScreenViewState, EmojiPickerScreenViewAction>
|
||||
|
||||
class EmojiPickerScreenViewModel: EmojiPickerScreenViewModelType, EmojiPickerScreenViewModelProtocol {
|
||||
var callback: ((EmojiPickerScreenViewModelAction) -> Void)?
|
||||
|
||||
private let emojiProvider: EmojiProviderProtocol
|
||||
|
||||
init(emojiProvider: EmojiProviderProtocol) {
|
||||
let initialViewState = EmojiPickerScreenViewState(categories: [])
|
||||
self.emojiProvider = emojiProvider
|
||||
super.init(initialViewState: initialViewState)
|
||||
loadEmojis()
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
override func process(viewAction: EmojiPickerScreenViewAction) async {
|
||||
switch viewAction {
|
||||
case let .search(searchString: searchString):
|
||||
let categories = await emojiProvider.getCategories(searchString: searchString)
|
||||
state.categories = convert(emojiCategories: categories)
|
||||
case let .emojiSelected(emoji: emoji):
|
||||
callback?(.selectEmoji(emojiId: emoji.id))
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func loadEmojis() {
|
||||
Task(priority: .userInitiated) { [weak self] in
|
||||
let categories = await emojiProvider.getCategories(searchString: nil)
|
||||
self?.state.categories = convert(emojiCategories: categories)
|
||||
}
|
||||
}
|
||||
|
||||
private func convert(emojiCategories: [EmojiCategory]) -> [EmojiPickerEmojiCategoryViewData] {
|
||||
emojiCategories.compactMap { emojiCategory in
|
||||
|
||||
let emojisViewData: [EmojiPickerEmojiViewData] = emojiCategory.emojis.compactMap { emojiItem in
|
||||
|
||||
guard let firstSkin = emojiItem.skins.first else {
|
||||
return nil
|
||||
}
|
||||
return EmojiPickerEmojiViewData(id: emojiItem.id, value: firstSkin.value)
|
||||
}
|
||||
|
||||
return EmojiPickerEmojiCategoryViewData(id: emojiCategory.id, emojis: emojisViewData)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user