Skip to content

Commit 07a2f1a

Browse files
ryanlntnkosmydel
authored andcommitted
Add isWideColorGamutEnabled to ReactActivityDelegate (facebook#43036)
Summary: This adds support for enabling wide color gamut mode for ReactActivity per the wide gamut color [RFC](react-native-community/discussions-and-proposals#738). ## Changelog: [ANDROID] [ADDED] - Add isWideColorGamutEnabled to ReactActivityDelegate Pull Request resolved: facebook#43036 Test Plan: Update RNTesterActivity.kt to enable wide color gamut: ```diff class RNTesterActivity : ReactActivity() { class RNTesterActivityDelegate(val activity: ReactActivity, mainComponentName: String) : // ... override fun getLaunchOptions() = if (this::initialProps.isInitialized) initialProps else Bundle() + override fun isWideColorGamutEnabled() = true } ``` Reviewed By: cortinico Differential Revision: D55749124 Pulled By: cipolleschi fbshipit-source-id: 44dd5631e1a2e429c86c01ed8747bbebbc8bdb3b
1 parent 365d7ed commit 07a2f1a

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public class com/facebook/react/ReactActivityDelegate {
128128
public fun getReactInstanceManager ()Lcom/facebook/react/ReactInstanceManager;
129129
protected fun getReactNativeHost ()Lcom/facebook/react/ReactNativeHost;
130130
protected fun isFabricEnabled ()Z
131+
protected fun isWideColorGamutEnabled ()Z
131132
protected fun loadApp (Ljava/lang/String;)V
132133
public fun onActivityResult (IILandroid/content/Intent;)V
133134
public fun onBackPressed ()Z

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import android.app.Activity;
1111
import android.content.Context;
1212
import android.content.Intent;
13+
import android.content.pm.ActivityInfo;
1314
import android.content.res.Configuration;
15+
import android.os.Build;
1416
import android.os.Bundle;
1517
import android.view.KeyEvent;
1618
import androidx.annotation.Nullable;
@@ -102,6 +104,9 @@ public String getMainComponentName() {
102104
public void onCreate(Bundle savedInstanceState) {
103105
String mainComponentName = getMainComponentName();
104106
final Bundle launchOptions = composeLaunchOptions();
107+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && isWideColorGamutEnabled()) {
108+
mActivity.getWindow().setColorMode(ActivityInfo.COLOR_MODE_WIDE_COLOR_GAMUT);
109+
}
105110
if (ReactFeatureFlags.enableBridgelessArchitecture) {
106111
mReactDelegate =
107112
new ReactDelegate(getPlainActivity(), getReactHost(), mainComponentName, launchOptions);
@@ -217,4 +222,13 @@ protected Activity getPlainActivity() {
217222
protected boolean isFabricEnabled() {
218223
return ReactFeatureFlags.enableFabricRenderer;
219224
}
225+
226+
/**
227+
* Override this method if you wish to selectively toggle wide color gamut for a specific surface.
228+
*
229+
* @return true if wide gamut is enabled for this Activity, false otherwise.
230+
*/
231+
protected boolean isWideColorGamutEnabled() {
232+
return false;
233+
}
220234
}

0 commit comments

Comments
 (0)