Skip to content

Commit f5982b1

Browse files
andrewdacenkometa-codesync[bot]
authored andcommitted
Convert YogaConfigJNIFinalizer and YogaNodeJNIFinalizer to Kotlin
Summary: Changelog: [Internal] Convert the last two Java finalizer classes in the yoga package to Kotlin, continuing the React Native Kotlinification effort. Both classes are simple JNI native memory cleanup wrappers (32 and 36 lines) that extend already-Kotlin base classes. Changes: - Convert `YogaConfigJNIFinalizer.java` → `.kt` (ReactAndroid + xplat/yoga copies) - Convert `YogaNodeJNIFinalizer.java` → `.kt` (ReactAndroid + xplat/yoga copies) - Remove `super.finalize()` calls (no-op in parent chain, and `Object.finalize()` is not directly callable from Kotlin) The `:yoga` Buck target already has `language = "KOTLIN"` and globs both `*.java` and `*.kt`, so no build config changes are needed. Differential Revision: D95872345
1 parent d527f2d commit f5982b1

File tree

4 files changed

+51
-66
lines changed

4 files changed

+51
-66
lines changed

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

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
public class YogaConfigJNIFinalizer internal constructor() : YogaConfigJNIBase() {
11+
12+
@Throws(Throwable::class)
13+
protected fun finalize() {
14+
freeNatives()
15+
}
16+
17+
public fun freeNatives() {
18+
if (nativePointer != 0L) {
19+
val pointer = nativePointer
20+
nativePointer = 0
21+
YogaNative.jni_YGConfigFreeJNI(pointer)
22+
}
23+
}
24+
}

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

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
public class YogaNodeJNIFinalizer : YogaNodeJNIBase {
11+
public constructor() : super()
12+
13+
public constructor(config: YogaConfig) : super(config)
14+
15+
@Throws(Throwable::class)
16+
protected fun finalize() {
17+
freeNatives()
18+
}
19+
20+
public fun freeNatives() {
21+
if (mNativePointer != 0L) {
22+
val nativePointer = mNativePointer
23+
mNativePointer = 0
24+
YogaNative.jni_YGNodeFinalizeJNI(nativePointer)
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)