@@ -24,7 +24,7 @@ constructor(
24
24
private val overrideColorScheme: OverrideColorScheme ? = null
25
25
) : NativeAppearanceSpec (reactContext) {
26
26
27
- private var colorScheme = colorSchemeForCurrentConfiguration(reactContext)
27
+ private var lastEmittedColorScheme : String? = null
28
28
29
29
/* * Optional override to the current color scheme */
30
30
public fun interface OverrideColorScheme {
@@ -42,10 +42,10 @@ constructor(
42
42
43
43
val currentNightMode =
44
44
context.resources.configuration.uiMode and Configuration .UI_MODE_NIGHT_MASK
45
- when (currentNightMode) {
46
- Configuration .UI_MODE_NIGHT_NO -> return " light"
47
- Configuration .UI_MODE_NIGHT_YES -> return " dark"
48
- else -> return " light"
45
+ return when (currentNightMode) {
46
+ Configuration .UI_MODE_NIGHT_NO -> " light"
47
+ Configuration .UI_MODE_NIGHT_YES -> " dark"
48
+ else -> " light"
49
49
}
50
50
}
51
51
@@ -54,16 +54,16 @@ constructor(
54
54
// scheme. This covers the scenario when AppCompatDelegate.setDefaultNightMode()
55
55
// is called directly (which can occur in Brownfield apps for example).
56
56
val activity = getCurrentActivity()
57
- colorScheme = colorSchemeForCurrentConfiguration(activity ? : getReactApplicationContext())
58
- return colorScheme
57
+ return colorSchemeForCurrentConfiguration(activity ? : getReactApplicationContext())
59
58
}
60
59
61
60
public override fun setColorScheme (style : String ) {
62
- when {
63
- style == " dark" -> AppCompatDelegate .setDefaultNightMode(AppCompatDelegate .MODE_NIGHT_YES )
64
- style == " light" -> AppCompatDelegate .setDefaultNightMode(AppCompatDelegate .MODE_NIGHT_NO )
65
- style == " unspecified" ->
61
+ when (style) {
62
+ " dark" -> AppCompatDelegate .setDefaultNightMode(AppCompatDelegate .MODE_NIGHT_YES )
63
+ " light" -> AppCompatDelegate .setDefaultNightMode(AppCompatDelegate .MODE_NIGHT_NO )
64
+ " unspecified" ->
66
65
AppCompatDelegate .setDefaultNightMode(AppCompatDelegate .MODE_NIGHT_FOLLOW_SYSTEM )
66
+
67
67
}
68
68
}
69
69
@@ -79,9 +79,9 @@ constructor(
79
79
*/
80
80
public fun onConfigurationChanged (currentContext : Context ) {
81
81
val newColorScheme = colorSchemeForCurrentConfiguration(currentContext)
82
- if (colorScheme != newColorScheme) {
83
- colorScheme = newColorScheme
84
- emitAppearanceChanged(colorScheme )
82
+ if (lastEmittedColorScheme != newColorScheme) {
83
+ lastEmittedColorScheme = newColorScheme
84
+ emitAppearanceChanged(newColorScheme )
85
85
}
86
86
}
87
87
0 commit comments