@@ -13,6 +13,8 @@ import androidx.activity.enableEdgeToEdge
1313import androidx.activity.viewModels
1414import androidx.appcompat.app.AppCompatActivity
1515import androidx.compose.foundation.isSystemInDarkTheme
16+ import androidx.compose.foundation.layout.Box
17+ import androidx.compose.foundation.layout.fillMaxSize
1618import androidx.compose.material3.ColorScheme
1719import androidx.compose.material3.MaterialTheme
1820import androidx.compose.material3.Typography
@@ -21,11 +23,18 @@ import androidx.compose.material3.dynamicDarkColorScheme
2123import androidx.compose.material3.dynamicLightColorScheme
2224import androidx.compose.material3.lightColorScheme
2325import androidx.compose.runtime.Composable
26+ import androidx.compose.runtime.CompositionLocalProvider
2427import androidx.compose.runtime.collectAsState
2528import androidx.compose.runtime.getValue
29+ import androidx.compose.runtime.mutableStateOf
30+ import androidx.compose.runtime.remember
31+ import androidx.compose.runtime.setValue
32+ import androidx.compose.ui.Modifier
33+ import androidx.compose.ui.layout.onGloballyPositioned
2634import androidx.compose.ui.platform.LocalFocusManager
2735import androidx.compose.ui.res.colorResource
2836import androidx.compose.ui.res.stringResource
37+ import androidx.compose.ui.unit.IntSize
2938import androidx.lifecycle.ViewModel
3039import androidx.lifecycle.viewmodel.initializer
3140import androidx.lifecycle.viewmodel.viewModelFactory
@@ -35,6 +44,7 @@ import f.cking.software.data.helpers.ActivityProvider
3544import f.cking.software.data.helpers.IntentHelper
3645import f.cking.software.data.helpers.PermissionHelper
3746import f.cking.software.isDarkModeOn
47+ import f.cking.software.utils.ScreenSizeLocal
3848import f.cking.software.utils.graphic.rememberProgressDialog
3949import f.cking.software.utils.navigation.BackCommand
4050import f.cking.software.utils.navigation.Navigator
@@ -86,13 +96,24 @@ class MainActivity : AppCompatActivity() {
8696 bodySmall = MaterialTheme .typography.bodySmall.copy(color = colors.onSurface),
8797 )
8898 ) {
89- val stack = viewModel.navigator.stack
90- if (stack.isEmpty()) {
91- finish()
92- } else {
93- focusManager.clearFocus(true )
94- stack.forEach { screen ->
95- screen()
99+ var screenSize by remember { mutableStateOf(IntSize (0 , 0 )) }
100+ Box (
101+ modifier = Modifier
102+ .fillMaxSize()
103+ .onGloballyPositioned { layoutCoordinates ->
104+ screenSize = layoutCoordinates.size
105+ }
106+ ) {
107+ val stack = viewModel.navigator.stack
108+ if (stack.isEmpty()) {
109+ finish()
110+ } else {
111+ focusManager.clearFocus(true )
112+ CompositionLocalProvider (ScreenSizeLocal provides screenSize) {
113+ stack.forEach { screen ->
114+ screen()
115+ }
116+ }
96117 }
97118 }
98119
@@ -183,6 +204,7 @@ class MainActivity : AppCompatActivity() {
183204 outlineVariant = colorResource(id = R .color.md_theme_dark_outlineVariant),
184205 scrim = colorResource(id = R .color.md_theme_dark_scrim),
185206 )
207+
186208 ! darkMode -> lightColorScheme(
187209 primary = colorResource(id = R .color.md_theme_light_primary),
188210 onPrimary = colorResource(id = R .color.md_theme_light_onPrimary),
@@ -217,6 +239,7 @@ class MainActivity : AppCompatActivity() {
217239 outlineVariant = colorResource(id = R .color.md_theme_light_outlineVariant),
218240 scrim = colorResource(id = R .color.md_theme_light_scrim),
219241 )
242+
220243 else -> throw IllegalStateException (" This state is unreachable" )
221244 }
222245 return colors
0 commit comments