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?