From ae89e98b995026179f38569c8d25faf040dca445 Mon Sep 17 00:00:00 2001 From: Brent Vatne Date: Tue, 16 Jun 2020 17:50:07 -0700 Subject: [PATCH] [ReactAndroid] Respect local night mode configuration for activity to play nicely with Expo client color scheme locking mechanism. https://github.com/expo/expo/pull/8793 This is a squashed commits with the following changes: commit 945096e54ff9f5d9f5639cea201f101efac472a9 Author: Kudo Chien Date: Tue Jul 27 16:49:09 2021 +0800 [android] Upgrade androidx.appcompat to 1.2.0 Backport from: https://github.com/expo/expo/commit/58fa52e3e3e29b7a852a814b2d5bb54f4a8e1065 --- .../react/modules/appearance/AppearanceModule.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/appearance/AppearanceModule.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/appearance/AppearanceModule.kt index 6aaf2b1cfbb07d..54015d4e87b13c 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/appearance/AppearanceModule.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/appearance/AppearanceModule.kt @@ -9,6 +9,7 @@ package com.facebook.react.modules.appearance import android.content.Context import android.content.res.Configuration +import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatDelegate import com.facebook.fbreact.specs.NativeAppearanceSpec import com.facebook.react.bridge.Arguments @@ -35,10 +36,21 @@ constructor( public fun getScheme(): String } + // NOTE(brentvatne): this was static previously, but it wasn't necessary and we need it to not be + // in order to use getCurrentActivity private fun colorSchemeForCurrentConfiguration(context: Context): String { if (overrideColorScheme != null) { return overrideColorScheme.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 (currentActivity is AppCompatActivity) { + val mode = (currentActivity as AppCompatActivity?)!!.delegate.localNightMode + when (mode) { + AppCompatDelegate.MODE_NIGHT_YES -> return "dark" + AppCompatDelegate.MODE_NIGHT_NO -> return "light" + } + } val currentNightMode = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK