adrielcafe / voyager

🛸 A pragmatic navigation library for Jetpack Compose
https://voyager.adriel.cafe
MIT License
2.54k stars 129 forks source link

Can't switch dark theme in compose-m3 1.2.0+ and NestedNavigator #489

Open qdsfdhvh opened 1 week ago

qdsfdhvh commented 1 week ago

Hi, I'm using voyager with compose-multiplatform 1.6.11 and I'm having an issue with the dark theme switching, codes like this:

setContent {
    var isNight by remember {
        mutableStateOf(false)
    }
    SwitchthemeinnestednavigatorTheme(isNight) {
        Navigator(HiddenScreen) {
            Navigator(HiddenScreen) { // ✅ if hide this line
                Scaffold { innerPadding ->
                    ...
                }
            }
        }
    }
}
implementation(compose.material3) // same with 1.2.1 🚫
// implementation("androidx.compose.material3:material3:1.1.2") // ✅
// implementation("androidx.compose.material3:material3:1.2.0") // 🚫
// implementation("androidx.compose.material3:material3:1.2.1") // 🚫
// implementation("androidx.compose.material3:material3:1.3.0") // 🚫

Nested Navigator will cause the dark theme to not switch, currently, I found two workaround:

  1. remove nested navigator.

  2. downgrade compose-md3 to 1.1.0+.

But I haven't found the real reason yet and need to ask for help.

demo: https://github.com/qdsfdhvh/switch-theme-in-nested-navigator

hristogochev commented 1 week ago

This may be related to https://github.com/adrielcafe/voyager/issues/486 and https://github.com/adrielcafe/voyager/issues/484, seems like the newest versions of compose partially break nested navigation in voyager.