forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate SurfaceHandlerBinding to kotlin (facebook#48870)
Summary: Pull Request resolved: facebook#48870 Migrate SurfaceHandlerBinding to kotlin changelog: [internal] internal Reviewed By: cortinico Differential Revision: D68480893
- Loading branch information
Showing
3 changed files
with
94 additions
and
90 deletions.
There are no files selected for viewing
87 changes: 0 additions & 87 deletions
87
...ct-native/ReactAndroid/src/main/java/com/facebook/react/fabric/SurfaceHandlerBinding.java
This file was deleted.
Oops, something went wrong.
91 changes: 91 additions & 0 deletions
91
...eact-native/ReactAndroid/src/main/java/com/facebook/react/fabric/SurfaceHandlerBinding.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters