Show both defaults and frequent emojis in the timeline item menu, make the list scrollable (#3534)

This commit is contained in:
Stefan Ceriu 2024-11-19 21:53:57 +02:00 committed by GitHub
parent bce3b3a385
commit 51227fffe3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
42 changed files with 121 additions and 114 deletions

View File

@ -47,7 +47,6 @@ final class AppSettings {
case fuzzyRoomListSearchEnabled
case enableOnlySignedDeviceIsolationMode
case knockingEnabled
case frequentEmojisEnabled
}
private static var suiteName: String = InfoPlistReader.main.appGroupIdentifier
@ -281,9 +280,6 @@ final class AppSettings {
@UserPreference(key: UserDefaultsKeys.knockingEnabled, defaultValue: false, storageType: .userDefaults(store))
var knockingEnabled
@UserPreference(key: UserDefaultsKeys.frequentEmojisEnabled, defaultValue: isDevelopmentBuild, storageType: .userDefaults(store))
var frequentEmojisEnabled
#endif
// MARK: - Shared

View File

@ -50,7 +50,6 @@ protocol DeveloperOptionsProtocol: AnyObject {
var enableOnlySignedDeviceIsolationMode: Bool { get set }
var elementCallBaseURLOverride: URL? { get set }
var knockingEnabled: Bool { get set }
var frequentEmojisEnabled: Bool { get set }
}
extension AppSettings: DeveloperOptionsProtocol { }

View File

@ -53,10 +53,6 @@ struct DeveloperOptionsScreen: View {
Toggle(isOn: $context.hideTimelineMedia) {
Text("Hide image & video previews")
}
Toggle(isOn: $context.frequentEmojisEnabled) {
Text("Show frequently used emojis")
}
}
Section("Join rules") {

View File

@ -11,6 +11,7 @@ import SwiftUI
struct TimelineItemMenu: View {
@EnvironmentObject private var context: TimelineViewModel.Context
@Environment(\.dismiss) private var dismiss
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
@State private var reactionsFrame = CGRect.zero
@ -109,11 +110,29 @@ struct TimelineItemMenu: View {
}
private var reactionsSection: some View {
HStack(spacing: 8) {
ScrollView(.horizontal) {
HStack(alignment: .center, spacing: 8) {
ForEach(actions.reactions, id: \.key) {
reactionButton(for: $0.key)
}
}
.padding(.horizontal)
.frame(minWidth: reactionsFrame.width, maxWidth: .infinity, alignment: .center)
}
.scrollIndicators(.hidden)
.scrollBounceBehavior(.basedOnSize, axes: .horizontal)
.readFrame($reactionsFrame)
.overlay {
if horizontalSizeClass == .compact {
LinearGradient(stops: [.init(color: .clear, location: 0.0),
.init(color: .clear, location: 0.9),
.init(color: .compound.bgCanvasDefault, location: 1.0)],
startPoint: .leading,
endPoint: .trailing)
.allowsHitTesting(false)
}
}
Button {
dismiss()
@ -128,12 +147,6 @@ struct TimelineItemMenu: View {
}
.accessibilityLabel(L10n.actionReact)
}
.padding(.horizontal)
.frame(minWidth: reactionsFrame.width, maxWidth: .infinity, alignment: .center)
}
.scrollIndicators(.hidden)
.scrollBounceBehavior(.basedOnSize, axes: .horizontal)
.readFrame($reactionsFrame)
}
private func reactionButton(for emoji: String) -> some View {

View File

@ -5,6 +5,7 @@
// Please see LICENSE in the repository root for full details.
//
import OrderedCollections
import SFSafeSymbols
import SwiftUI
@ -25,30 +26,32 @@ struct TimelineItemMenuActions {
self.actions = actions
self.debugActions = debugActions
// Only process 5 of the most frequently used emojis instead of all of them
var frequentlyUsed = emojiProvider.frequentlyUsedSystemEmojis().prefix(5).map { TimelineItemMenuReaction(key: $0, symbol: .heart) }
frequentlyUsed += [
var frequentlyUsed: OrderedSet<TimelineItemMenuReaction> = [
.init(key: "👍️", symbol: .handThumbsup),
.init(key: "👎️", symbol: .handThumbsdown),
.init(key: "🔥", symbol: .flame),
.init(key: "❤️", symbol: .heart),
.init(key: "👏", symbol: .handsClap)
.init(key: "🎉", symbol: .partyPopper),
.init(key: "❤️", symbol: .heart)
]
frequentlyUsed = Array(frequentlyUsed.prefix(5))
frequentlyUsed.append(contentsOf: emojiProvider.frequentlyUsedSystemEmojis().map { TimelineItemMenuReaction(key: $0, symbol: .heart) })
reactions = if isReactable {
frequentlyUsed
Array(frequentlyUsed.elements.prefix(10))
} else {
[]
}
}
}
struct TimelineItemMenuReaction {
struct TimelineItemMenuReaction: Hashable {
let key: String
let symbol: SFSymbol
// Frequently used emojis on the all use the same .heart SFSymbol.
// Override equatable so we can remove duplicates.
static func == (lhs: TimelineItemMenuReaction, rhs: TimelineItemMenuReaction) -> Bool {
lhs.key == rhs.key
}
}
enum TimelineItemMenuAction: Identifiable, Hashable {

View File

@ -57,7 +57,7 @@ class EmojiProvider: EmojiProviderProtocol {
}
func frequentlyUsedSystemEmojis() -> [String] {
guard appSettings.frequentEmojisEnabled, !ProcessInfo.processInfo.isiOSAppOnMac else {
guard !ProcessInfo.processInfo.isiOSAppOnMac else {
return []
}
@ -72,7 +72,7 @@ class EmojiProvider: EmojiProviderProtocol {
}
func markEmojiAsFrequentlyUsed(_ emoji: String) {
guard appSettings.frequentEmojisEnabled else {
guard !ProcessInfo.processInfo.isiOSAppOnMac else {
return
}