Issues of this method:
Issues of this method:
Thank you for your suggestion to use the add_widget/remove_widget method for managing the navigation bar visibility. While this method can work in some scenarios, it introduces a critical limitation: the loss of state. Let me explain this using a specific example:
In my App:
Hi ElliotG ,
I just wanted to say thank you for suggesting the nested ScreenManager approach for managing the navigation bar in my app. I implemented it, and it worked beautifully! It saved me a lot of effort compared to my previous method of toggling the navigation bar's visibility and initializing it in on_pre_enter() for each screen.
That said, this method adds a little complexity when navigating from a specific screen within the nested ScreenManager (e.g., home_screen) to a major screen like transaction_screen in the root ScreenManager, and vice versa.
here is the structure of main.kv:
#: include app/screens/signupscreen/signupscreen.kv
#: include app/screens/loginscreen/loginscreen.kv
#: include app/screens/navigationscreens/navigationscreens.kv
#: include app/screens/transactionscreen/transactionscreen.kv
ScreenManager:
id: screen_manager
LoginScreen:
name: 'login_screen'
SignupScreen:
name: 'signup_screen'
NavigationScreens:
name: 'nav_screens'
TransactionScreen:
name: 'transaction_screen'
here is navigationscreens.py:
from kivymd.uix.screen import MDScreen
from kivy.properties import ObjectProperty
from app.screens.homescreen.homescreen import HomeScreen
from app.screens.statisticsscreen.statisticsscreen import StatisticsScreen
class NavigationScreens(MDScreen):
nested_screen_manager = ObjectProperty()
pass
Here is navigationscreens.kv:
#: include app/screens/homescreen/homescreen.kv
#: include app/screens/statisticsscreen/statisticsscreen.kv
#: include app/customwidgets/customnavigationbar/customnavigationbar.kv
<NavigationScreens>
nested_screen_manager: nested_screen_manager
size: root.width, root.height
md_bg_color: 'white'
ScreenManager:
id: nested_screen_manager
HomeScreen:
name: 'home_screen'
StatisticsScreen:
name: 'statistics_screen'
CustomNavigationBar:
id: nested_navigation_bar
pos_hint: {'center_x': .5, 'y': 0}
on_switch_tabs: app.on_nested_switch_tabs(*args)