mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Support MobileConfig in Fabric Core C++ in FB4A and Catalyst
Summary: MobileConfig should be wrapped and presented as a ReactNativeConfig object so that core Fabric C++ code can use it. This is just a noop plumbing diff. Real support will be added in follow-on diff. Reviewed By: fkgozali Differential Revision: D13985466 fbshipit-source-id: a2ac2175688e855eda3b89aa69faf07749c6bd31
This commit is contained in:
committed by
Facebook Github Bot
parent
864a30185d
commit
a15e723476
@@ -37,14 +37,17 @@ public class FabricJSIModuleProvider implements JSIModuleProvider<UIManager> {
|
||||
private final JavaScriptContextHolder mJSContext;
|
||||
private final ReactApplicationContext mReactApplicationContext;
|
||||
private final ComponentFactoryDelegate mComponentFactoryDelegate;
|
||||
private final ReactNativeConfig mConfig;
|
||||
|
||||
public FabricJSIModuleProvider(
|
||||
ReactApplicationContext reactApplicationContext,
|
||||
JavaScriptContextHolder jsContext,
|
||||
ComponentFactoryDelegate componentFactoryDelegate) {
|
||||
ComponentFactoryDelegate componentFactoryDelegate,
|
||||
ReactNativeConfig config) {
|
||||
mReactApplicationContext = reactApplicationContext;
|
||||
mJSContext = jsContext;
|
||||
mComponentFactoryDelegate = componentFactoryDelegate;
|
||||
mConfig = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,7 +66,7 @@ public class FabricJSIModuleProvider implements JSIModuleProvider<UIManager> {
|
||||
.getReactQueueConfiguration()
|
||||
.getJSQueueThread();
|
||||
binding.register(mJSContext, uiManager, eventBeatManager, jsMessageQueueThread,
|
||||
mComponentFactoryDelegate);
|
||||
mComponentFactoryDelegate, mConfig);
|
||||
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
return uiManager;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
// This is a wrapper for the ReactNativeConfig object in C++
|
||||
public interface ReactNativeConfig {
|
||||
boolean getBool(String param);
|
||||
int getInt64(String param);
|
||||
String getString(String param);
|
||||
double getDouble(String param);
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import com.facebook.proguard.annotations.DoNotStrip;
|
||||
import com.facebook.react.bridge.JavaScriptContextHolder;
|
||||
import com.facebook.react.bridge.NativeMap;
|
||||
import com.facebook.react.bridge.queue.MessageQueueThread;
|
||||
import com.facebook.react.fabric.ReactNativeConfig;
|
||||
import com.facebook.react.fabric.FabricUIManager;
|
||||
import com.facebook.react.uimanager.PixelUtil;
|
||||
|
||||
@@ -36,7 +37,8 @@ public class Binding {
|
||||
Object uiManager,
|
||||
EventBeatManager eventBeatManager,
|
||||
MessageQueueThread jsMessageQueueThread,
|
||||
ComponentFactoryDelegate componentsRegistry);
|
||||
ComponentFactoryDelegate componentsRegistry,
|
||||
Object reactNativeConfig);
|
||||
|
||||
public native void startSurface(int surfaceId, NativeMap initialProps);
|
||||
|
||||
@@ -54,10 +56,11 @@ public class Binding {
|
||||
FabricUIManager fabricUIManager,
|
||||
EventBeatManager eventBeatManager,
|
||||
MessageQueueThread jsMessageQueueThread,
|
||||
ComponentFactoryDelegate componentFactoryDelegate) {
|
||||
ComponentFactoryDelegate componentFactoryDelegate,
|
||||
ReactNativeConfig reactNativeConfig) {
|
||||
fabricUIManager.setBinding(this);
|
||||
installFabricUIManager(
|
||||
jsContext.get(), fabricUIManager, eventBeatManager, jsMessageQueueThread, componentFactoryDelegate);
|
||||
jsContext.get(), fabricUIManager, eventBeatManager, jsMessageQueueThread, componentFactoryDelegate, reactNativeConfig);
|
||||
setPixelDensity(PixelUtil.getDisplayMetricDensity());
|
||||
}
|
||||
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
#include "AsyncEventBeat.h"
|
||||
#include "Binding.h"
|
||||
#include "EventEmitterWrapper.h"
|
||||
#include "ReactNativeConfigHolder.h"
|
||||
|
||||
#include <android/log.h>
|
||||
#include <fb/fbjni.h>
|
||||
#include <jsi/jsi.h>
|
||||
#include <jsi/JSIDynamic.h>
|
||||
#include <react/components/scrollview/ScrollViewProps.h>
|
||||
#include <react/config/ReactNativeConfig.h>
|
||||
#include <react/debug/SystraceSection.h>
|
||||
#include <react/events/EventEmitter.h>
|
||||
#include <react/events/EventBeat.h>
|
||||
@@ -79,7 +79,7 @@ void Binding::setConstraints(jint rootTag, jfloat minWidth, jfloat maxWidth, jfl
|
||||
}
|
||||
}
|
||||
|
||||
void Binding::installFabricUIManager(jlong jsContextNativePointer, jni::alias_ref<jobject> javaUIManager, EventBeatManager* eventBeatManager, jni::alias_ref<JavaMessageQueueThread::javaobject> jsMessageQueueThread, ComponentFactoryDelegate* componentsRegistry) {
|
||||
void Binding::installFabricUIManager(jlong jsContextNativePointer, jni::alias_ref<jobject> javaUIManager, EventBeatManager* eventBeatManager, jni::alias_ref<JavaMessageQueueThread::javaobject> jsMessageQueueThread, ComponentFactoryDelegate* componentsRegistry, jni::alias_ref<jobject> reactNativeConfig) {
|
||||
Runtime* runtime = (Runtime*) jsContextNativePointer;
|
||||
|
||||
javaUIManager_ = make_global(javaUIManager);
|
||||
@@ -104,7 +104,7 @@ void Binding::installFabricUIManager(jlong jsContextNativePointer, jni::alias_re
|
||||
};
|
||||
|
||||
// TODO: Provide non-empty impl for ReactNativeConfig.
|
||||
std::shared_ptr<const ReactNativeConfig> config = std::make_shared<const EmptyReactNativeConfig>();
|
||||
std::shared_ptr<const ReactNativeConfig> config = std::make_shared<const ReactNativeConfigHolder>(reactNativeConfig);
|
||||
contextContainer->registerInstance(config, "ReactNativeConfig");
|
||||
contextContainer->registerInstance<EventBeatFactory>(synchronousBeatFactory, "synchronous");
|
||||
contextContainer->registerInstance<EventBeatFactory>(asynchronousBeatFactory, "asynchronous");
|
||||
|
||||
@@ -38,7 +38,7 @@ private:
|
||||
|
||||
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jclass>);
|
||||
|
||||
void installFabricUIManager(jlong jsContextNativePointer, jni::alias_ref<jobject> javaUIManager, EventBeatManager* eventBeatManager, jni::alias_ref<JavaMessageQueueThread::javaobject> jsMessageQueueThread, ComponentFactoryDelegate* componentsRegistry);
|
||||
void installFabricUIManager(jlong jsContextNativePointer, jni::alias_ref<jobject> javaUIManager, EventBeatManager* eventBeatManager, jni::alias_ref<JavaMessageQueueThread::javaobject> jsMessageQueueThread, ComponentFactoryDelegate* componentsRegistry, jni::alias_ref<jobject> reactNativeConfig);
|
||||
|
||||
void startSurface(jint surfaceId, NativeMap *initialProps);
|
||||
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import "ReactNativeConfigHolder.h"
|
||||
|
||||
#include <fb/fbjni.h>
|
||||
|
||||
using namespace facebook::react;
|
||||
|
||||
bool ReactNativeConfigHolder::getBool(const std::string ¶m) const {
|
||||
static const auto method = facebook::jni::findClassStatic("com/facebook/react/fabric/ReactNativeConfig")
|
||||
->getMethod<jboolean(jstring)>("getBool");
|
||||
return method(reactNativeConfig_, facebook::jni::make_jstring(param).get());
|
||||
}
|
||||
|
||||
std::string ReactNativeConfigHolder::getString(const std::string ¶m) const {
|
||||
static const auto method = facebook::jni::findClassStatic("com/facebook/react/fabric/ReactNativeConfig")
|
||||
->getMethod<jstring(jstring)>("getString");
|
||||
return method(reactNativeConfig_, facebook::jni::make_jstring(param).get())->toString();
|
||||
}
|
||||
|
||||
int64_t ReactNativeConfigHolder::getInt64(const std::string ¶m) const {
|
||||
static const auto method = facebook::jni::findClassStatic("com/facebook/react/fabric/ReactNativeConfig")
|
||||
->getMethod<jint(jstring)>("getInt64");
|
||||
return method(reactNativeConfig_, facebook::jni::make_jstring(param).get());
|
||||
}
|
||||
|
||||
double ReactNativeConfigHolder::getDouble(const std::string ¶m) const {
|
||||
static const auto method = facebook::jni::findClassStatic("com/facebook/react/fabric/ReactNativeConfig")
|
||||
->getMethod<jdouble(jstring)>("getDouble");
|
||||
return method(reactNativeConfig_, facebook::jni::make_jstring(param).get());
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <fb/fbjni.h>
|
||||
#include <react/jni/JMessageQueueThread.h>
|
||||
#include <react/jni/ReadableNativeMap.h>
|
||||
#include <react/config/ReactNativeConfig.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
/**
|
||||
* Implementation of ReactNativeConfig that wraps a FabricMobileConfig Java object.
|
||||
*/
|
||||
class ReactNativeConfigHolder : public ReactNativeConfig {
|
||||
public:
|
||||
ReactNativeConfigHolder(jni::alias_ref<jobject> reactNativeConfig) : reactNativeConfig_(reactNativeConfig) {};
|
||||
|
||||
bool getBool(const std::string ¶m) const override;
|
||||
std::string getString(const std::string ¶m) const override;
|
||||
int64_t getInt64(const std::string ¶m) const override;
|
||||
double getDouble(const std::string ¶m) const override;
|
||||
|
||||
private:
|
||||
jni::alias_ref<jobject> reactNativeConfig_;
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
Reference in New Issue
Block a user