Reputation: 818
I have a View
in a tab bar application, where I need to hide the toolbar (navigation bar). By using .toolbar(.hidden)
on the View
, I have hidden the toolbar. But, I need to unhide the same toolbar on leaving the view, either it is NavigationLink
or Sheet
. For that I have added a @State var showToolbar = false
and in .onDisappear
, I have made it to showToolbar = true
and update toolbar visibility code as .toolbar(showToolbar ? .visible : .hidden)
. But this .onDisappear
acts as UIKit's viewDidDisappear
, so toolbar is still in hidden state in next/previous view.
To achieve UIKit's viewWillDisappear
I have referred the code mentioned here and used onWillDisappear
to update showToolbar = true
. But the issue remains same after following this approach. We have an option to make toolbar visible on other views by adding .toolbar(.visible)
, but I don't want write code in every view, because we have lot of navigations to different views as we support push notification, deep link and tab bar. Someone please help on handling toolbar visibility based on view life cycle within the same view, like hiding toolbar while view appears and unhiding toolbar while view disappears. Also, let me know if .toolbar(showToolbar ? .visible : .hidden)
will render with showToolbar
changes.
UPDATE: I tried by making showToolbar = true
on tap of some button action, it's working and toolbar got displayed. Please help me on achieving the same thing in .onWillDisappear
.
Upvotes: 0
Views: 70