'LayoutConstraints error when changing from a Tab to another Tab (TabView)

I have the below BaseView which holds a TabView, but I have some layoutConstrains errors when navigation to Workouts [.tag(Page.workouts)] tab.

WorkoutTabView has only a Text inside.

If I delete the NavigationView (check code below), the errors does not occur anymore.

Can anyone explain and maybe help me fix this? I can run the app but I don't think is a good idea to forget about the errors and just continue developing the app. :)

These are the errors:

2022-05-08 14:05:36.004019+0300 FitnessApp[3198:96825] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x600003b6e9e0 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x134581790]-(6)-[_UIModernBarButton:0x134546800'Workouts']   (active)>",
    "<NSLayoutConstraint:0x600003b6e990 'CB_Trailing_Trailing' _UIModernBarButton:0x134546800'Workouts'.trailing <= _UIButtonBarButton:0x134561170.trailing   (active)>",
    "<NSLayoutConstraint:0x600003b6fa70 'UINav_static_button_horiz_position' _UIModernBarButton:0x134581790.leading == UILayoutGuide:0x600002168c40'UIViewLayoutMarginsGuide'.leading   (active)>",
    "<NSLayoutConstraint:0x600003b6fb60 'UINavItemContentGuide-leading' H:[_UIButtonBarButton:0x134561170]-(6)-[UILayoutGuide:0x6000021689a0'UINavigationBarItemContentLayoutGuide']   (active)>",
    "<NSLayoutConstraint:0x600003b73b10 'UINavItemContentGuide-trailing' UILayoutGuide:0x6000021689a0'UINavigationBarItemContentLayoutGuide'.trailing == _UINavigationBarContentView:0x13453e340.trailing   (active)>",
    "<NSLayoutConstraint:0x600003b14e60 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x13453e340.width == 0   (active)>",
    "<NSLayoutConstraint:0x600003b73ed0 'UIView-leftMargin-guide-constraint' H:|-(8)-[UILayoutGuide:0x600002168c40'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UINavigationBarContentView:0x13453e340 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600003b6e9e0 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x134581790]-(6)-[_UIModernBarButton:0x134546800'Workouts']   (active)>

struct BaseView: View {
    @EnvironmentObject var workoutManager: WorkoutManager
    @EnvironmentObject var dateModel: DateModel
    @EnvironmentObject var viewRouter: ViewRouter

    @State private var isShowingAddWorkoutSheet = false

    var body: some View {
        TabView(selection: $viewRouter.currentTab) {
            HomeTabView()
                .tabItem {
                    Image(systemName: "house")
                    Text("Home")
                }
                .tag(Page.home)

            CalendarTabView()
                .tabItem {
                    Image(systemName: "calendar")
                    Text("Calendar")
                }
                .tag(Page.calendar)

            NavigationView {
                WorkoutTabView()
                .navigationTitle("Workouts")
                .toolbar {
                    Button {
                        isShowingAddWorkoutSheet.toggle()
                    } label: {
                        Image(systemName: "plus")
                    }
                    .accessibilityLabel("Add new Workout")
                    .sheet(isPresented: $isShowingAddWorkoutSheet) {
                        AddWorkoutView()
                    }
                }
            }
            .tabItem {
                Image(systemName: "list.bullet.rectangle")
                Text("Workouts")
            }
            .tag(Page.workouts)

            ProfileTabView()
                .tabItem {
                    Image(systemName: "person")
                    Text("Profile")
                }
                .tag(Page.profile)
        }
    }
}

struct WorkoutTabView: View {
    @EnvironmentObject var workoutManager: WorkoutManager
    @EnvironmentObject var dateModel: DateModel

    var body: some View {
        Text("Workouts")
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source