mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-05 11:58:32 +00:00
Fix UserIndicatorController delayed appearance (#1330)
This commit is contained in:
@@ -19,7 +19,7 @@ import SwiftUI
|
|||||||
class UserIndicatorController: ObservableObject, UserIndicatorControllerProtocol, CustomStringConvertible {
|
class UserIndicatorController: ObservableObject, UserIndicatorControllerProtocol, CustomStringConvertible {
|
||||||
private let rootCoordinator: CoordinatorProtocol
|
private let rootCoordinator: CoordinatorProtocol
|
||||||
|
|
||||||
private var dismisalTimer: Timer?
|
private var dismissalTimer: Timer?
|
||||||
private var displayTimes = [String: Date]()
|
private var displayTimes = [String: Date]()
|
||||||
private var delayedIndicators = Set<String>()
|
private var delayedIndicators = Set<String>()
|
||||||
|
|
||||||
@@ -32,8 +32,8 @@ class UserIndicatorController: ObservableObject, UserIndicatorControllerProtocol
|
|||||||
activeIndicator = indicatorQueue.last
|
activeIndicator = indicatorQueue.last
|
||||||
|
|
||||||
if let activeIndicator, !activeIndicator.persistent {
|
if let activeIndicator, !activeIndicator.persistent {
|
||||||
dismisalTimer?.invalidate()
|
dismissalTimer?.invalidate()
|
||||||
dismisalTimer = Timer.scheduledTimer(withTimeInterval: nonPersistentDisplayDuration, repeats: false) { [weak self] _ in
|
dismissalTimer = Timer.scheduledTimer(withTimeInterval: nonPersistentDisplayDuration, repeats: false) { [weak self] _ in
|
||||||
self?.retractIndicatorWithId(activeIndicator.id)
|
self?.retractIndicatorWithId(activeIndicator.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,27 +55,24 @@ class UserIndicatorController: ObservableObject, UserIndicatorControllerProtocol
|
|||||||
func submitIndicator(_ indicator: UserIndicator, delay: Duration?) {
|
func submitIndicator(_ indicator: UserIndicator, delay: Duration?) {
|
||||||
if let index = indicatorQueue.firstIndex(where: { $0.id == indicator.id }) {
|
if let index = indicatorQueue.firstIndex(where: { $0.id == indicator.id }) {
|
||||||
indicatorQueue[index] = indicator
|
indicatorQueue[index] = indicator
|
||||||
|
displayTimes[indicator.id] = .now
|
||||||
} else {
|
} else {
|
||||||
if let delay {
|
if let delay {
|
||||||
delayedIndicators.insert(indicator.id)
|
delayedIndicators.insert(indicator.id)
|
||||||
|
|
||||||
Timer.scheduledTimer(withTimeInterval: delay.seconds, repeats: false) { [weak self] _ in
|
Timer.scheduledTimer(withTimeInterval: delay.seconds, repeats: false) { [weak self] _ in
|
||||||
guard let self else { return }
|
guard let self else { return }
|
||||||
|
|
||||||
guard delayedIndicators.contains(indicator.id) else {
|
guard delayedIndicators.contains(indicator.id) else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
retractIndicatorWithId(indicator.id)
|
enqueue(indicator: indicator)
|
||||||
indicatorQueue.append(indicator)
|
|
||||||
delayedIndicators.remove(indicator.id)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
retractIndicatorWithId(indicator.id)
|
enqueue(indicator: indicator)
|
||||||
indicatorQueue.append(indicator)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
displayTimes[indicator.id] = .now
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func retractAllIndicators() {
|
func retractAllIndicators() {
|
||||||
@@ -103,4 +100,12 @@ class UserIndicatorController: ObservableObject, UserIndicatorControllerProtocol
|
|||||||
var description: String {
|
var description: String {
|
||||||
"UserIndicatorController(\(String(describing: rootCoordinator)))"
|
"UserIndicatorController(\(String(describing: rootCoordinator)))"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Private
|
||||||
|
|
||||||
|
private func enqueue(indicator: UserIndicator) {
|
||||||
|
retractIndicatorWithId(indicator.id)
|
||||||
|
indicatorQueue.append(indicator)
|
||||||
|
displayTimes[indicator.id] = .now
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user