This is my code with swiftui, when I click button => change tradingMode inside sheet => after show keyboard from ContentView => app crash. Please help me and thanks!
and video bug
drive.google.com/file/d/18eXCmlByGqJylEhCZbtJ4Rn0wmI0bb/view
Code Block enum TradingMode { case Derivatives, Equities } struct ContentView: View { @State var tradingMode : TradingMode = TradingMode.Equities @State var isShowSecondView = false var body: some View { VStack(content: { Button("show second view") { isShowSecondView.toggle() } TabView { switch tradingMode { case .Equities: VStack(content: { Text("Tab 1 Un") .padding() TextField("ple", text: .constant("")) }) .tabItem { Text("tab 1") }.tag(0) case .Derivatives: VStack(content: { Text("Tab 1 Der") .padding() TextField("ple", text: .constant("")) }) .tabItem { Text("tab 1") }.tag(0) } switch tradingMode { case .Equities: VStack(content: { Text("Tab 2 Un") .padding() TextField("ple", text: .constant("")) }) .tabItem { Text("tab 2") }.tag(1) case .Derivatives: VStack(content: { Text("Tab 2 Der") .padding() TextField("ple", text: .constant("")) }) .tabItem { Text("tab 2") }.tag(1) } } }) .sheet(isPresented: $isShowSecondView, content: { SecondView(tradingMode: $tradingMode) }) } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() .previewLayout(.device) } } struct SecondView: View { @Environment(\.presentationMode) var presentation @Binding var tradingMode : TradingMode var body: some View { VStack(content: { Button("Change state") { if tradingMode == .Derivatives { tradingMode = .Equities } else { tradingMode = .Derivatives } self.presentation.wrappedValue.dismiss() } }) } }
and video bug
drive.google.com/file/d/18eXCmlByGqJylEhCZbtJ4Rn0wmI0bb/view
You may have tried already (and this may be difficult to apply to your actual app), but this is the only workaround I could have found till now:
Code Block struct ContentView: View { @State var tradingMode : TradingMode = TradingMode.Equities @State var isShowSecondView = false var body: some View { VStack(content: { Button("show second view") { isShowSecondView.toggle() } TabView { switch tradingMode { case .Equities: VStack(content: { Text("Tab 1 Un") .padding() TextField("ple", text: .constant("")) }) .tabItem { Text("tab 1") }.tag(0) VStack(content: { Text("Tab 2 Un") .padding() TextField("ple", text: .constant("")) }) .tabItem { Text("tab 2") }.tag(1) case .Derivatives: VStack(content: { Text("Tab 1 Der") .padding() TextField("ple", text: .constant("")) }) .tabItem { Text("tab 1") }.tag(0) VStack(content: { Text("Tab 2 Der") .padding() TextField("ple", text: .constant("")) }) .tabItem { Text("tab 2") }.tag(1) } } }) .sheet(isPresented: $isShowSecondView, content: { SecondView(tradingMode: $tradingMode) }) } }