0

I have this weird issue. When I click the ColorPicker, the view dismissed and pop back to the root view. I have attach a screen record below. Anyone have idea how to fix this issue?

The code run on simulator ios 15.2

See screen record here

import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationView {
            TabView {
                HomePageView()
                    .tabItem {
                        Label("Home", systemImage: "circle.grid.cross.fill")
                    }
              
                ProfileView()
                    .tabItem {
                        Label("Profile", systemImage: "person.fill")
                    }
            }
            .background(.secondary)
        }
    }
}

struct HomePageView: View {
    var body: some View {
        Text("Home View")
    }
}

struct ProfileView: View {
    var body: some View {
        NavigationLink {
            ColorPickerView()
        } label: {
            Text("Color Picker View")
        }
    }
}

struct ColorPickerView: View {
    @State var bgColor = Color.blue
    var body: some View {
        ColorPicker("Pick color", selection: self.$bgColor)
            .padding(.horizontal, 15)
    }
}
yang1818
  • 3
  • 1

2 Answers2

0

NavigationView in each tab instead of outside the TabView

lorem ipsum
  • 21,175
  • 5
  • 24
  • 48
  • Hi @loremipsum, so after I put the NavigationView inside each tab item, the bottom tab bar always appear inside each detailed view. Do you know how to hide it? – yang1818 Feb 08 '22 at 13:26
  • @yang1818 There are workarounds out there for hiding like your original question and the other solutions in the comments but that behavior goes against apple [guidelines](https://developer.apple.com/design/human-interface-guidelines/ios/bars/tab-bars/) there is no perfect solution to hiding the tabbar as far as I know. You always give something up. – lorem ipsum Feb 08 '22 at 13:47
0

New suggestion: Use NavigationStack in iOS16 to overcome the issue of popping to the previous or sometimes to the root view.

Tob
  • 627
  • 6
  • 9