Migrate FabricUIManagerProviderImpl to kotlin (#48869)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48869

Migrate FabricUIManagerProviderImpl to kotlin

changelog: [internal] internal

Reviewed By: tdn120, cortinico

Differential Revision: D68480341

fbshipit-source-id: bf0f548230f9c8bcba07fe32a1fde5d9a1d72550
This commit is contained in:
David Vacca
2025-01-22 13:20:37 -08:00
committed by Facebook GitHub Bot
parent 98b0991128
commit 159fc9922c
3 changed files with 74 additions and 68 deletions
@@ -2632,7 +2632,7 @@ public class com/facebook/react/fabric/FabricUIManager : com/facebook/react/brid
public fun updateRootLayoutSpecs (IIIII)V
}
public class com/facebook/react/fabric/FabricUIManagerProviderImpl : com/facebook/react/bridge/UIManagerProvider {
public final class com/facebook/react/fabric/FabricUIManagerProviderImpl : com/facebook/react/bridge/UIManagerProvider {
public fun <init> (Lcom/facebook/react/fabric/ComponentFactory;Lcom/facebook/react/uimanager/ViewManagerRegistry;)V
public fun createUIManager (Lcom/facebook/react/bridge/ReactApplicationContext;)Lcom/facebook/react/bridge/UIManager;
}
@@ -1,67 +0,0 @@
/*
* 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.fabric;
import com.facebook.infer.annotation.Nullsafe;
import com.facebook.react.bridge.CatalystInstance;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.RuntimeExecutor;
import com.facebook.react.bridge.RuntimeScheduler;
import com.facebook.react.bridge.UIManager;
import com.facebook.react.bridge.UIManagerProvider;
import com.facebook.react.fabric.events.EventBeatManager;
import com.facebook.react.uimanager.ViewManagerRegistry;
import com.facebook.systrace.Systrace;
@Nullsafe(Nullsafe.Mode.LOCAL)
public class FabricUIManagerProviderImpl implements UIManagerProvider {
private final ComponentFactory mComponentFactory;
private final ViewManagerRegistry mViewManagerRegistry;
public FabricUIManagerProviderImpl(
ComponentFactory componentFactory, ViewManagerRegistry viewManagerRegistry) {
mComponentFactory = componentFactory;
mViewManagerRegistry = viewManagerRegistry;
}
public UIManager createUIManager(ReactApplicationContext reactApplicationContext) {
Systrace.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricUIManagerProviderImpl.create");
EventBeatManager eventBeatManager = new EventBeatManager();
Systrace.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricUIManagerProviderImpl.createUIManager");
FabricUIManager fabricUIManager =
new FabricUIManager(reactApplicationContext, mViewManagerRegistry, eventBeatManager);
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
Systrace.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricUIManagerProviderImpl.registerBinding");
final FabricUIManagerBinding binding = new FabricUIManagerBinding();
CatalystInstance catalystInstance = reactApplicationContext.getCatalystInstance();
RuntimeExecutor runtimeExecutor = catalystInstance.getRuntimeExecutor();
RuntimeScheduler runtimeScheduler = catalystInstance.getRuntimeScheduler();
if (runtimeExecutor != null && runtimeScheduler != null) {
binding.register(
runtimeExecutor, runtimeScheduler, fabricUIManager, eventBeatManager, mComponentFactory);
} else {
throw new IllegalStateException(
"Unable to register FabricUIManager with CatalystInstance, runtimeExecutor and"
+ " runtimeScheduler must not be null");
}
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
return fabricUIManager;
}
}
@@ -0,0 +1,73 @@
/*
* 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.fabric
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.UIManager
import com.facebook.react.bridge.UIManagerProvider
import com.facebook.react.fabric.events.EventBeatManager
import com.facebook.react.uimanager.ViewManagerRegistry
import com.facebook.systrace.Systrace
/**
* Implementation of the UIManagerProvider for Fabric renderer on bridge mode
*
* @param [componentFactory] The factory for creating components.
* @param [viewManagerRegistry] The registry of view managers.
*/
public class FabricUIManagerProviderImpl(
private val componentFactory: ComponentFactory,
private val viewManagerRegistry: ViewManagerRegistry
) : UIManagerProvider {
/**
* Creates a UIManager instance for the provided ReactApplicationContext.
*
* This method initializes tracing sections for performance monitoring, creates a FabricUIManager
* using the supplied ReactApplicationContext and ViewManagerRegistry, manages event beats, and
* registers FabricUIManagerBinding with the runtime environment of the provided
* ReactApplicationContext.
*
* @param context The React application context.
* @return A newly created FabricUIManager instance.
* @throws IllegalStateException If runtimeExecutor or runtimeScheduler is null.
*/
override fun createUIManager(context: ReactApplicationContext): UIManager {
Systrace.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricUIManagerProviderImpl.create")
val eventBeatManager = EventBeatManager()
Systrace.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricUIManagerProviderImpl.createUIManager")
val fabricUIManager = FabricUIManager(context, viewManagerRegistry, eventBeatManager)
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE)
Systrace.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricUIManagerProviderImpl.registerBinding")
val binding = FabricUIManagerBinding()
val catalystInstance = context.catalystInstance
val runtimeExecutor = catalystInstance?.runtimeExecutor
val runtimeScheduler = catalystInstance?.runtimeScheduler
if (runtimeExecutor != null && runtimeScheduler != null) {
binding.register(
runtimeExecutor, runtimeScheduler, fabricUIManager, eventBeatManager, componentFactory)
} else {
throw IllegalStateException(
"Unable to register FabricUIManager with CatalystInstance, runtimeExecutor and" +
" runtimeScheduler must not be null")
}
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE)
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE)
return fabricUIManager
}
}