I am using Navigation-Compose in my app :
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
ComposeTheme {
val navController = rememberNavController()
NavHost(navController = navController, startDestination = Screens.Dashboard.title) {
composable(Screens.Dashboard.title) {
DashboardScreen(navController)
}
composable(
Screens.Section.title, arguments = listOf(
navArgument(LINK) {
type = AssetParamType()
}
)
) {
SectionDetailsScreen(navController)
}
}
}
}
}
I have a separate appBar in every screen such as :
@Composable
fun DashboardScreen(
navController: NavHostController,
viewModel: DashboardViewModel = hiltViewModel()
) {
Scaffold(
topBar = {
TopAppBar(
title = {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.fillMaxSize()
) {
Text(text = stringResource(id = R.string.label_dashboard))
}
},
elevation = 8.dp,
modifier = Modifier.clip(
RoundedCornerShape(bottomStart = 18.dp, bottomEnd = 18.dp)
)
)
},
content = {
Content(viewModel = viewModel) { dashboard ->
VerticalCollection(dashboard) { link ->
val json = Uri.encode(Gson().toJson(link))
navController.navigate(
Screens.Section.title.replace
("{${LINK}}", json)
)
}
}
})
}
Screens are flashing when I navigate between them in Dark theme. There is a small flashing on appBar when dark theme is off. How to resolve it?
Source code of my project can be found here : https://github.com/alirezaeiii/Navigation-Compose
Addenda :
I found out that if we get use of accompanist library as indicated in this link : TopAppBar flashing when navigating with Compose Navigation Flashing issue will be resolved, but it is a must to use accompanist.
I solved screen flashing like this but topBar is flashing. Change windowBackground according to your dark or light theme using
When you do this, your background will be the same as your Compose background, so it won't be flashing.
I solved topper flashing too
I changed my top bar colors
Also try to implement dark mode like now in android app.you don't need my first recommendation.They solve more cleaner way
Now in android sample