SwiftUI navigationBarTitle - displayMode: .inline - Crash
Asked Answered
I

1

8

I have a problem with SwiftUI. I am creating a list with a navigation bar, and I want to set navigation bar mode to inline, I don't want it to be large which is by default. But when I set navigation bar title mode to inline, the app crashes.

struct User {
    var index: Int
    var name: String
}

struct ContentView : View {
    var users: [User] = [
        User(index: 0, name: "Peter"),
        User(index: 1, name: "Marko"),
        User(index: 2, name: "John")]

    var body: some View {
        NavigationView {
            List(users.identified(by: \.index)) {
                UserRow(user: $0)
            }
            .navigationBarTitle(Text("Users"), displayMode: .inline)
        }
    }
}

struct UserRow: View {
    var user: User
    var body: some View {
        Text(user.name)
    }
}

I suppose that it is a SwiftUI bug.

Does someone know what could be the problem? Thanks in advance.

Ides answered 19/7, 2019 at 8:1 Comment(8)
The above code is working fine. perhaps some other issues might affect a crash. Which XCode Beta version you use?Awaken
I've tried with beta 1 and the latest beta 4. It crashes all the time. Maybe the problem is because I'm testing on simulator. The app crashes in line: window.makeKeyAndVisible() I get the error: "nw_endpoint_get_type called with null endpoint ... __nwlog_err_simulate_crash simulate crash already simulated nw_endpoint_get_type called with null endpoint ..." Some other people also have reported similar problem: forums.developer.apple.com/thread/120104Ides
I think that it is a problem with: UINavigationBar.appearance().isTranslucent = false. When I remove this line, the code doesn't crash any more.Ides
There are also some bugs in new XCode beta. Obviously, this code is Ok, but we are waiting for new XCode versionsIdes
This still happens even after XCode 11 was officially released. Not sure if it would work on a barebones SwiftUI-app, but our case does not where we have UIHostingController wrapping the SwiftUI view(s).Defense
I have the same problem since I added UINavigationBar.appearance().isTranslucent = falseGildus
Seem like Swift UI bug, UINavigationBar.appearance().isTranslucent = false , navigationBarTitle - displayMode: .inline and .navigationViewStyle(StackNavigationViewStyle()) combination made crash for me. I gonna remove UINavigationBar.appearance().isTranslucent = false for now to solveRasbora
@VladimirDinic how did you end up fixing it? I'm having users crashing due to this bug when they run 13.2 or 13.3Misconception
R
0

Looks like it is fixed in Xcode 11.4 beta 2

Reis answered 21/2, 2020 at 21:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.