Skip to content

Commit

Permalink
[ReactAndroid] Respect local night mode configuration for activity to…
Browse files Browse the repository at this point in the history
… play nicely with Expo client color scheme locking mechanism. expo/expo#8793

This is a squashed commits with the following changes:

commit 945096e
Author: Kudo Chien <kudo@expo.io>
Date:   Tue Jul 27 16:49:09 2021 +0800

    [android] Upgrade androidx.appcompat to 1.2.0

    Backport from: expo/expo@58fa52e
  • Loading branch information
brentvatne authored and Kudo committed Feb 17, 2022
1 parent 39ef7d4 commit e94398d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ReactAndroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ dependencies {
api("com.facebook.infer.annotation:infer-annotation:0.18.0")
api("com.facebook.yoga:proguard-annotations:1.19.0")
api("javax.inject:javax.inject:1")
api("androidx.appcompat:appcompat:1.0.2")
api("androidx.appcompat:appcompat:1.2.0")
api("androidx.autofill:autofill:1.1.0")
api("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0")
api("com.facebook.fresco:fresco:${FRESCO_VERSION}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;

/** Module that exposes the user's preferred color scheme. */
@ReactModule(name = AppearanceModule.NAME)
public class AppearanceModule extends NativeAppearanceSpec {
Expand Down Expand Up @@ -52,10 +55,23 @@ public AppearanceModule(
mColorScheme = colorSchemeForCurrentConfiguration(reactContext);
}

// NOTE(brentvatne): this was static previously, but it wasn't necessary and we need it to not be
// in order to use getCurrentActivity
private String colorSchemeForCurrentConfiguration(Context context) {
if (mOverrideColorScheme != null) {
return mOverrideColorScheme.getScheme();
}
// NOTE(brentvatne): Same code (roughly) that we use in ExpoAppearanceModule to get the config
// as set by ExperienceActivityUtils to force the dark/light mode config on the activity
if (getCurrentActivity() instanceof AppCompatActivity) {
int mode = ((AppCompatActivity) getCurrentActivity()).getDelegate().getLocalNightMode();
switch (mode) {
case AppCompatDelegate.MODE_NIGHT_YES:
return "dark";
case AppCompatDelegate.MODE_NIGHT_NO:
return "light";
}
}
int currentNightMode =
context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
switch (currentNightMode) {
Expand Down

0 comments on commit e94398d

Please sign in to comment.