Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions ElementX/Sources/Application/AppSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ final class AppSettings {
case fuzzyRoomListSearchEnabled
case enableOnlySignedDeviceIsolationMode
case knockingEnabled
case frequentEmojisEnabled
}

private static var suiteName: String = InfoPlistReader.main.appGroupIdentifier
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 { }
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -109,31 +110,43 @@ struct TimelineItemMenu: View {
}

private var reactionsSection: some View {
ScrollView(.horizontal) {
HStack(alignment: .center, spacing: 8) {
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))
HStack(spacing: 8) {
ScrollView(.horizontal) {
HStack(alignment: .center, spacing: 8) {
ForEach(actions.reactions, id: \.key) {
reactionButton(for: $0.key)
}
} 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)
}
.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()
// 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)
}
.padding(.horizontal)
.frame(minWidth: reactionsFrame.width, maxWidth: .infinity, alignment: .center)
.accessibilityLabel(L10n.actionReact)
}
.scrollIndicators(.hidden)
.scrollBounceBehavior(.basedOnSize, axes: .horizontal)
.readFrame($reactionsFrame)
}

private func reactionButton(for emoji: String) -> some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Please see LICENSE in the repository root for full details.
//

import OrderedCollections
import SFSafeSymbols
import SwiftUI

Expand All @@ -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.
Comment on lines +50 to +51
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm just waiting for the other shoe to drop 🙈

static func == (lhs: TimelineItemMenuReaction, rhs: TimelineItemMenuReaction) -> Bool {
lhs.key == rhs.key
}
}

enum TimelineItemMenuAction: Identifiable, Hashable {
Expand Down
4 changes: 2 additions & 2 deletions ElementX/Sources/Services/Emojis/EmojiProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class EmojiProvider: EmojiProviderProtocol {
}

func frequentlyUsedSystemEmojis() -> [String] {
guard appSettings.frequentEmojisEnabled, !ProcessInfo.processInfo.isiOSAppOnMac else {
guard !ProcessInfo.processInfo.isiOSAppOnMac else {
return []
}

Expand All @@ -72,7 +72,7 @@ class EmojiProvider: EmojiProviderProtocol {
}

func markEmojiAsFrequentlyUsed(_ emoji: String) {
guard appSettings.frequentEmojisEnabled else {
guard !ProcessInfo.processInfo.isiOSAppOnMac else {
return
}

Expand Down
Loading