Hi there,
My SwiftUI project displays a cooldown timer to inform a user when they can attempt a new data download.
This timer is being initiated after finishing a data fetch and is working on the main thread of a dispatch group:
dispatchGroupForDownloads.notify(queue: .main) {
self.cooldowncounter = 10
if self.timer == nil { self.timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(self.updateCounter), userInfo: nil, repeats: true)}
My updateCounter method decrements the timer:
@objc func updateCounter() {
if cooldowncounter > 0 {
cooldowncounter -= 1
} else if cooldowncounter == 0 {
timer?.invalidate()
timer = nil
}
}
The timer works as expected and is displayed to the user. However, this is the issue: Whenever the timer is counting down, I cannot navigate anywhere else in my app without it "snapping back" to the previous view. That's the best way I can describe it.
Is there any other way to show a timer to the user that does not interrupt the UI?
Post
Replies
Boosts
Views
Activity
Hi!
I am testing my app on the new Xcode 12 beta and iOS 14 beta 1.
My app contains a section where a SwiftUI List is presented modally with a simple .sheet declaration:
.sheet(isPresented: $showingSheet, content: {
Within this presented list, tapping an item in the list will present further content in a new modally presented .sheet on top of the first one. These subsequent modal sheets also contain SwiftUI List objects with further content.
My issue in these new betas is that any .sheet modals presented subsequently to the first .sheet presented will not render any content in their Lists.
My lists contain buttons that toggle the Boolean that presents the .sheet content. Example:
List {
ForEach(selectableLeagues, id: \.self) { league in
Button(action: {
self.selectedDivision.append(contentsOf: league)
self.showSheet.toggle()
Sometimes, dismissing and reopening the subsequent modals will make the List content pop in, but this is very unreliable.
Needless to say, all of these features worked in Xcode 11 and iOS 13.
Has anyone else experienced this in the new betas so far?