当我使用导航组合在深色主题中导航到屏幕时,屏幕闪烁

Ali*_*Ali 8 android navigation-compose

我在我的应用程序中使用 Navigation-Compose :

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)
                    }
                }
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

我在每个屏幕上都有一个单独的应用程序栏,例如:

@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)
                    )
                }
            }
        })
}
Run Code Online (Sandbox Code Playgroud)

当我在深色主题中在屏幕之间导航时,屏幕会闪烁。当深色主题关闭时,appBar 上会有一个小闪烁。如何解决呢?

我的项目的源代码可以在这里找到: https: //github.com/alirezaeiii/Navigation-Compose

附录:

我发现,如果我们使用此链接中所示的伴奏库:TopAppBar flashing when navigating with Compose Navigation Flashing 问题将得到解决,但必须使用伴奏。

小智 4

我在没有使用伴奏库(并覆盖动画效果)的情况下解决了这个问题。

您是否确保您AppTheme所申请的manifest.xml用途DayNight

默认情况下,您的项目可能使用:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

您可以将其替换为:
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">