fix empty toast issue and improve the duration of toast

pull/1061/head
Ryan ZHAO 2 months ago
parent be95cb181f
commit 7daa8835a3

@ -14,10 +14,11 @@ extension ContextMenuVC {
struct Action {
let icon: UIImage?
let title: String
let feedback: String
let feedback: String?
let expirationInfo: ExpirationInfo?
let themeColor: ThemeValue
let actionType: ActionType
let shouldDismissInfoScreen: Bool
let accessibilityLabel: String?
let work: () -> Void
@ -33,10 +34,11 @@ extension ContextMenuVC {
init(
icon: UIImage? = nil,
title: String = "",
feedback: String = "",
feedback: String? = nil,
expirationInfo: ExpirationInfo? = nil,
themeColor: ThemeValue = .textPrimary,
actionType: ActionType = .generic,
shouldDismissInfoScreen: Bool = false,
accessibilityLabel: String? = nil,
work: @escaping () -> Void
) {
@ -46,6 +48,7 @@ extension ContextMenuVC {
self.expirationInfo = expirationInfo
self.themeColor = themeColor
self.actionType = actionType
self.shouldDismissInfoScreen = shouldDismissInfoScreen
self.accessibilityLabel = accessibilityLabel
self.work = work
}
@ -75,6 +78,7 @@ extension ContextMenuVC {
return Action(
icon: UIImage(named: "ic_reply"),
title: "reply".localized(),
shouldDismissInfoScreen: true,
accessibilityLabel: "Reply to message"
) { delegate?.reply(cellViewModel, using: dependencies) }
}
@ -107,6 +111,7 @@ extension ContextMenuVC {
expiresInSeconds: cellViewModel.expiresInSeconds
),
themeColor: .danger,
shouldDismissInfoScreen: true,
accessibilityLabel: "Delete message"
) { delegate?.delete(cellViewModel, using: dependencies) }
}
@ -134,6 +139,7 @@ extension ContextMenuVC {
icon: UIImage(named: "ic_block"),
title: "banDeleteAll".localized(),
themeColor: .danger,
shouldDismissInfoScreen: true,
accessibilityLabel: "Ban user and delete"
) { delegate?.banAndDeleteAllMessages(cellViewModel, using: dependencies) }
}

@ -307,9 +307,12 @@ struct MessageInfoScreen: View {
action: {
actions[index].work()
feedbackMessage = actions[index].feedback
DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
dismiss()
})
if actions[index].shouldDismissInfoScreen {
let deadline: DispatchTime = .now() + (feedbackMessage?.isEmpty == false ? 2 : 0)
DispatchQueue.main.asyncAfter(deadline: deadline, execute: {
dismiss()
})
}
},
label: {
HStack(spacing: Values.largeSpacing) {

@ -2,6 +2,7 @@
import SwiftUI
import Combine
import NaturalLanguage
public struct ToastModifier: ViewModifier {
@Binding var message: String?
@ -34,7 +35,17 @@ public struct ToastModifier: ViewModifier {
}
workItem = task
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5, execute: task)
let duration: TimeInterval = {
guard let message: String = message else { return 1.5 }
let tokenizer = NLTokenizer(unit: .word)
tokenizer.string = message
let wordCount = tokenizer.tokens(for: message.startIndex..<message.endIndex).count
return min(1.5 + Double(wordCount - 1) * 0.1 , 5)
}()
DispatchQueue.main.asyncAfter(deadline: .now() + duration, execute: task)
}
private func dismissToast() {

Loading…
Cancel
Save