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 gabrieldonadel committed Jul 17, 2024
1 parent 1249137 commit ae89e98
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ae89e98

Please sign in to comment.