Mehdi Haghgoo
11/09/2021, 2:58 PMclass AppState(
val player: MediaPlayer,
val recorder: MediaRecorder,
var mediaState: MediaState,
val scaffoldState: ScaffoldState,
val navController: NavHostController,
private val resources: Resources
){
fun navigateToBottomBarRoute(route:String){
navController.navigate(route){
popUpTo(navController.graph.findStartDestination().id){
saveState = true
}
restoreState = true
launchSingleTop = true
}
}
@OptIn(DelicateCoroutinesApi::class)
fun showSnackbar(message: String){
GlobalScope.launch {
scaffoldState.snackbarHostState.showSnackbar(message, duration = SnackbarDuration.Long)
}
}
}
And i access the state as follows:
@Composable
fun rememberAppState(
player: MediaPlayer,
recorder: MediaRecorder,
mediaState: MediaState,
scaffoldState: ScaffoldState,
navController: NavHostController,
resources: Resources = LocalContext.current.resources
) = remember(player, recorder, mediaState, scaffoldState, navController, resources){
AppState(player, recorder, mediaState, scaffoldState, navController, resources)
}
For some reason, when I change the value of a component e.g. mediaState, the composables using it are not recomposed, so my UI is not updated unless I navigate to another screen and come back to see the updated UI.Zach Klippenstein (he/him) [MOD]
11/09/2021, 4:33 PM