Skip to content

Commit

Permalink
Adding new APIs for creating UIManager in FabricUIManagerProviderImpl (
Browse files Browse the repository at this point in the history
…#41301)

Summary:
Pull Request resolved: #41301

Adding the new API for creating UIManager(`FabricUIManager`) for Fabric initialization:
```
createUIManager(ReactApplicationContext reactApplicationContext)
```

and `FabricUIManagerProviderImpl()` and making it also implement the `UIManagerProvider` interface

NOTE:

Letting the older implementations in place and will be removed once the references have been removed from the apps and similarly for old constructor `FabricUIManagerProviderImpl()` and similarly for old implement relationship with `JSIModuleProvider`

Changelog:
[Internal] internal

Reviewed By: javache, philIip, mdvacca

Differential Revision: D50783295

fbshipit-source-id: 767f27c7f0d42840a5dad693e98cf5b6a243f933
  • Loading branch information
arushikesarwani94 authored and facebook-github-bot committed Nov 7, 2023
1 parent bc68794 commit 3e15821
Showing 1 changed file with 48 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,64 +7,85 @@

package com.facebook.react.fabric;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.facebook.infer.annotation.Nullsafe;
import com.facebook.react.bridge.CatalystInstance;
import com.facebook.react.bridge.JSIModuleProvider;
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;

public class FabricUIManagerProviderImpl implements JSIModuleProvider<UIManager> {
@Nullsafe(Nullsafe.Mode.LOCAL)
public class FabricUIManagerProviderImpl
implements JSIModuleProvider<UIManager>, UIManagerProvider {

@NonNull private final ReactApplicationContext mReactApplicationContext;
@NonNull private final ComponentFactory mComponentFactory;
@NonNull private final ReactNativeConfig mConfig;
@NonNull private final ViewManagerRegistry mViewManagerRegistry;
private final @Nullable ReactApplicationContext mReactApplicationContext;
private final ComponentFactory mComponentFactory;
private final ReactNativeConfig mConfig;
private final ViewManagerRegistry mViewManagerRegistry;

public FabricUIManagerProviderImpl(
@NonNull ReactApplicationContext reactApplicationContext,
@NonNull ComponentFactory componentFactory,
@NonNull ReactNativeConfig config,
@NonNull ViewManagerRegistry viewManagerRegistry) {
ReactApplicationContext reactApplicationContext,
ComponentFactory componentFactory,
ReactNativeConfig config,
ViewManagerRegistry viewManagerRegistry) {
mReactApplicationContext = reactApplicationContext;
mComponentFactory = componentFactory;
mConfig = config;
mViewManagerRegistry = viewManagerRegistry;
}

public FabricUIManagerProviderImpl(
ComponentFactory componentFactory,
ReactNativeConfig config,
ViewManagerRegistry viewManagerRegistry) {
mReactApplicationContext = null;
mComponentFactory = componentFactory;
mConfig = config;
mViewManagerRegistry = viewManagerRegistry;
}

@Override
public UIManager get() {
Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricUIManagerProviderImpl.get");
final EventBeatManager eventBeatManager = new EventBeatManager();
final FabricUIManager uiManager = createUIManager(eventBeatManager);
if (mReactApplicationContext != null) {
return createUIManager(mReactApplicationContext);
}
throw new IllegalStateException(
"This method shoulndn't be called without ReactContext initialized");
}

@Override
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 Binding binding = new BindingImpl();

CatalystInstance catalystInstance = reactApplicationContext.getCatalystInstance();

binding.register(
mReactApplicationContext.getCatalystInstance().getRuntimeExecutor(),
mReactApplicationContext.getCatalystInstance().getRuntimeScheduler(),
uiManager,
catalystInstance.getRuntimeExecutor(),
catalystInstance.getRuntimeScheduler(),
fabricUIManager,
eventBeatManager,
mComponentFactory,
mConfig);

Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);

return uiManager;
}

private FabricUIManager createUIManager(@NonNull EventBeatManager eventBeatManager) {
Systrace.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricUIManagerProviderImpl.createUIManager");

FabricUIManager fabricUIManager;
fabricUIManager =
new FabricUIManager(mReactApplicationContext, mViewManagerRegistry, eventBeatManager);
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
return fabricUIManager;
}
}

0 comments on commit 3e15821

Please sign in to comment.