Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Body Render Issue with NavigationStack in XCode 14 Beta

In the following code, background color of the ContentView doesn’t change after two seconds.

struct ContentView: View {
    @State private var bool: Bool = false
    
    var body: some View {
        NavigationStack(root: {
            Group(content: {
                if bool {
                    Color.red
                } else {
                    Color.blue
                }
            })
                .onAppear(perform: {
                    DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
                        print(">>>")
                        bool = true
                    })
                })
        })
    }
}

However, when replacing NavigationStack(root: { with NavigationView(content: {, the problem disappears.

Is anyone facing the same problem, or am I doing something wrong? I am using XCode 14.0 beta 2 (14A5229c), and running it on iOS 16.0 (20A5303i). Issue happens on both, simulator and physical device.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Who knows… may be it is intentional may be it is a bug, submit feedback to Apple.

Meanwhile here is a workaround, tested with Xcode 14 / iOS 16

    NavigationStack {
        if bool {
            Color.red
        } else {
            Color.blue
        }
    }
    .id(bool)             // << here !!

*BTW, Group is not needed anymore in such cases.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading