From e6fc9b6f2950a1a55237f242791d0f9131e78284 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Thu, 11 Nov 2021 07:39:37 -0800 Subject: [PATCH] Introduce EmptyReactNativeConfig inside Java Summary: I'm adding a `EmptyReactNativeConfig` for Java as we had a similar class in C++. Ideally inside the Playbook we can allow users to use this class rather than having to create an anonymous inner class. Changelog: [Internal] [Added] - Introduce EmptyReactNativeConfig inside Java Reviewed By: ShikaSD Differential Revision: D32277916 fbshipit-source-id: f6bbeb0477681d536dfd89930b732609add7c43a --- .../react/fabric/EmptyReactNativeConfig.java | 35 +++++++++++++++++++ .../react/fabric/ReactNativeConfig.java | 11 +++++- .../react/uiapp/RNTesterApplication.java | 24 ++----------- 3 files changed, 47 insertions(+), 23 deletions(-) create mode 100644 ReactAndroid/src/main/java/com/facebook/react/fabric/EmptyReactNativeConfig.java diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/EmptyReactNativeConfig.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/EmptyReactNativeConfig.java new file mode 100644 index 00000000000..9c3aa63acd5 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/EmptyReactNativeConfig.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.react.fabric; + +/** + * An empty {@link ReactNativeConfig} that is returning empty responses and false for all the + * requested keys. + */ +public class EmptyReactNativeConfig implements ReactNativeConfig { + + @Override + public boolean getBool(final String s) { + return false; + } + + @Override + public int getInt64(final String s) { + return 0; + } + + @Override + public String getString(final String s) { + return ""; + } + + @Override + public double getDouble(final String s) { + return 0; + } +} diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/ReactNativeConfig.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/ReactNativeConfig.java index a211cec1f3f..04b166542a0 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/ReactNativeConfig.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/ReactNativeConfig.java @@ -10,7 +10,16 @@ package com.facebook.react.fabric; import androidx.annotation.NonNull; import com.facebook.proguard.annotations.DoNotStrip; -// This is a wrapper for the ReactNativeConfig object in C++ +/** + * ReactNative Configuration that allows to customize the behavior of key/value pairs used by the + * framework to enable/disable capabilities. + * + *

The hosting app should provide an implementation of this interface to allow specific + * customization of single keys. An empty implementation is available as {@link + * EmptyReactNativeConfig}. + * + *

This is a wrapper for the ReactNativeConfig object in C++ + */ @DoNotStrip public interface ReactNativeConfig { /** diff --git a/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java b/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java index 243c36a6eeb..643c4627618 100644 --- a/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java +++ b/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java @@ -28,8 +28,8 @@ import com.facebook.react.bridge.UIManager; import com.facebook.react.config.ReactFeatureFlags; import com.facebook.react.fabric.ComponentFactory; import com.facebook.react.fabric.CoreComponentsRegistry; +import com.facebook.react.fabric.EmptyReactNativeConfig; import com.facebook.react.fabric.FabricJSIModuleProvider; -import com.facebook.react.fabric.ReactNativeConfig; import com.facebook.react.module.model.ReactModuleInfo; import com.facebook.react.module.model.ReactModuleInfoProvider; import com.facebook.react.shell.MainReactPackage; @@ -152,27 +152,7 @@ public class RNTesterApplication extends Application implements ReactApplication reactApplicationContext, componentFactory, // TODO: T71362667 add ReactNativeConfig's support in RNTester - new ReactNativeConfig() { - @Override - public boolean getBool(final String s) { - return false; - } - - @Override - public int getInt64(final String s) { - return 0; - } - - @Override - public String getString(final String s) { - return ""; - } - - @Override - public double getDouble(final String s) { - return 0; - } - }, + new EmptyReactNativeConfig(), viewManagerRegistry); } });