Migrate YogaConfigJNIBase to Kotlin (#55419)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/55419

Migrate com.facebook.yoga.YogaConfigJNIBase to Kotlin.

X-link: https://github.com/facebook/yoga/pull/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
This commit is contained in:
Mateo Guzmán authored and meta-codesync[bot] committed 2026-02-10 02:18:26 -08:00
1 parent d5399dd40d
commit 9db85e7503
6 files changed
+72 -70

No files matched your search

@@ -21,9 +21,9 @@ public abstract class YogaConfig {
public abstract fun getErrata(): YogaErrata
public abstract fun setLogger(logger: YogaLogger)
public abstract fun setLogger(logger: YogaLogger?)
public abstract fun getLogger(): YogaLogger
public abstract fun getLogger(): YogaLogger?
protected abstract fun getNativePointer(): Long
@@ -1,62 +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.yoga;
public abstract class YogaConfigJNIBase extends YogaConfig {
long mNativePointer;
private YogaLogger mLogger;
private YogaConfigJNIBase(long nativePointer) {
if (nativePointer == 0) {
throw new IllegalStateException("Failed to allocate native memory");
}
mNativePointer = nativePointer;
}
YogaConfigJNIBase() {
this(YogaNative.jni_YGConfigNewJNI());
}
YogaConfigJNIBase(boolean useVanillaJNI) {
this(YogaNative.jni_YGConfigNewJNI());
}
public void setExperimentalFeatureEnabled(YogaExperimentalFeature feature, boolean enabled) {
YogaNative.jni_YGConfigSetExperimentalFeatureEnabledJNI(mNativePointer, feature.intValue(), enabled);
}
public void setUseWebDefaults(boolean useWebDefaults) {
YogaNative.jni_YGConfigSetUseWebDefaultsJNI(mNativePointer, useWebDefaults);
}
public void setPointScaleFactor(float pixelsInPoint) {
YogaNative.jni_YGConfigSetPointScaleFactorJNI(mNativePointer, pixelsInPoint);
}
public void setErrata(YogaErrata errata) {
YogaNative.jni_YGConfigSetErrataJNI(mNativePointer, errata.intValue());
}
public YogaErrata getErrata() {
return YogaErrata.fromInt(YogaNative.jni_YGConfigGetErrataJNI(mNativePointer));
}
public void setLogger(YogaLogger logger) {
mLogger = logger;
YogaNative.jni_YGConfigSetLoggerJNI(mNativePointer, logger);
}
public YogaLogger getLogger() {
return mLogger;
}
protected long getNativePointer() {
return mNativePointer;
}
}
@@ -0,0 +1,64 @@
/*
* 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.yoga
import com.facebook.yoga.YogaNative.jni_YGConfigGetErrataJNI
import com.facebook.yoga.YogaNative.jni_YGConfigNewJNI
import com.facebook.yoga.YogaNative.jni_YGConfigSetErrataJNI
import com.facebook.yoga.YogaNative.jni_YGConfigSetExperimentalFeatureEnabledJNI
import com.facebook.yoga.YogaNative.jni_YGConfigSetLoggerJNI
import com.facebook.yoga.YogaNative.jni_YGConfigSetPointScaleFactorJNI
import com.facebook.yoga.YogaNative.jni_YGConfigSetUseWebDefaultsJNI
public abstract class YogaConfigJNIBase
private constructor(@JvmField protected var nativePointer: Long) : YogaConfig() {
private var _logger: YogaLogger? = null
init {
check(nativePointer != 0L) { "Failed to allocate native memory" }
}
internal constructor() : this(jni_YGConfigNewJNI())
internal constructor(useVanillaJNI: Boolean) : this(jni_YGConfigNewJNI())
public override fun setExperimentalFeatureEnabled(
feature: YogaExperimentalFeature,
enabled: Boolean,
) {
YogaNative.jni_YGConfigSetExperimentalFeatureEnabledJNI(
nativePointer,
feature.intValue(),
enabled,
)
}
public override fun setUseWebDefaults(useWebDefaults: Boolean) {
YogaNative.jni_YGConfigSetUseWebDefaultsJNI(nativePointer, useWebDefaults)
}
public override fun setPointScaleFactor(pixelsInPoint: Float) {
YogaNative.jni_YGConfigSetPointScaleFactorJNI(nativePointer, pixelsInPoint)
}
public override fun setErrata(errata: YogaErrata) {
YogaNative.jni_YGConfigSetErrataJNI(nativePointer, errata.intValue())
}
public override fun getErrata(): YogaErrata =
YogaErrata.fromInt(YogaNative.jni_YGConfigGetErrataJNI(nativePointer))
public override fun setLogger(logger: YogaLogger?) {
_logger = logger
YogaNative.jni_YGConfigSetLoggerJNI(nativePointer, logger)
}
public override fun getLogger(): YogaLogger? = _logger
public override fun getNativePointer(): Long = nativePointer
}
@@ -22,10 +22,10 @@ public class YogaConfigJNIFinalizer extends YogaConfigJNIBase {
}
public void freeNatives() {
if (mNativePointer != 0) {
long nativePointer = mNativePointer;
mNativePointer = 0;
YogaNative.jni_YGConfigFreeJNI(nativePointer);
if (nativePointer != 0) {
long pointer = nativePointer;
nativePointer = 0;
YogaNative.jni_YGConfigFreeJNI(pointer);
}
}
}
@@ -39,7 +39,7 @@ public object YogaNative {
@JvmStatic public external fun jni_YGConfigGetErrataJNI(nativePointer: Long): Int
@JvmStatic public external fun jni_YGConfigSetLoggerJNI(nativePointer: Long, logger: YogaLogger)
@JvmStatic public external fun jni_YGConfigSetLoggerJNI(nativePointer: Long, logger: YogaLogger?)
// YGNode related
@JvmStatic public external fun jni_YGNodeNewJNI(): Long
@@ -57,7 +57,7 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
}
YogaNodeJNIBase(YogaConfig config) {
this(YogaNative.jni_YGNodeNewWithConfigJNI(((YogaConfigJNIBase) config).mNativePointer));
this(YogaNative.jni_YGNodeNewWithConfigJNI(((YogaConfigJNIBase) config).nativePointer));
mConfig = config; // makes sure the YogaConfig is not garbage collected
}