2

New iOS 15 makes navigation bar background completely transparent if there is no element behind, if there is a List and you scroll the elements to be behind the navigation bar this obtains a white translucent background, but if I use a TabView where every TabItem have a List inside the navigation bar background did not update correctly when switching between tab items, the navigation bar keep always transparent background.

Im using SwiftUI and my basic code looks like this:

struct Main: View {
    var body: some View {
        WindowGroup {
            NavigationView {
                TabView {
                    TabElement()
                    TabElement()
                    TabElement()
                    TabElement()
                    TabElement()
                }.navigationBarTitle(Text("Main"), displayMode: .inline).navigationBarBackButtonHidden(true)
            }
        }
    }
}

struct TabElement: View {
    var body: some View {
        VStack {
            List {
               Text("empty")
               Text("empty")
               Text("empty")
               Text("empty")
               Text("empty")
               Text("empty")
               Text("empty")
               Text("empty")
               Text("empty")
               Text("empty")
           }.listStyle(InsetGroupedListStyle())
        }.tabItem {
            Image(systemName: "star.fill")
            Text("dummy")
        }
    }
}

So, this code makes a tabed view with five tabs, each tab have a list of ten Text views, if I switch to any other tab and scroll the elements to the top, the list can be seen through navigation bar instead of behind.

enter image description here

What is causing this behavior? It's some kind of bug or my code is wrong? This problem is not happening in iOS 14.* since navigation bar always have white background.

NOTE: I found that it is possible to use:

if #available(iOS 15, *) {
    let appearance = UINavigationBarAppearance()
    appearance.configureWithOpaqueBackground()
    UINavigationBar.appearance().standardAppearance = appearance
    UINavigationBar.appearance().scrollEdgeAppearance = appearance
}

...in my ApDelegate but it's look like a tricky way to get rid of the transparency in navigation bar. If Apple decide to use this new design in iOS 15 I wanna implement it in my app, but only if the transparency update correctly.

Steven-Carrot
  • 2,368
  • 2
  • 12
  • 37
lcpr_phoenix
  • 373
  • 4
  • 15

1 Answers1

0

Yes apple has changed that in iOS 15.
If you want to change the appearance of the navigation bar in a single ViewController, you can use this code: https://stackoverflow.com/a/69493819/9263676

IluSioN
  • 923
  • 8
  • 20