@@ -9,10 +9,12 @@ import androidx.compose.foundation.layout.fillMaxSize
99import androidx.compose.foundation.layout.padding
1010import androidx.compose.material3.Scaffold
1111import androidx.compose.runtime.Composable
12+ import androidx.compose.runtime.CompositionLocalProvider
1213import androidx.compose.runtime.getValue
1314import androidx.compose.runtime.mutableStateOf
1415import androidx.compose.runtime.remember
1516import androidx.compose.runtime.setValue
17+ import androidx.compose.runtime.staticCompositionLocalOf
1618import androidx.compose.ui.Modifier
1719import androidx.compose.ui.zIndex
1820import cafe.adriel.voyager.navigator.LocalNavigator
@@ -29,6 +31,8 @@ import de.markusressel.mkdocseditor.feature.main.ui.compose.tab.FileBrowserTab
2931import de.markusressel.mkdocseditor.feature.main.ui.compose.tab.SettingsTab
3032import de.markusressel.mkdocseditor.ui.activity.UiState
3133
34+ val LocalMainScreenOnBack = staticCompositionLocalOf< () -> Unit > { {} }
35+
3236@SuppressLint(" UnusedMaterial3ScaffoldPaddingParameter" )
3337@Composable
3438internal fun MainScreenContent (
@@ -51,55 +55,54 @@ internal fun MainScreenContent(
5155 )
5256 }
5357
54- TabNavigator (
55- tab = uiState.initialTab.toTab (
56- contentType = contentType,
57- onBackPressed = onBackPressedCallback
58- )
59- ) { tabNavigator ->
60- globalTabNavigator = tabNavigator
58+ CompositionLocalProvider ( LocalMainScreenOnBack provides onBackPressedCallback) {
59+ TabNavigator (
60+ tab = uiState.initialTab.toTab(
61+ contentType = contentType,
62+ )
63+ ) { tabNavigator ->
64+ globalTabNavigator = tabNavigator
6165
62- Scaffold (
63- bottomBar = {
64- if (navigationType == NavigationLayoutType .BOTTOM_NAVIGATION ) {
65- BottomBar (
66- selectedNavItem = tabNavigator.current.toNavItem(),
67- navItems = uiState.bottomBarNavItems,
68- onItemSelected = { navItem ->
69- tabNavigator.current = navItem.toTab(
70- contentType = contentType,
71- onBackPressed = onBackPressedCallback
72- )
73- },
74- )
75- }
76- }
77- ) { paddingValues ->
78- Box (
79- modifier = Modifier .padding(
80- bottom = paddingValues.calculateBottomPadding()
81- )
82- ) {
83- Row {
84- // Navigation Rail
85- AnimatedVisibility (
86- modifier = Modifier .zIndex(1000f ),
87- visible = navigationType == NavigationLayoutType .NAVIGATION_RAIL
88- ) {
89- MkDocsEditorNavigationRail (
66+ Scaffold (
67+ bottomBar = {
68+ if (navigationType == NavigationLayoutType .BOTTOM_NAVIGATION ) {
69+ BottomBar (
9070 selectedNavItem = tabNavigator.current.toNavItem(),
9171 navItems = uiState.bottomBarNavItems,
9272 onItemSelected = { navItem ->
9373 tabNavigator.current = navItem.toTab(
9474 contentType = contentType,
95- onBackPressed = onBackPressedCallback
9675 )
9776 },
9877 )
9978 }
79+ }
80+ ) { paddingValues ->
81+ Box (
82+ modifier = Modifier .padding(
83+ bottom = paddingValues.calculateBottomPadding()
84+ )
85+ ) {
86+ Row {
87+ // Navigation Rail
88+ AnimatedVisibility (
89+ modifier = Modifier .zIndex(1000f ),
90+ visible = navigationType == NavigationLayoutType .NAVIGATION_RAIL
91+ ) {
92+ MkDocsEditorNavigationRail (
93+ selectedNavItem = tabNavigator.current.toNavItem(),
94+ navItems = uiState.bottomBarNavItems,
95+ onItemSelected = { navItem ->
96+ tabNavigator.current = navItem.toTab(
97+ contentType = contentType,
98+ )
99+ },
100+ )
101+ }
100102
101- // Actual tab content
102- CurrentTab ()
103+ // Actual tab content
104+ CurrentTab ()
105+ }
103106 }
104107 }
105108 }
@@ -122,18 +125,16 @@ private fun onBackPressed(
122125 if (tabNavigator != null ) {
123126 tabNavigator.current = initialTab.toTab(
124127 contentType = contentType,
125- onBackPressed = { onBackPressed(navigator, tabNavigator, initialTab, contentType) }
126128 )
127129 }
128130}
129131
130132private fun NavItem.toTab (
131133 contentType : ContentLayoutType ,
132- onBackPressed : () -> Unit
133134): Tab = when (this ) {
134135 is NavItem .BackendSelection -> BackendSelectionTab
135136 is NavItem .FileBrowser -> FileBrowserTab (contentType)
136- is NavItem .Settings -> SettingsTab (onBackPressed)
137+ is NavItem .Settings -> SettingsTab
137138 is NavItem .About -> AboutTab
138139}
139140
0 commit comments