Skip to content

Commit f96ebfe

Browse files
committed
fix crash
1 parent 3ce9ad4 commit f96ebfe

4 files changed

Lines changed: 59 additions & 49 deletions

File tree

app/src/main/java/de/markusressel/mkdocseditor/feature/main/ui/compose/MainScreenContent.kt

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import androidx.compose.foundation.layout.fillMaxSize
99
import androidx.compose.foundation.layout.padding
1010
import androidx.compose.material3.Scaffold
1111
import androidx.compose.runtime.Composable
12+
import androidx.compose.runtime.CompositionLocalProvider
1213
import androidx.compose.runtime.getValue
1314
import androidx.compose.runtime.mutableStateOf
1415
import androidx.compose.runtime.remember
1516
import androidx.compose.runtime.setValue
17+
import androidx.compose.runtime.staticCompositionLocalOf
1618
import androidx.compose.ui.Modifier
1719
import androidx.compose.ui.zIndex
1820
import cafe.adriel.voyager.navigator.LocalNavigator
@@ -29,6 +31,8 @@ import de.markusressel.mkdocseditor.feature.main.ui.compose.tab.FileBrowserTab
2931
import de.markusressel.mkdocseditor.feature.main.ui.compose.tab.SettingsTab
3032
import de.markusressel.mkdocseditor.ui.activity.UiState
3133

34+
val LocalMainScreenOnBack = staticCompositionLocalOf<() -> Unit> { {} }
35+
3236
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
3337
@Composable
3438
internal 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

130132
private 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

app/src/main/java/de/markusressel/mkdocseditor/feature/main/ui/compose/tab/AboutTab.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package de.markusressel.mkdocseditor.feature.main.ui.compose.tab
22

3+
import androidx.activity.compose.BackHandler
34
import androidx.compose.foundation.layout.fillMaxSize
45
import androidx.compose.foundation.layout.statusBarsPadding
56
import androidx.compose.runtime.Composable
@@ -8,6 +9,7 @@ import androidx.compose.ui.Modifier
89
import cafe.adriel.voyager.navigator.tab.Tab
910
import cafe.adriel.voyager.navigator.tab.TabOptions
1011
import de.markusressel.mkdocseditor.feature.about.ui.compose.AboutScreen
12+
import de.markusressel.mkdocseditor.feature.main.ui.compose.LocalMainScreenOnBack
1113

1214
object AboutTab : Tab {
1315
override val options: TabOptions
@@ -22,6 +24,12 @@ object AboutTab : Tab {
2224

2325
@Composable
2426
override fun Content() {
27+
val onBack = LocalMainScreenOnBack.current
28+
BackHandler(
29+
enabled = true,
30+
onBack = onBack,
31+
)
32+
2533
AboutScreen(
2634
modifier = Modifier
2735
.fillMaxSize()

app/src/main/java/de/markusressel/mkdocseditor/feature/main/ui/compose/tab/SettingsTab.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ import androidx.compose.runtime.remember
66
import androidx.compose.ui.Modifier
77
import cafe.adriel.voyager.navigator.tab.Tab
88
import cafe.adriel.voyager.navigator.tab.TabOptions
9+
import de.markusressel.mkdocseditor.feature.main.ui.compose.LocalMainScreenOnBack
910
import de.markusressel.mkdocseditor.feature.preferences.ui.compose.PreferencesScreen
1011

11-
class SettingsTab(
12-
private val onBackPressed: () -> Unit,
13-
) : Tab {
12+
object SettingsTab : Tab {
1413
override val options: TabOptions
1514
@Composable
1615
get() = remember {
@@ -23,9 +22,11 @@ class SettingsTab(
2322

2423
@Composable
2524
override fun Content() {
25+
val onBack = LocalMainScreenOnBack.current
26+
2627
PreferencesScreen(
2728
modifier = Modifier.fillMaxSize(),
28-
onBack = onBackPressed,
29+
onBack = onBack,
2930
)
3031
}
3132
}

gradle/libs.versions.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ androidxActivity = "1.12.4"
66
androidxActivityCompose = "1.12.4"
77
androidxAppCompat = "1.7.1"
88
androidxDatastore = "1.2.0"
9-
androidxComposeBom = "2026.02.00"
9+
androidxComposeBom = "2026.02.01"
1010
androidxCore = "1.17.0"
1111
androidxLifecycle = "2.10.0"
1212
androidxTestExtJunit = "1.3.0"
@@ -35,7 +35,7 @@ kotlin = "2.3.10"
3535
kotlinCoroutinesCore = "1.10.2"
3636
kotlinCoroutinesAndroid = "1.10.2"
3737
ksp = "2.3.2"
38-
kutePreferences = "30843e9958"
38+
kutePreferences = "e6a98a8987"
3939
lifecycleCommonJava8 = "2.10.0"
4040
lifecycleViewmodelKtx = "2.10.0"
4141
liveevent = "1.2.0"
@@ -49,10 +49,10 @@ store4 = "4.0.7"
4949
store5 = "5.0.0"
5050
typedPreferences = "v2.1.1"
5151
materialDialogs = "0.9.0"
52-
uiToolingVersion = "1.10.3"
52+
uiToolingVersion = "1.10.4"
5353
webkitVersion = "1.15.0"
5454
windowVersion = "1.5.1"
55-
uiViewbinding = "1.10.3"
55+
uiViewbinding = "1.10.4"
5656
workTesting = "2.11.1"
5757
voyager = "1.1.0-beta03"
5858
zoomlayout = "1.9.0"

0 commit comments

Comments
 (0)