minor refactor on context menu actions

pull/1023/head
Ryan ZHAO 1 year ago
parent a7b8a120e3
commit 87efc38a04

@ -16,12 +16,17 @@ extension ContextMenuVC {
let title: String
let expirationInfo: ExpirationInfo?
let themeColor: ThemeValue
let isEmojiAction: Bool
let isEmojiPlus: Bool
let isDismissAction: Bool
let actionType: ActionType
let accessibilityLabel: String?
let work: () -> Void
enum ActionType {
case emoji
case emojiPlus
case dismiss
case generic
}
// MARK: - Initialization
init(
@ -29,9 +34,7 @@ extension ContextMenuVC {
title: String = "",
expirationInfo: ExpirationInfo? = nil,
themeColor: ThemeValue = .textPrimary,
isEmojiAction: Bool = false,
isEmojiPlus: Bool = false,
isDismissAction: Bool = false,
actionType: ActionType = .generic,
accessibilityLabel: String? = nil,
work: @escaping () -> Void
) {
@ -39,9 +42,7 @@ extension ContextMenuVC {
self.title = title
self.expirationInfo = expirationInfo
self.themeColor = themeColor
self.isEmojiAction = isEmojiAction
self.isEmojiPlus = isEmojiPlus
self.isDismissAction = isDismissAction
self.actionType = actionType
self.accessibilityLabel = accessibilityLabel
self.work = work
}
@ -134,20 +135,20 @@ extension ContextMenuVC {
static func react(_ cellViewModel: MessageViewModel, _ emoji: EmojiWithSkinTones, _ delegate: ContextMenuActionDelegate?, using dependencies: Dependencies) -> Action {
return Action(
title: emoji.rawValue,
isEmojiAction: true
actionType: .emoji
) { delegate?.react(cellViewModel, with: emoji, using: dependencies) }
}
static func emojiPlusButton(_ cellViewModel: MessageViewModel, _ delegate: ContextMenuActionDelegate?, using dependencies: Dependencies) -> Action {
return Action(
isEmojiPlus: true,
actionType: .emojiPlus,
accessibilityLabel: "Add emoji"
) { delegate?.showFullEmojiKeyboard(cellViewModel, using: dependencies) }
}
static func dismiss(_ delegate: ContextMenuActionDelegate?) -> Action {
return Action(
isDismissAction: true
actionType: .dismiss
) { delegate?.contextMenuDismissed() }
}
}

@ -37,7 +37,7 @@ final class ContextMenuVC: UIViewController {
private lazy var emojiPlusButton: EmojiPlusButton = {
let result: EmojiPlusButton = EmojiPlusButton(
action: self.actions.first(where: { $0.isEmojiPlus }),
action: self.actions.first(where: { $0.actionType == .emojiPlus }),
dismiss: snDismiss
)
result.clipsToBounds = true
@ -140,7 +140,7 @@ final class ContextMenuVC: UIViewController {
let emojiBarStackView = UIStackView(
arrangedSubviews: actions
.filter { $0.isEmojiAction }
.filter { $0.actionType == .emoji }
.map { action -> EmojiReactsView in EmojiReactsView(for: action, dismiss: snDismiss) }
)
emojiBarStackView.axis = .horizontal
@ -165,7 +165,7 @@ final class ContextMenuVC: UIViewController {
let menuStackView = UIStackView(
arrangedSubviews: actions
.filter { !$0.isEmojiAction && !$0.isEmojiPlus && !$0.isDismissAction }
.filter { $0.actionType == .generic }
.map { action -> ActionView in
ActionView(for: action, dismiss: snDismiss)
}
@ -406,7 +406,7 @@ final class ContextMenuVC: UIViewController {
},
completion: { [weak self] _ in
self?.dismiss()
self?.actions.first(where: { $0.isDismissAction })?.work()
self?.actions.first(where: { $0.actionType == .dismiss })?.work()
}
)
}

@ -528,6 +528,8 @@ final class ConversationVC: BaseVC, SessionUtilRespondingViewController, Convers
object: nil
)
self.viewModel.navigatableState.setupBindings(viewController: self, disposables: &self.viewModel.disposables)
// The first time the view loads we should mark the thread as read (in case it was manually
// marked as unread) - doing this here means if we add a "mark as unread" action within the
// conversation settings then we don't need to worry about the conversation getting marked as

@ -47,6 +47,7 @@ public class ConversationViewModel: OWSAudioPlayerDelegate, NavigatableStateHold
public static let pageSize: Int = 50
public let navigatableState: NavigatableState = NavigatableState()
public var disposables: Set<AnyCancellable> = Set()
private var threadId: String
public let initialThreadVariant: SessionThread.Variant

Loading…
Cancel
Save