Skip to content

Commit 9db85e7

Browse files
mateoguzmanameta-codesync[bot]
authored andcommitted
Migrate YogaConfigJNIBase to Kotlin (#55419)
Summary: Pull Request resolved: #55419 Migrate com.facebook.yoga.YogaConfigJNIBase to Kotlin. X-link: react/yoga#1850 Test Plan: RN ```sh yarn android yarn test-android ``` Yoga ```sh ./gradlew :yoga:assembleDebug ``` Reviewed By: alanleedev Differential Revision: D92398806 Pulled By: cortinico fbshipit-source-id: 366f3eca95d2b03c62636c0c947f15aa075534b6
1 parent d5399dd commit 9db85e7

6 files changed

Lines changed: 72 additions & 70 deletions

File tree

packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaConfig.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public abstract class YogaConfig {
2121

2222
public abstract fun getErrata(): YogaErrata
2323

24-
public abstract fun setLogger(logger: YogaLogger)
24+
public abstract fun setLogger(logger: YogaLogger?)
2525

26-
public abstract fun getLogger(): YogaLogger
26+
public abstract fun getLogger(): YogaLogger?
2727

2828
protected abstract fun getNativePointer(): Long
2929

packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaConfigJNIBase.java

Lines changed: 0 additions & 62 deletions
This file was deleted.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.yoga
9+
10+
import com.facebook.yoga.YogaNative.jni_YGConfigGetErrataJNI
11+
import com.facebook.yoga.YogaNative.jni_YGConfigNewJNI
12+
import com.facebook.yoga.YogaNative.jni_YGConfigSetErrataJNI
13+
import com.facebook.yoga.YogaNative.jni_YGConfigSetExperimentalFeatureEnabledJNI
14+
import com.facebook.yoga.YogaNative.jni_YGConfigSetLoggerJNI
15+
import com.facebook.yoga.YogaNative.jni_YGConfigSetPointScaleFactorJNI
16+
import com.facebook.yoga.YogaNative.jni_YGConfigSetUseWebDefaultsJNI
17+
18+
public abstract class YogaConfigJNIBase
19+
private constructor(@JvmField protected var nativePointer: Long) : YogaConfig() {
20+
private var _logger: YogaLogger? = null
21+
22+
init {
23+
check(nativePointer != 0L) { "Failed to allocate native memory" }
24+
}
25+
26+
internal constructor() : this(jni_YGConfigNewJNI())
27+
28+
internal constructor(useVanillaJNI: Boolean) : this(jni_YGConfigNewJNI())
29+
30+
public override fun setExperimentalFeatureEnabled(
31+
feature: YogaExperimentalFeature,
32+
enabled: Boolean,
33+
) {
34+
YogaNative.jni_YGConfigSetExperimentalFeatureEnabledJNI(
35+
nativePointer,
36+
feature.intValue(),
37+
enabled,
38+
)
39+
}
40+
41+
public override fun setUseWebDefaults(useWebDefaults: Boolean) {
42+
YogaNative.jni_YGConfigSetUseWebDefaultsJNI(nativePointer, useWebDefaults)
43+
}
44+
45+
public override fun setPointScaleFactor(pixelsInPoint: Float) {
46+
YogaNative.jni_YGConfigSetPointScaleFactorJNI(nativePointer, pixelsInPoint)
47+
}
48+
49+
public override fun setErrata(errata: YogaErrata) {
50+
YogaNative.jni_YGConfigSetErrataJNI(nativePointer, errata.intValue())
51+
}
52+
53+
public override fun getErrata(): YogaErrata =
54+
YogaErrata.fromInt(YogaNative.jni_YGConfigGetErrataJNI(nativePointer))
55+
56+
public override fun setLogger(logger: YogaLogger?) {
57+
_logger = logger
58+
YogaNative.jni_YGConfigSetLoggerJNI(nativePointer, logger)
59+
}
60+
61+
public override fun getLogger(): YogaLogger? = _logger
62+
63+
public override fun getNativePointer(): Long = nativePointer
64+
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaConfigJNIFinalizer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ protected void finalize() throws Throwable {
2222
}
2323

2424
public void freeNatives() {
25-
if (mNativePointer != 0) {
26-
long nativePointer = mNativePointer;
27-
mNativePointer = 0;
28-
YogaNative.jni_YGConfigFreeJNI(nativePointer);
25+
if (nativePointer != 0) {
26+
long pointer = nativePointer;
27+
nativePointer = 0;
28+
YogaNative.jni_YGConfigFreeJNI(pointer);
2929
}
3030
}
3131
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaNative.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public object YogaNative {
3939

4040
@JvmStatic public external fun jni_YGConfigGetErrataJNI(nativePointer: Long): Int
4141

42-
@JvmStatic public external fun jni_YGConfigSetLoggerJNI(nativePointer: Long, logger: YogaLogger)
42+
@JvmStatic public external fun jni_YGConfigSetLoggerJNI(nativePointer: Long, logger: YogaLogger?)
4343

4444
// YGNode related
4545
@JvmStatic public external fun jni_YGNodeNewJNI(): Long

packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaNodeJNIBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private YogaNodeJNIBase(long nativePointer) {
5757
}
5858

5959
YogaNodeJNIBase(YogaConfig config) {
60-
this(YogaNative.jni_YGNodeNewWithConfigJNI(((YogaConfigJNIBase) config).mNativePointer));
60+
this(YogaNative.jni_YGNodeNewWithConfigJNI(((YogaConfigJNIBase) config).nativePointer));
6161
mConfig = config; // makes sure the YogaConfig is not garbage collected
6262
}
6363

0 commit comments

Comments
 (0)