Hello all,
My app has a welcome screen that only displays when the app is first launched. I'm doing this using @AppStorage property wrapper. It is set to true initially, which triggers the .sheet(isPresented:) modal view. In the modal view, there is a button that users can press to dismiss the modal view. This button sets a binding variable to false, which in turn should change the AppStorage variable to false. Problem is, the button, when pressed, doesn't dismiss the modal. Please see code below:
This is the modal view:
This is the content view:
When I press the button in the modal view, it prints 123 but doesn't dismiss the modal. Am I doing something wrong?
My app has a welcome screen that only displays when the app is first launched. I'm doing this using @AppStorage property wrapper. It is set to true initially, which triggers the .sheet(isPresented:) modal view. In the modal view, there is a button that users can press to dismiss the modal view. This button sets a binding variable to false, which in turn should change the AppStorage variable to false. Problem is, the button, when pressed, doesn't dismiss the modal. Please see code below:
This is the modal view:
Code Block struct IntroductionView: View { @Binding var isShowingIntroScreen: Bool var body: some View { VStack { Spacer() .frame(height: 20) ScrollView { TitleView() Spacer() InformationContainerView() Spacer() } Button(action: { self.isShowingIntroScreen = false print(123) } ) { Text("Get started") .customButton() } .padding() Spacer() .frame(height: 0) } } }
This is the content view:
Code Block struct ContentView: View { @AppStorage("Onboarding View") var isShowingOnboardingScreen = true var body: some View { .background(EmptyView() .sheet(isPresented: $isShowingOnboardingScreen, content: { IntroductionView(isShowingIntroScreen: $isShowingOnboardingScreen) }) )
When I press the button in the modal view, it prints 123 but doesn't dismiss the modal. Am I doing something wrong?
I have tested your project on my iPhone 7 plus (iOS 14.3)/iPhone 12 Max (iOS 14.4), and both work as expected as I wrote in my former post.
I needed to change Bundle Identifier and remove Capabilities: iCloud and Push Notification to test the app on my testing account. And I needed to Trust my testing account, each time I deleted the app. Any of such things may be affecting.
So, I think your code is well, just your testing environment or something other than code may be affecting.
I recommend you, again, to create another brand-new project. Move some code from your actual project to it one by one , until you can reproduce the issue. (You may need to modify your project settings and code to make it build and run with the limited resources for each step.) That may reveal what may be affecting.
I needed to change Bundle Identifier and remove Capabilities: iCloud and Push Notification to test the app on my testing account. And I needed to Trust my testing account, each time I deleted the app. Any of such things may be affecting.
So, I think your code is well, just your testing environment or something other than code may be affecting.
If that is an observable fact, we should think based on it. But as for now, I have no clue what's causing the issue.after that, the button stopped working, if you'll believe it.
I recommend you, again, to create another brand-new project. Move some code from your actual project to it one by one , until you can reproduce the issue. (You may need to modify your project settings and code to make it build and run with the limited resources for each step.) That may reveal what may be affecting.