XCode 14 Beta中的NavigationStack的身体渲染问题

发布于 2025-02-12 08:23:18 字数 872 浏览 0 评论 0原文

在以下代码中,contentView的背景颜色在两秒钟后不会更改。

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
                    })
                })
        })
    }
}

root:{用navigationView(content:content:{

但是,当替换navigationStack ( 使用Xcode 14.0 beta 2(14a5229c),并在iOS 16.0上运行它(20A5303I)。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

好多鱼好多余 2025-02-19 08:23:18

谁知道...可能是故意的,这可能是一个错误,向苹果提交反馈。

同时,这里是一个解决方法,

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

在这种情况下,不再需要使用Xcode 14 / ios 16 *btw,< / code>组< / code>进行测试。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文