Skip to content

Commit

Permalink
Make FabricUIManager's Binding an interface (facebook#36613)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#36613

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D44340265

fbshipit-source-id: 1ab4e434fa20840a40590ac2157fd7f817807990
  • Loading branch information
javache authored and OlimpiaZurek committed May 22, 2023
1 parent 8fa0b02 commit a1d56ff
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,20 @@

package com.facebook.react.fabric;

import android.annotation.SuppressLint;
import androidx.annotation.NonNull;
import com.facebook.jni.HybridData;
import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.NativeMap;
import com.facebook.react.bridge.ReadableNativeMap;
import com.facebook.react.bridge.RuntimeExecutor;
import com.facebook.react.bridge.RuntimeScheduler;
import com.facebook.react.common.mapbuffer.MapBufferSoLoader;
import com.facebook.react.fabric.events.EventBeatManager;
import com.facebook.react.fabric.events.EventEmitterWrapper;
import com.facebook.react.uimanager.PixelUtil;

@DoNotStrip
@SuppressLint("MissingNativeLoadLibrary")
public class Binding {
public interface Binding {

static {
FabricSoLoader.staticInit();
MapBufferSoLoader.staticInit();
}

@DoNotStrip private final HybridData mHybridData;

private static native HybridData initHybrid();

public Binding() {
mHybridData = initHybrid();
}

private native void installFabricUIManager(
RuntimeExecutor runtimeExecutor,
RuntimeScheduler runtimeScheduler,
FabricUIManager uiManager,
EventBeatManager eventBeatManager,
ComponentFactory componentsRegistry,
Object reactNativeConfig);

public native void startSurface(
public void startSurface(
int surfaceId, @NonNull String moduleName, @NonNull NativeMap initialProps);

public native void startSurfaceWithConstraints(
public void startSurfaceWithConstraints(
int surfaceId,
String moduleName,
NativeMap initialProps,
Expand All @@ -61,13 +33,13 @@ public native void startSurfaceWithConstraints(
boolean isRTL,
boolean doLeftAndRightSwapInRTL);

public native void renderTemplateToSurface(int surfaceId, String uiTemplate);
public void renderTemplateToSurface(int surfaceId, String uiTemplate);

public native void stopSurface(int surfaceId);
public void stopSurface(int surfaceId);

public native void setPixelDensity(float pointScaleFactor);
public void setPixelDensity(float pointScaleFactor);

public native void setConstraints(
public void setConstraints(
int surfaceId,
float minWidth,
float maxWidth,
Expand All @@ -78,37 +50,21 @@ public native void setConstraints(
boolean isRTL,
boolean doLeftAndRightSwapInRTL);

public native void driveCxxAnimations();
public void driveCxxAnimations();

public native ReadableNativeMap getInspectorDataForInstance(
EventEmitterWrapper eventEmitterWrapper);
public ReadableNativeMap getInspectorDataForInstance(EventEmitterWrapper eventEmitterWrapper);

public void register(
@NonNull RuntimeExecutor runtimeExecutor,
@NonNull RuntimeScheduler runtimeScheduler,
@NonNull FabricUIManager fabricUIManager,
@NonNull EventBeatManager eventBeatManager,
@NonNull ComponentFactory componentFactory,
@NonNull ReactNativeConfig reactNativeConfig) {
fabricUIManager.setBinding(this);
installFabricUIManager(
runtimeExecutor,
runtimeScheduler,
fabricUIManager,
eventBeatManager,
componentFactory,
reactNativeConfig);

setPixelDensity(PixelUtil.getDisplayMetricDensity());
}

private native void uninstallFabricUIManager();
@NonNull ReactNativeConfig reactNativeConfig);

public void unregister() {
uninstallFabricUIManager();
}
public void unregister();

public native void registerSurface(SurfaceHandlerBinding surfaceHandler);
public void registerSurface(SurfaceHandlerBinding surfaceHandler);

public native void unregisterSurface(SurfaceHandlerBinding surfaceHandler);
public void unregisterSurface(SurfaceHandlerBinding surfaceHandler);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* 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 android.annotation.SuppressLint;
import androidx.annotation.NonNull;
import com.facebook.jni.HybridData;
import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.NativeMap;
import com.facebook.react.bridge.ReadableNativeMap;
import com.facebook.react.bridge.RuntimeExecutor;
import com.facebook.react.bridge.RuntimeScheduler;
import com.facebook.react.common.mapbuffer.MapBufferSoLoader;
import com.facebook.react.fabric.events.EventBeatManager;
import com.facebook.react.fabric.events.EventEmitterWrapper;
import com.facebook.react.uimanager.PixelUtil;

@DoNotStrip
@SuppressLint("MissingNativeLoadLibrary")
public class BindingImpl implements Binding {

static {
FabricSoLoader.staticInit();
MapBufferSoLoader.staticInit();
}

@DoNotStrip private final HybridData mHybridData;

private static native HybridData initHybrid();

public BindingImpl() {
mHybridData = initHybrid();
}

private native void installFabricUIManager(
RuntimeExecutor runtimeExecutor,
RuntimeScheduler runtimeScheduler,
FabricUIManager uiManager,
EventBeatManager eventBeatManager,
ComponentFactory componentsRegistry,
Object reactNativeConfig);

@Override
public native void startSurface(
int surfaceId, @NonNull String moduleName, @NonNull NativeMap initialProps);

@Override
public native void startSurfaceWithConstraints(
int surfaceId,
String moduleName,
NativeMap initialProps,
float minWidth,
float maxWidth,
float minHeight,
float maxHeight,
float offsetX,
float offsetY,
boolean isRTL,
boolean doLeftAndRightSwapInRTL);

@Override
public native void renderTemplateToSurface(int surfaceId, String uiTemplate);

@Override
public native void stopSurface(int surfaceId);

@Override
public native void setPixelDensity(float pointScaleFactor);

@Override
public native void setConstraints(
int surfaceId,
float minWidth,
float maxWidth,
float minHeight,
float maxHeight,
float offsetX,
float offsetY,
boolean isRTL,
boolean doLeftAndRightSwapInRTL);

public native void driveCxxAnimations();

public native ReadableNativeMap getInspectorDataForInstance(
EventEmitterWrapper eventEmitterWrapper);

public void register(
@NonNull RuntimeExecutor runtimeExecutor,
@NonNull RuntimeScheduler runtimeScheduler,
@NonNull FabricUIManager fabricUIManager,
@NonNull EventBeatManager eventBeatManager,
@NonNull ComponentFactory componentFactory,
@NonNull ReactNativeConfig reactNativeConfig) {
fabricUIManager.setBinding(this);
installFabricUIManager(
runtimeExecutor,
runtimeScheduler,
fabricUIManager,
eventBeatManager,
componentFactory,
reactNativeConfig);

setPixelDensity(PixelUtil.getDisplayMetricDensity());
}

private native void uninstallFabricUIManager();

public void unregister() {
uninstallFabricUIManager();
}

public native void registerSurface(SurfaceHandlerBinding surfaceHandler);

public native void unregisterSurface(SurfaceHandlerBinding surfaceHandler);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public UIManager get() {

Systrace.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricJSIModuleProvider.registerBinding");
final Binding binding = new Binding();
final Binding binding = new BindingImpl();

binding.register(
mReactApplicationContext.getCatalystInstance().getRuntimeExecutor(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Binding : public jni::HybridClass<Binding>,
public LayoutAnimationStatusDelegate {
public:
constexpr static const char *const kJavaDescriptor =
"Lcom/facebook/react/fabric/Binding;";
"Lcom/facebook/react/fabric/BindingImpl;";

static void registerNatives();

Expand Down

0 comments on commit a1d56ff

Please sign in to comment.