mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Migrate SurfaceHandlerBinding to kotlin (#48870)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48870 Migrate SurfaceHandlerBinding to kotlin changelog: [internal] internal Reviewed By: cortinico Differential Revision: D68480893 fbshipit-source-id: a326d2646212598ded962d25cb8d1caf7a2ed6aa
This commit is contained in:
committed by
Facebook GitHub Bot
parent
d1028885ee
commit
c5af75294a
-87
@@ -1,87 +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 static com.facebook.react.fabric.mounting.LayoutMetricsConversions.getMaxSize;
|
||||
import static com.facebook.react.fabric.mounting.LayoutMetricsConversions.getMinSize;
|
||||
|
||||
import com.facebook.infer.annotation.Nullsafe;
|
||||
import com.facebook.jni.HybridClassBase;
|
||||
import com.facebook.react.bridge.NativeMap;
|
||||
import com.facebook.react.interfaces.fabric.SurfaceHandler;
|
||||
|
||||
@Nullsafe(Nullsafe.Mode.LOCAL)
|
||||
public class SurfaceHandlerBinding extends HybridClassBase implements SurfaceHandler {
|
||||
static {
|
||||
FabricSoLoader.staticInit();
|
||||
}
|
||||
|
||||
private static final int NO_SURFACE_ID = 0;
|
||||
|
||||
/* Keep in sync with SurfaceHandler.cpp */
|
||||
public static final int DISPLAY_MODE_VISIBLE = 0;
|
||||
public static final int DISPLAY_MODE_SUSPENDED = 1;
|
||||
public static final int DISPLAY_MODE_HIDDEN = 2;
|
||||
|
||||
private native void initHybrid(int surfaceId, String moduleName);
|
||||
|
||||
public SurfaceHandlerBinding(String moduleName) {
|
||||
initHybrid(NO_SURFACE_ID, moduleName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public native int getSurfaceId();
|
||||
|
||||
@Override
|
||||
public native String getModuleName();
|
||||
|
||||
@Override
|
||||
public native boolean isRunning();
|
||||
|
||||
@Override
|
||||
public void setLayoutConstraints(
|
||||
int widthMeasureSpec,
|
||||
int heightMeasureSpec,
|
||||
int offsetX,
|
||||
int offsetY,
|
||||
boolean doLeftAndRightSwapInRTL,
|
||||
boolean isRTL,
|
||||
float pixelDensity) {
|
||||
setLayoutConstraintsNative(
|
||||
getMinSize(widthMeasureSpec) / pixelDensity,
|
||||
getMaxSize(widthMeasureSpec) / pixelDensity,
|
||||
getMinSize(heightMeasureSpec) / pixelDensity,
|
||||
getMaxSize(heightMeasureSpec) / pixelDensity,
|
||||
offsetX / pixelDensity,
|
||||
offsetY / pixelDensity,
|
||||
doLeftAndRightSwapInRTL,
|
||||
isRTL,
|
||||
pixelDensity);
|
||||
}
|
||||
|
||||
private native void setLayoutConstraintsNative(
|
||||
float minWidth,
|
||||
float maxWidth,
|
||||
float minHeight,
|
||||
float maxHeight,
|
||||
float offsetX,
|
||||
float offsetY,
|
||||
boolean doLeftAndRightSwapInRTL,
|
||||
boolean isRTL,
|
||||
float pixelDensity);
|
||||
|
||||
@Override
|
||||
public native void setProps(NativeMap props);
|
||||
|
||||
@Override
|
||||
public void setMountable(boolean mountable) {
|
||||
setDisplayMode(mountable ? DISPLAY_MODE_VISIBLE : DISPLAY_MODE_SUSPENDED);
|
||||
}
|
||||
|
||||
private native void setDisplayMode(int mode);
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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.jni.HybridClassBase
|
||||
import com.facebook.react.bridge.NativeMap
|
||||
import com.facebook.react.fabric.mounting.LayoutMetricsConversions
|
||||
import com.facebook.react.interfaces.fabric.SurfaceHandler
|
||||
|
||||
public open class SurfaceHandlerBinding(moduleName: String) : HybridClassBase(), SurfaceHandler {
|
||||
|
||||
init {
|
||||
initHybrid(NO_SURFACE_ID, moduleName)
|
||||
}
|
||||
|
||||
private external fun initHybrid(surfaceId: Int, moduleName: String)
|
||||
|
||||
override val surfaceId: Int
|
||||
get() = _getSurfaceId()
|
||||
|
||||
override val isRunning: Boolean
|
||||
get() = _isRunning()
|
||||
|
||||
override val moduleName: String
|
||||
get() = _getModuleName()
|
||||
|
||||
private external fun _getSurfaceId(): Int
|
||||
|
||||
private external fun _getModuleName(): String
|
||||
|
||||
private external fun _isRunning(): Boolean
|
||||
|
||||
override fun setLayoutConstraints(
|
||||
widthMeasureSpec: Int,
|
||||
heightMeasureSpec: Int,
|
||||
offsetX: Int,
|
||||
offsetY: Int,
|
||||
doLeftAndRightSwapInRTL: Boolean,
|
||||
isRTL: Boolean,
|
||||
pixelDensity: Float
|
||||
) {
|
||||
setLayoutConstraintsNative(
|
||||
LayoutMetricsConversions.getMinSize(widthMeasureSpec) / pixelDensity,
|
||||
LayoutMetricsConversions.getMaxSize(widthMeasureSpec) / pixelDensity,
|
||||
LayoutMetricsConversions.getMinSize(heightMeasureSpec) / pixelDensity,
|
||||
LayoutMetricsConversions.getMaxSize(heightMeasureSpec) / pixelDensity,
|
||||
offsetX / pixelDensity,
|
||||
offsetY / pixelDensity,
|
||||
doLeftAndRightSwapInRTL,
|
||||
isRTL,
|
||||
pixelDensity)
|
||||
}
|
||||
|
||||
private external fun setLayoutConstraintsNative(
|
||||
minWidth: Float,
|
||||
maxWidth: Float,
|
||||
minHeight: Float,
|
||||
maxHeight: Float,
|
||||
offsetX: Float,
|
||||
offsetY: Float,
|
||||
doLeftAndRightSwapInRTL: Boolean,
|
||||
isRTL: Boolean,
|
||||
pixelDensity: Float
|
||||
)
|
||||
|
||||
external override fun setProps(props: NativeMap)
|
||||
|
||||
override fun setMountable(mountable: Boolean) {
|
||||
setDisplayMode(if (mountable) DISPLAY_MODE_VISIBLE else DISPLAY_MODE_SUSPENDED)
|
||||
}
|
||||
|
||||
private external fun setDisplayMode(mode: Int)
|
||||
|
||||
private companion object {
|
||||
private const val NO_SURFACE_ID = 0
|
||||
|
||||
// Keep in sync with SurfaceHandler.cpp
|
||||
const val DISPLAY_MODE_VISIBLE = 0
|
||||
const val DISPLAY_MODE_SUSPENDED = 1
|
||||
const val DISPLAY_MODE_HIDDEN = 2
|
||||
|
||||
init {
|
||||
FabricSoLoader.staticInit()
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -73,9 +73,9 @@ const SurfaceHandler& SurfaceHandlerBinding::getSurfaceHandler() {
|
||||
void SurfaceHandlerBinding::registerNatives() {
|
||||
registerHybrid({
|
||||
makeNativeMethod("initHybrid", SurfaceHandlerBinding::initHybrid),
|
||||
makeNativeMethod("getSurfaceId", SurfaceHandlerBinding::getSurfaceId),
|
||||
makeNativeMethod("isRunning", SurfaceHandlerBinding::isRunning),
|
||||
makeNativeMethod("getModuleName", SurfaceHandlerBinding::getModuleName),
|
||||
makeNativeMethod("_getSurfaceId", SurfaceHandlerBinding::getSurfaceId),
|
||||
makeNativeMethod("_isRunning", SurfaceHandlerBinding::isRunning),
|
||||
makeNativeMethod("_getModuleName", SurfaceHandlerBinding::getModuleName),
|
||||
makeNativeMethod(
|
||||
"setLayoutConstraintsNative",
|
||||
SurfaceHandlerBinding::setLayoutConstraints),
|
||||
|
||||
Reference in New Issue
Block a user