Skip to content

Commit 4a07aac

Browse files
Kudoalanjhughes
authored andcommitted
Fix appearance changed into wrong activity (#34)
the original `AppCompatDelegate.setDefaultNightMode()` is a global setup. when changing the night mode, it will actually call HomeActivity's `onConfigurationChanged`. this pr tries to set night mode to current activity by using the `setLocalNightMode()`
1 parent f5c038d commit 4a07aac

File tree

1 file changed

+11
-3
lines changed
  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/appearance

1 file changed

+11
-3
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/appearance/AppearanceModule.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,20 @@ private String colorSchemeForCurrentConfiguration(Context context) {
8484

8585
@Override
8686
public void setColorScheme(String style) {
87+
int nightMode = AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
8788
if (style.equals("dark")) {
88-
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
89+
nightMode = AppCompatDelegate.MODE_NIGHT_YES;
8990
} else if (style.equals("light")) {
90-
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
91+
nightMode = AppCompatDelegate.MODE_NIGHT_NO;
9192
} else if (style.equals("unspecified")) {
92-
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
93+
nightMode = AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
94+
}
95+
96+
Activity activity = getCurrentActivity();
97+
if (activity instanceof AppCompatActivity) {
98+
((AppCompatActivity) activity).getDelegate().setLocalNightMode(nightMode);
99+
} else {
100+
AppCompatDelegate.setDefaultNightMode(nightMode);
93101
}
94102
}
95103

0 commit comments

Comments
 (0)