Skip to content

Commit

Permalink
Add isWideColorGamutEnabled to ReactActivityDelegate (facebook#43036)
Browse files Browse the repository at this point in the history
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
    }
```

Differential Revision: D55749124

Reviewed By: cortinico

Pulled By: cortinico
  • Loading branch information
ryanlntn authored and facebook-github-bot committed Apr 23, 2024
1 parent bab13b2 commit 7e276ee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public class com/facebook/react/ReactActivityDelegate {
public fun getReactInstanceManager ()Lcom/facebook/react/ReactInstanceManager;
protected fun getReactNativeHost ()Lcom/facebook/react/ReactNativeHost;
protected fun isFabricEnabled ()Z
protected fun isWideColorGamutEnabled ()Z
protected fun loadApp (Ljava/lang/String;)V
public fun onActivityResult (IILandroid/content/Intent;)V
public fun onBackPressed ()Z
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.view.KeyEvent;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -102,6 +104,9 @@ public String getMainComponentName() {
public void onCreate(Bundle savedInstanceState) {
String mainComponentName = getMainComponentName();
final Bundle launchOptions = composeLaunchOptions();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && isWideColorGamutEnabled()) {
mActivity.getWindow().setColorMode(ActivityInfo.COLOR_MODE_WIDE_COLOR_GAMUT);
}
if (ReactFeatureFlags.enableBridgelessArchitecture) {
mReactDelegate =
new ReactDelegate(getPlainActivity(), getReactHost(), mainComponentName, launchOptions);
Expand Down Expand Up @@ -217,4 +222,13 @@ protected Activity getPlainActivity() {
protected boolean isFabricEnabled() {
return ReactFeatureFlags.enableFabricRenderer;
}

/**
* Override this method if you wish to selectively toggle wide color gamut for a specific surface.
*
* @return true if wide gamut is enabled for this Activity, false otherwise.
*/
protected boolean isWideColorGamutEnabled() {
return false;
}
}

0 comments on commit 7e276ee

Please sign in to comment.