2

I have an Issue where my text disappears behind the navigation bar. The navigation bar is made visible once the user clicks on Settings (or any other menu button). It shows up and the content is visible but then when done loading the new view the text disappears behind the bar. Any solutions?

I change the status of the navigation bar being visible with .onAppear and .onDisappear of views that are root level. enter image description here

Code something like this:


struct ContentView: View {

    @State public var navBarHidden = true

    var body: some View {

        NavigationView{
            VStack{
                ZStack(alignment: .center){
                    WhiteImage().onAppear{self.navBarHidden = true} //Here only seen as white background
                    BottomButtons().onDisappear{self.navBarHidden = false}
                    ProfileInvoke().navigationBarTitle("").navigationBarHidden(self.navBarHidden)
                }
            }
        }
    }
}

//The buttons are done with such a construct

struct MenuButton: View {

    var buttonText: String
    var buttonCallView: AnyView

    var body: some View {
        NavigationLink(destination: self.buttonCallView) {
            Text(self.buttonText)
        }.padding()

    }
}

//Population of a button

MenuButton(buttonText: "My Favourites", buttonCallView: AnyView(MyFavouritesView().navigationBarTitle(Text("My Favourites"), displayMode: .inline)))


// The settings view where the title disappears 

struct SettingsView: View {

    var body: some View {
        HStack(alignment: .top){
            VStack(alignment: .leading){
                Text("General").bold()
                Divider()
                Spacer()
            }.padding()
            Spacer()
        }
    }
}

I have the feeling that it has something to do with the .onAppear and .onDisappear where I set the status of the navigation bar being hidden or not. Ain't sure tho.

Simon
  • 1,754
  • 14
  • 32
  • Any solution can be only for any demo code... – Asperi Apr 05 '20 at 16:28
  • @Asperi You are right. Added the code needed to understand what I'm doing here. Thanks. – Simon Apr 05 '20 at 16:45
  • onAppear is ok, onDisappear is too late... see [this my post](https://stackoverflow.com/a/60996978/12299030) for solution of similar use-case. – Asperi Apr 05 '20 at 16:59
  • @Asperi Issue is with that is, that I "uninvoke" my menu by tapping on the greyed out side next to it. (Its a slide out menu). As the gray area next to it is also part of it I do reset the hidden status to false as I'm tapping it again. – Simon Apr 05 '20 at 17:30

0 Answers0