'use Firestore model value as toggle to present fullscreen view in SwiftUI
I have two screens in a SwiftUI app.
Screen A is displayed after the app launch and contains a button which will update the value for currentWorkoutID
on the user
model and save that modification to a Firestore database.
Screen B is shown from screen A when currentWorkoutID
is not nil on the user
model.
The problem that I'm seeing is that when I press the button in screen A, screen B immediately shows up (no animation), then is dismissed with animation and then is shown again with no animation.
I'm unsure what the issue is or how to solve it.
struct TrainingProgramDetails: View{
@EnvironmentObject var workoutCompletionStore: WorkoutCompletionDataStore
var presentWorkoutScreenBinding: Binding<Bool> {
Binding(get: {
return userDataStore.user.profileData.currentWorkoutID != nil
},
set: { value in
//nothing to do here
})
}
var body: some View {
let nextWorkoutID = userDataStore.user.profileData.currentWorkoutID
GeometryReader { screenGeometryProxy in
let imageHeight = screenGeometryProxy.size.height / 3
WorkoutsList(workouts: program.workoutsData) {
...
}
.fullScreenCover(isPresented: presentWorkoutScreenBinding,
onDismiss: {
}, content: {
WorkoutScreenAdaptor(workoutID: nextWorkoutID!,
onShowFeedback: showFeedback)
})
}
.edgesIgnoringSafeArea(.top)
}
struct User: Codable {
var profileData: ProfileData = .init()
...
}
struct ProfileData: Codable {
var currentWorkoutID:String?
...
}
Solution 1:[1]
Turns out the problem was on a container to this screen that would cause this screen to be taken out of view and then reloaded.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | otusweb |