myanmarking
08/11/2023, 9:38 AMmyanmarking
08/11/2023, 9:38 AMmyanmarking
08/11/2023, 9:38 AM<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="<http://schemas.android.com/apk/res/android>"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.prozis.main_app.ui.dashboard.view.BottomBarScaffoldView
android:id="@+id/bottomBarScaffoldView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
myanmarking
08/11/2023, 9:39 AMabstract class BridgeComposeFrameLayout @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
) : FrameLayout(context, attrs, defStyleAttr) {
private val darkTheme = mutableStateOf(
when (context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
Configuration.UI_MODE_NIGHT_NO -> false
else -> true
},
)
init {
this.addView(
ComposeView(this.context).apply {
setContent(
content = {
Screen(darkTheme.value)
},
)
},
)
this.context.findActivity()
.addOnConfigurationChangedListener {
val darkTheme =
when (it.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
Configuration.UI_MODE_NIGHT_NO -> false
else -> true
}
if (darkTheme != this.darkTheme.value) {
this.darkTheme.value = darkTheme
}
}
}
@Composable
abstract fun Screen(darkTheme: Boolean)
}
Alex Vanyo
08/12/2023, 12:33 AMisSystemIsDarkTheme
checks the value of the configuration from LocalConfiguration
directly, which will return a new value when there’s a new configuration, so I’m surprised that the workaround above works but isSystemInDarkTheme
doesn’t. Do you have a sample when isSystemInDarkTheme
isn’t updating?myanmarking
08/21/2023, 9:53 AMmyanmarking
08/21/2023, 10:43 AM