Skip to content

Commit

Permalink
Make UIConstantsProviderManager a static method
Browse files Browse the repository at this point in the history
Differential Revision: D55241233
  • Loading branch information
javache authored and facebook-github-bot committed Mar 22, 2024
1 parent b58d81b commit 0721900
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 267 deletions.
11 changes: 6 additions & 5 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -4851,19 +4851,20 @@ public abstract interface class com/facebook/react/uimanager/UIBlock {
public abstract fun execute (Lcom/facebook/react/uimanager/NativeViewHierarchyManager;)V
}

public class com/facebook/react/uimanager/UIConstantsProviderManager {
public fun <init> (Lcom/facebook/react/bridge/RuntimeExecutor;Lcom/facebook/react/uimanager/UIConstantsProviderManager$DefaultEventTypesProvider;Lcom/facebook/react/uimanager/UIConstantsProviderManager$ConstantsForViewManagerProvider;Lcom/facebook/react/uimanager/UIConstantsProviderManager$ConstantsProvider;)V
public final class com/facebook/react/uimanager/UIConstantsProviderBinding {
public static final field INSTANCE Lcom/facebook/react/uimanager/UIConstantsProviderBinding;
public static final fun install (Lcom/facebook/react/bridge/RuntimeExecutor;Lcom/facebook/react/uimanager/UIConstantsProviderBinding$DefaultEventTypesProvider;Lcom/facebook/react/uimanager/UIConstantsProviderBinding$ConstantsForViewManagerProvider;Lcom/facebook/react/uimanager/UIConstantsProviderBinding$ConstantsProvider;)V
}

public abstract interface class com/facebook/react/uimanager/UIConstantsProviderManager$ConstantsForViewManagerProvider {
public abstract interface class com/facebook/react/uimanager/UIConstantsProviderBinding$ConstantsForViewManagerProvider {
public abstract fun getConstantsForViewManager (Ljava/lang/String;)Lcom/facebook/react/bridge/NativeMap;
}

public abstract interface class com/facebook/react/uimanager/UIConstantsProviderManager$ConstantsProvider {
public abstract interface class com/facebook/react/uimanager/UIConstantsProviderBinding$ConstantsProvider {
public abstract fun getConstants ()Lcom/facebook/react/bridge/NativeMap;
}

public abstract interface class com/facebook/react/uimanager/UIConstantsProviderManager$DefaultEventTypesProvider {
public abstract interface class com/facebook/react/uimanager/UIConstantsProviderBinding$DefaultEventTypesProvider {
public abstract fun getDefaultEventTypes ()Lcom/facebook/react/bridge/NativeMap;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
import com.facebook.react.uimanager.ComponentNameResolverBinding;
import com.facebook.react.uimanager.DisplayMetricsHolder;
import com.facebook.react.uimanager.IllegalViewOperationException;
import com.facebook.react.uimanager.UIConstantsProviderManager;
import com.facebook.react.uimanager.UIConstantsProviderBinding;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.UIManagerModuleConstantsHelper;
import com.facebook.react.uimanager.ViewManager;
Expand Down Expand Up @@ -97,8 +97,6 @@ final class ReactInstance {

private JavaScriptContextHolder mJavaScriptContextHolder;

@DoNotStrip @Nullable private UIConstantsProviderManager mUIConstantsProviderManager;

static {
loadLibraryIfNeeded();
}
Expand Down Expand Up @@ -231,46 +229,43 @@ final class ReactInstance {
if (ReactFeatureFlags.useNativeViewConfigsInBridgelessMode) {
Map<String, Object> customDirectEvents = new HashMap<>();

mUIConstantsProviderManager =
new UIConstantsProviderManager(
// Use unbuffered RuntimeExecutor to install binding
unbufferedRuntimeExecutor,
// Here we are construncting the return value for UIManager.getConstants call.
// The old architectre relied on the constatnts struct to contain:
// 1. Eagerly loaded view configs for all native components.
// 2. genericBubblingEventTypes.
// 3. genericDirectEventTypes.
// We want to match this beahavior.
() -> {
return (NativeMap)
Arguments.makeNativeMap(
UIManagerModuleConstantsHelper.getDefaultExportableEventTypes());
},
(String viewManagerName) -> {
ViewManager viewManager = mViewManagerResolver.getViewManager(viewManagerName);
if (viewManager == null) {
return null;
}
return (NativeMap)
UIManagerModule.getConstantsForViewManager(viewManager, customDirectEvents);
},
() -> {
List<ViewManager> viewManagers =
new ArrayList<ViewManager>(
mViewManagerResolver.getEagerViewManagerMap().values());

Map<String, Object> constants =
UIManagerModule.createConstants(viewManagers, null, customDirectEvents);

Collection<String> lazyViewManagers =
mViewManagerResolver.getLazyViewManagerNames();
if (lazyViewManagers.size() > 0) {
constants.put("ViewManagerNames", new ArrayList<>(lazyViewManagers));
constants.put("LazyViewManagersEnabled", true);
}

return Arguments.makeNativeMap(constants);
});
UIConstantsProviderBinding.install(
// Use unbuffered RuntimeExecutor to install binding
unbufferedRuntimeExecutor,
// Here we are construncting the return value for UIManager.getConstants call.
// The old architectre relied on the constatnts struct to contain:
// 1. Eagerly loaded view configs for all native components.
// 2. genericBubblingEventTypes.
// 3. genericDirectEventTypes.
// We want to match this beahavior.
() -> {
return (NativeMap)
Arguments.makeNativeMap(
UIManagerModuleConstantsHelper.getDefaultExportableEventTypes());
},
(String viewManagerName) -> {
ViewManager viewManager = mViewManagerResolver.getViewManager(viewManagerName);
if (viewManager == null) {
return null;
}
return (NativeMap)
UIManagerModule.getConstantsForViewManager(viewManager, customDirectEvents);
},
() -> {
List<ViewManager> viewManagers =
new ArrayList<>(mViewManagerResolver.getEagerViewManagerMap().values());

Map<String, Object> constants =
UIManagerModule.createConstants(viewManagers, null, customDirectEvents);

Collection<String> lazyViewManagers = mViewManagerResolver.getLazyViewManagerNames();
if (lazyViewManagers.size() > 0) {
constants.put("ViewManagerNames", new ArrayList<>(lazyViewManagers));
constants.put("LazyViewManagersEnabled", true);
}

return Arguments.makeNativeMap(constants);
});
}

EventBeatManager eventBeatManager = new EventBeatManager();
Expand Down Expand Up @@ -430,7 +425,6 @@ public Collection<NativeModule> getNativeModules() {
mFabricUIManager.invalidate();
mJavaTimerManager.onInstanceDestroy();
mHybridData.resetNative();
mUIConstantsProviderManager = null;
mJavaScriptContextHolder.clear();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) Meta Platforms, Inc. and 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.uimanager

import com.facebook.proguard.annotations.DoNotStripAny
import com.facebook.react.bridge.NativeMap
import com.facebook.react.bridge.RuntimeExecutor
import com.facebook.soloader.SoLoader
import kotlin.jvm.JvmStatic

@DoNotStripAny
object UIConstantsProviderBinding {
init {
SoLoader.loadLibrary("uimanagerjni")
}

@JvmStatic
external fun install(
runtimeExecutor: RuntimeExecutor,
defaultEventTypesProvider: DefaultEventTypesProvider,
viewManagerConstantsProvider: ConstantsForViewManagerProvider,
constantsProvider: ConstantsProvider
)

@DoNotStripAny
interface DefaultEventTypesProvider {
/* Returns UIManager's constants. */
fun getDefaultEventTypes(): NativeMap
}

@DoNotStripAny
interface ConstantsForViewManagerProvider {
/* Returns UIManager's constants. */
fun getConstantsForViewManager(viewManagerName: String): NativeMap?
}

@DoNotStripAny
interface ConstantsProvider {
/* Returns UIManager's constants. */
fun getConstants(): NativeMap
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
#include <fbjni/fbjni.h>

#include "ComponentNameResolverBinding.h"
#include "UIConstantsProviderManager.h"
#include "UIConstantsProviderBinding.h"

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
return facebook::jni::initialize(vm, [] {
facebook::react::ComponentNameResolverBinding::registerNatives();
facebook::react::UIConstantsProviderManager::registerNatives();
facebook::react::UIConstantsProviderBinding::registerNatives();
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include "UIConstantsProviderBinding.h"

#include <react/runtime/nativeviewconfig/LegacyUIManagerConstantsProviderBinding.h>

namespace facebook::react {

using namespace facebook::jni;

void UIConstantsProviderBinding::registerNatives() {
javaClassStatic()->registerNatives({
makeNativeMethod("install", UIConstantsProviderBinding::install),
});
}

void UIConstantsProviderBinding::install(
jni::alias_ref<jclass> /* unused */,
jni::alias_ref<JRuntimeExecutor::javaobject> runtimeExecutor,
jni::alias_ref<DefaultEventTypesProvider::javaobject>
defaultExportableEventTypesProvider,
jni::alias_ref<ConstantsForViewManagerProvider::javaobject>
constantsForViewManagerProvider,
jni::alias_ref<ConstantsProvider::javaobject> constantsProvider) {
auto executor = runtimeExecutor->cthis()->get();
executor([defaultExportableEventTypesProvider =
make_global(defaultExportableEventTypesProvider),
constantsForViewManagerProvider =
make_global(constantsForViewManagerProvider),
constantsProvider =
make_global(constantsProvider)](jsi::Runtime& runtime) mutable {
LegacyUIManagerConstantsProviderBinding::install(
runtime,
"getDefaultEventTypes",
[provider = std::move(defaultExportableEventTypesProvider)](
jsi::Runtime& runtime) {
return jsi::valueFromDynamic(
runtime, provider->getDefaultEventTypes());
});

LegacyUIManagerConstantsProviderBinding::install(
runtime,
"getConstantsForViewManager",
[provider = std::move(constantsForViewManagerProvider)](
jsi::Runtime& runtime, const std::string& viewManagerName) {
return jsi::valueFromDynamic(
runtime, provider->getConstantsForViewManager(viewManagerName));
});

LegacyUIManagerConstantsProviderBinding::install(
runtime,
"getConstants",
[provider = std::move(constantsProvider)](jsi::Runtime& runtime) {
return jsi::valueFromDynamic(runtime, provider->getConstants());
});
});
}

} // namespace facebook::react
Loading

0 comments on commit 0721900

Please sign in to comment.