HomeiOS Developmentios - Change Content material of TabView Dynamically Trigger Web page to...

ios – Change Content material of TabView Dynamically Trigger Web page to Grow to be Clean


When I attempt to change the content material of a TabView in runtime, the app crashes or present a clean display screen. Platform: Xcode 15.0 beta 6 (15A5219j) / iOS 17.0 beta 5 (21A5303d)

Under is the minimal code that may reproduce this situation. Notice that this code will run usually as anticipated on iOS 16.

import SwiftUI

class Coordinator: ObservableObject {
    @Printed var open = false
}

struct TabbedView: View {
    @StateObject var coordinator = Coordinator()
    
    var physique: some View {
        TabView {
            if coordinator.open {
                Textual content("Good day World!")
                    .tabItem {
                        Label("Characteristic", systemImage: "star")
                    }
            }
            
            SettingsView()
                .tabItem {
                    Label("Settings", systemImage: "gear")
                }
        }
        .environmentObject(coordinator)
    }
}

struct SettingsView: View {
    @EnvironmentObject var coordinator: Coordinator
    
    var physique: some View {
        NavigationStack {
            Checklist {
                Button("Toggle") {
                    coordinator.open.toggle()
                }
            }
            .navigationTitle("Settings")
        }
    }
}

The app has 2 sections: A clean function part and a settings part. Within the settings part, there’s a button that may management whether or not the function part ought to seem. After I faucet the button for the primary time, the function part seems usually. Nonetheless, once I faucet the button for the second time, the function part disappears, however all content material inside settings part disappears, the web page simply change into clean.

The NavigationStack is essential for the bug to look. Did I do one thing fallacious right here, or is it a bug of SwiftUI?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments