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
42 changed files with 121 additions and 114 deletions
@@ -47,7 +47,6 @@ final class AppSettings {
case fuzzyRoomListSearchEnabled case fuzzyRoomListSearchEnabled
case enableOnlySignedDeviceIsolationMode case enableOnlySignedDeviceIsolationMode
case knockingEnabled case knockingEnabled
case frequentEmojisEnabled
} }
private static var suiteName: String = InfoPlistReader.main.appGroupIdentifier private static var suiteName: String = InfoPlistReader.main.appGroupIdentifier
@@ -281,9 +280,6 @@ final class AppSettings {
@UserPreference(key: UserDefaultsKeys.knockingEnabled, defaultValue: false, storageType: .userDefaults(store)) @UserPreference(key: UserDefaultsKeys.knockingEnabled, defaultValue: false, storageType: .userDefaults(store))
var knockingEnabled var knockingEnabled
@UserPreference(key: UserDefaultsKeys.frequentEmojisEnabled, defaultValue: isDevelopmentBuild, storageType: .userDefaults(store))
var frequentEmojisEnabled
#endif #endif
// MARK: - Shared // MARK: - Shared
@@ -50,7 +50,6 @@ protocol DeveloperOptionsProtocol: AnyObject {
var enableOnlySignedDeviceIsolationMode: Bool { get set } var enableOnlySignedDeviceIsolationMode: Bool { get set }
var elementCallBaseURLOverride: URL? { get set } var elementCallBaseURLOverride: URL? { get set }
var knockingEnabled: Bool { get set } var knockingEnabled: Bool { get set }
var frequentEmojisEnabled: Bool { get set }
} }
extension AppSettings: DeveloperOptionsProtocol { } extension AppSettings: DeveloperOptionsProtocol { }
@@ -53,10 +53,6 @@ struct DeveloperOptionsScreen: View {
Toggle(isOn: $context.hideTimelineMedia) { Toggle(isOn: $context.hideTimelineMedia) {
Text("Hide image & video previews") Text("Hide image & video previews")
} }
Toggle(isOn: $context.frequentEmojisEnabled) {
Text("Show frequently used emojis")
}
} }
Section("Join rules") { Section("Join rules") {
@@ -11,6 +11,7 @@ import SwiftUI
struct TimelineItemMenu: View { struct TimelineItemMenu: View {
@EnvironmentObject private var context: TimelineViewModel.Context @EnvironmentObject private var context: TimelineViewModel.Context
@Environment(\.dismiss) private var dismiss @Environment(\.dismiss) private var dismiss
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
@State private var reactionsFrame = CGRect.zero @State private var reactionsFrame = CGRect.zero
@@ -109,31 +110,43 @@ struct TimelineItemMenu: View {
} }
private var reactionsSection: some View { private var reactionsSection: some View {
ScrollView(.horizontal) { HStack(spacing: 8) {
HStack(alignment: .center, spacing: 8) { ScrollView(.horizontal) {
ForEach(actions.reactions, id: \.key) { HStack(alignment: .center, spacing: 8) {
reactionButton(for: $0.key) ForEach(actions.reactions, id: \.key) {
} reactionButton(for: $0.key)
Button {
dismiss()
// Otherwise we get errors that a sheet is already presented
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
context.send(viewAction: .displayEmojiPicker(itemID: item.id))
} }
} label: {
CompoundIcon(\.reactionAdd, size: .medium, relativeTo: .compound.headingLG)
.foregroundColor(.compound.iconSecondary)
.padding(10)
} }
.accessibilityLabel(L10n.actionReact) .padding(.horizontal)
.frame(minWidth: reactionsFrame.width, maxWidth: .infinity, alignment: .center)
} }
.padding(.horizontal) .scrollIndicators(.hidden)
.frame(minWidth: reactionsFrame.width, maxWidth: .infinity, alignment: .center) .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()
// Otherwise we get errors that a sheet is already presented
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
context.send(viewAction: .displayEmojiPicker(itemID: item.id))
}
} label: {
CompoundIcon(\.reactionAdd, size: .medium, relativeTo: .compound.headingLG)
.foregroundColor(.compound.iconSecondary)
.padding(10)
}
.accessibilityLabel(L10n.actionReact)
} }
.scrollIndicators(.hidden)
.scrollBounceBehavior(.basedOnSize, axes: .horizontal)
.readFrame($reactionsFrame)
} }
private func reactionButton(for emoji: String) -> some View { private func reactionButton(for emoji: String) -> some View {
@@ -5,6 +5,7 @@
// Please see LICENSE in the repository root for full details. // Please see LICENSE in the repository root for full details.
// //
import OrderedCollections
import SFSafeSymbols import SFSafeSymbols
import SwiftUI import SwiftUI
@@ -25,30 +26,32 @@ struct TimelineItemMenuActions {
self.actions = actions self.actions = actions
self.debugActions = debugActions self.debugActions = debugActions
// Only process 5 of the most frequently used emojis instead of all of them var frequentlyUsed: OrderedSet<TimelineItemMenuReaction> = [
var frequentlyUsed = emojiProvider.frequentlyUsedSystemEmojis().prefix(5).map { TimelineItemMenuReaction(key: $0, symbol: .heart) }
frequentlyUsed += [
.init(key: "👍️", symbol: .handThumbsup), .init(key: "👍️", symbol: .handThumbsup),
.init(key: "👎️", symbol: .handThumbsdown), .init(key: "👎️", symbol: .handThumbsdown),
.init(key: "🔥", symbol: .flame), .init(key: "🎉", symbol: .partyPopper),
.init(key: "❤️", symbol: .heart), .init(key: "❤️", symbol: .heart)
.init(key: "👏", symbol: .handsClap)
] ]
frequentlyUsed = Array(frequentlyUsed.prefix(5)) frequentlyUsed.append(contentsOf: emojiProvider.frequentlyUsedSystemEmojis().map { TimelineItemMenuReaction(key: $0, symbol: .heart) })
reactions = if isReactable { reactions = if isReactable {
frequentlyUsed Array(frequentlyUsed.elements.prefix(10))
} else { } else {
[] []
} }
} }
} }
struct TimelineItemMenuReaction { struct TimelineItemMenuReaction: Hashable {
let key: String let key: String
let symbol: SFSymbol 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 { enum TimelineItemMenuAction: Identifiable, Hashable {
@@ -57,7 +57,7 @@ class EmojiProvider: EmojiProviderProtocol {
} }
func frequentlyUsedSystemEmojis() -> [String] { func frequentlyUsedSystemEmojis() -> [String] {
guard appSettings.frequentEmojisEnabled, !ProcessInfo.processInfo.isiOSAppOnMac else { guard !ProcessInfo.processInfo.isiOSAppOnMac else {
return [] return []
} }
@@ -72,7 +72,7 @@ class EmojiProvider: EmojiProviderProtocol {
} }
func markEmojiAsFrequentlyUsed(_ emoji: String) { func markEmojiAsFrequentlyUsed(_ emoji: String) {
guard appSettings.frequentEmojisEnabled else { guard !ProcessInfo.processInfo.isiOSAppOnMac else {
return return
} }
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:03139a4b36b40b979854ab2659f8bef19a4415a07a7922e13f22bfafbce96362 oid sha256:bcc6fdf7c3f7e40f9beedb8f9779fa74b3c8d7020112398059783ff2820fa4ed
size 139155 size 135575
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:d4bcf22687551f169a13c2b242ba0bc2fd20d93f1438a2a99263c4fde6677ff9 oid sha256:3e337818f2c9ecd0e7abfe35868857394f3b1129e798354266035b65ed9fe9ee
size 146820 size 142532
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:1e4244ced22d9ba2c2938a9939512fb8202d1e5f471fc0d00f58b58845abad2c oid sha256:a7ba26595547bdab86bc57097fcccb0062b73c9afcccc5ee2d9481c24a5ee954
size 137736 size 134046
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:26ea8ac5f8d377083815e42276831a7def7ec4d2c0ed5b118d431a362b4a123e oid sha256:7f1d6997b3ca132dbf486145371ccc38418ee1ccfbb05ebd670f73f621008c48
size 128100 size 124084
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:afa8b6189392fe1053312c29995783017ff9697b85f8960a75ecb76a83e05446 oid sha256:fbf1b0ba7b26a5bf3040ceffbfcca15cf38445fe4db7a39b81b16826517c6762
size 138537 size 134605
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:36fa2f45e35a597c0c0dfe672616bc584f12e93c8d742c2fcdc0a40195dd7159 oid sha256:bdcb99ed272db7ee82b09574da7e791ee371b35107ca8104a72acd71e99b1156
size 132986 size 129013
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:26ea8ac5f8d377083815e42276831a7def7ec4d2c0ed5b118d431a362b4a123e oid sha256:7f1d6997b3ca132dbf486145371ccc38418ee1ccfbb05ebd670f73f621008c48
size 128100 size 124084
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:1583ad4ade4b6eac9eface5466a742999213b9f4e2e80ac62d174338722d6799 oid sha256:83ec69d4b69f3a33422b0a472665c65855a365b4f676888edb9eb054ebaf77d4
size 137445 size 133818
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:c80e3745e88d27713eebb5f28fe4ee1bcc65e8690e30cba71c83b6a240a818ac oid sha256:e173a969f56bdfad935308070f5dc1958eaf7781fbcf18e01c81b95799ce3ae1
size 136759 size 132960
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:faa541dc8e53791b4f0fbe78a3ef2f99afcff7b91fe9f6e6293ea831baf15b07 oid sha256:c5a5a1d65cd3f0c569f2ca1fb80258e8179870acade4a1d68b3e9e67a52d8d29
size 146264 size 142541
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:403ddbf0882f5ded4fbd1ac0e34d635909f260dd2f2988a979503ca29c59db5b oid sha256:9fbc2bf481aeecb17f3be814b3bcf7147f2d8d757eb82a15b2a0db10a5ec8f40
size 148734 size 144452
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:4dd28156f64422ca6df2dc5178afdf6e3d840ab220e2e17bb55d55f3f306f359 oid sha256:1eac1d2d29c71d9c332f26b311b50c7ef601896a6941a1f617d200e23bb88731
size 145601 size 141641
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:25d707eeb27e5fbb22a6ec3efe70142b8781a3ea5423d44d284deebd78bfda22 oid sha256:39c0cc82049d6e4c12416c457a087d99b52169ab266da1beaa22888aa933bca5
size 129934 size 125934
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:4b3d27ebbcc1acf240e82893f4ea815bb117e8e7f033aa368983ef59e48e60bf oid sha256:eac68c72456505eaafd6c94948857aaa2d54accc4990c3dd3cd1cb31023c89bf
size 144624 size 140645
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:ffbe89eadebb2a4590f2c8d5cfb2d053eafd190f7512c7b560d73fe057bc2419 oid sha256:150daec2df86269a675887b754f64e067dcdb856dff9d1c8a36e746495745ab8
size 137105 size 133199
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:25d707eeb27e5fbb22a6ec3efe70142b8781a3ea5423d44d284deebd78bfda22 oid sha256:39c0cc82049d6e4c12416c457a087d99b52169ab266da1beaa22888aa933bca5
size 129934 size 125934
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:fd14d07d1258d5740e90cb017b42cb7715c61a7eb9ac0211ee1af57a0eac71fa oid sha256:a1d61ad248aa93c90b680e51cdf4a30d8cfd9568a062b03b559d6f9d57fffddf
size 143967 size 140013
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:039542c53b6877e128483381d0aa599d454401b60017eee2d73817d4475cfcfa oid sha256:2c30cb638c2eecebb63ca66a5f0107bb85225aa786cbf32ecbca9974b42cd383
size 142473 size 139069
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:fe429e48ab5e9733b17383b056d882cd73fec21dd79fd8fed6ef295a77c02b9c oid sha256:dd17e2229ac0f1c09ef301589f24de7f879364dbc468460d6e387b2393d6b584
size 91910 size 88452
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:f7d5688fb1e653dd4d7c025496bf21c4794566772028a4fcb164255be5829ef7 oid sha256:2e9f207e4656524273989488b2e8f1d9ee2901d500a76b89dbbf01e831a146c7
size 91186 size 91341
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:09d0ef69aac97f605af70dee72274600e243d95b896e06ff4a5b88edfcbe492f oid sha256:46f40c81c046bb1593d0ac0d1b396558e75ab4d9a85ce9f460610c623835711a
size 90909 size 87463
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:ca46714baac623515ee64da0f80cb8588938dc322446e8100c2fa19c80c4103e oid sha256:b1a6d6103056a883e4fa9344b65766867ef28355f359c428c6f8fc7b8a5b1dd4
size 81690 size 78383
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:b668de157b45f5f1f75e9485d3c35e8a103428ac03563ff851b24111f3699553 oid sha256:12b9450065c9aa924ac7b833d2c98a8ea011ea3ec470438869f08591590a5576
size 91806 size 88346
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:6533795aeb46d968aa65e814a8a6f16d8da8806ef367400d2ef7fddb19ffc0a6 oid sha256:05ae1dfcf89ec7c5329c570e29b876935d261470a6fc074d961452f75e4ab4e3
size 84498 size 81155
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:ca46714baac623515ee64da0f80cb8588938dc322446e8100c2fa19c80c4103e oid sha256:b1a6d6103056a883e4fa9344b65766867ef28355f359c428c6f8fc7b8a5b1dd4
size 81690 size 78383
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:1ebc67234b0185ddea83263dd44cd4f90dc578698d2cc40baa64167f87c28f88 oid sha256:100ebc998da4d0625307771a9fda2dc78becccf2fe0e58cb514967cc26b77e46
size 90370 size 86917
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:ea7194599f6f232bcd6e2b4bf6a23095d8bdeba217ccfc5c1e53326e02118c5f oid sha256:5d2451f6dfdb5d0342c13d9bba95f035610649f5e0c6c026b6b5c02a3f5ea792
size 87424 size 84457
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:14f96e9cc4c72a8be248885673df3b678d99b7a5227ea4751c37d027de86b543 oid sha256:a7e0833f33a5372ac34cb1ffc904b3113c292ddfac1798f2ec49263f72487b8b
size 107635 size 104147
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:917f4a8cdf90f2dec6ec9812bd19d6a87611376c007d5ab528aac8ca81fdafb0 oid sha256:9dd681b7005cad7f3172e46704ce15f35348741ab4f61c25c7e25dbc976dd47f
size 96764 size 96872
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:439d46bc024a1c7a387e674f454f9b67fb78276d5761b88a86dc2b399daa3629 oid sha256:66a515af35f86cc79842515e6f200a8ac9e66393bafa3d08dd73c94b55a0e273
size 105944 size 102463
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:8bf1639b2cf203490b7c0e0e801274fc7fd05b3942ebb9684e224192e1f1ca12 oid sha256:f9f354421510618dc4c3ebdd4ed3f6aeb274236bd4d680948127a21737882a35
size 87380 size 83970
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:a9283c5c852d4843ee9d58b2af0df2c4effc4693f47100b232bdb5cf7c7157c1 oid sha256:20be265e58a5ce19848a1d9c9221587656efbeb1eefa982bf598021ed91b1976
size 108300 size 104759
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:55119111fd3419c9a280b49eaac288c4ff1da935280eb785815891e59dec6a4c oid sha256:bbcb5ce6d51e66aa74d7ebb6cdaf574a80613cf5cbc2a52285f2db5758a260c8
size 91962 size 88609
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:8bf1639b2cf203490b7c0e0e801274fc7fd05b3942ebb9684e224192e1f1ca12 oid sha256:f9f354421510618dc4c3ebdd4ed3f6aeb274236bd4d680948127a21737882a35
size 87380 size 83970
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:aa27e929fdcb97f2900eb540c9e0fdbce42dabacd99c1b8a84aa761406cb7e25 oid sha256:cb4cba6c55ed6d5a399729817e3bbcf0109e940022009ec2b994d744a0e26b9e
size 104293 size 100765
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:67a6b2f31d5cd87a54558c93ee7f56a6af75b9887f2cbad4b28aca781696b923 oid sha256:e808c53766810d2cef79e239295f55b151a151cb42a7d7fd24f83ef889964ae1
size 99497 size 95987