Dovydas
02/09/2025, 2:47 PMDovydas
02/09/2025, 2:48 PM@Composable
fun AppScreenRoot(
viewModel: AppViewModel = koinViewModel<AppViewModel>(),
onNotLoggedInToEsm: () -> Unit,
onNotLoggedInToSms: () -> Unit,
) {
val state by viewModel.state.collectAsStateWithLifecycle()
AppScreen(
state = state,
onAction = { action ->
viewModel.onAction(action)
},
)
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AppScreen(
state: AppState,
onAction: (AppAction) -> Unit,
) {
val pagerState = rememberPagerState(
pageCount = { AppTabs.entries.size },
)
val refreshState = rememberPullToRefreshState()
Column {
AppTopBar(
modifier = Modifier.fillMaxWidth().statusBarsPadding().padding(vertical = 10.dp, horizontal = 4.dp),
pagerState = pagerState
)
RefreshIndicator(
modifier = Modifier.fillMaxWidth(),
refreshState= refreshState,
isRefreshing = { state.isRefreshing }
)
HorizontalPager(
modifier = Modifier.fillMaxSize(),
pageSpacing = 30.dp,
state = pagerState,
) {
TimetableScreenRoot(
onRefreshStart = { onAction(AppAction.onRefreshStart) },
onRefreshStop = { onAction(AppAction.onRefreshStop) },
refreshState
)
}
}
}
Dovydas
02/09/2025, 2:49 PMDovydas
02/09/2025, 2:50 PMZach Klippenstein (he/him) [MOD]
02/09/2025, 5:50 PMDovydas
02/09/2025, 5:51 PMdata class AppState(
val isEsmLoggedIn: Boolean = false,
val isSmsLoggedIn: Boolean = false,
val isInitialized: Boolean = false,
val isRefreshing: Boolean = false,
)
Zach Klippenstein (he/him) [MOD]
02/09/2025, 5:54 PMDovydas
02/09/2025, 5:54 PMZach Klippenstein (he/him) [MOD]
02/09/2025, 5:55 PMZach Klippenstein (he/him) [MOD]
02/09/2025, 5:55 PMDovydas
02/09/2025, 5:55 PMfun AppScreen(
state: () -> AppState,
onAction: (AppAction) -> Unit,
) {
But is that really the correct wayDovydas
02/09/2025, 5:56 PMZach Klippenstein (he/him) [MOD]
02/09/2025, 5:57 PMDovydas
02/09/2025, 5:59 PM@Composable
fun AppTopBar(
modifier: Modifier = Modifier,
pagerState: PagerState
) {
pagerState is just rememberPagerState, sorry if this is a noob question, but how would I check if it's stable?Zach Klippenstein (he/him) [MOD]
02/09/2025, 6:03 PMZach Klippenstein (he/him) [MOD]
02/09/2025, 6:04 PM@Stable
annotation then that also tells youZach Klippenstein (he/him) [MOD]
02/09/2025, 6:04 PMZach Klippenstein (he/him) [MOD]
02/09/2025, 6:05 PMDovydas
02/09/2025, 6:07 PMDovydas
02/09/2025, 6:18 PMstatusBarPadding
modifier that is causing it to recompose:
AppTopBar(
modifier = Modifier.fillMaxWidth().padding(vertical = 10.dp, horizontal = 4.dp).statusBarsPadding(),
pagerState = pagerState
)
Dovydas
02/09/2025, 6:20 PMAppTopBar
then it doesn't recompose but I'd prefer to keep it on the parent screenZach Klippenstein (he/him) [MOD]
02/09/2025, 6:34 PMwindowInsetsPadding
which is inline AND uses composed
, i think it might be recomposing because statusBarsPadding
which calls it passes a no-inline inspectorInfo
lambda but is not itself composable, which means compose won’t memoize the lambda, so it’s going to be a different instance each time you call the modifier. I bet this is an oversight, i would file a bug.Zach Klippenstein (he/him) [MOD]
02/09/2025, 6:35 PM