Skip to content

Commit f9bd9b0

Browse files
alanleedevfacebook-github-bot
authored andcommitted
Convert StateWrapperImpl.java to Kotlin (facebook#50615)
Summary: Pull Request resolved: facebook#50615 Convert Java to Kotlin Changelog: [Internal] Differential Revision: D72752437
1 parent e424a57 commit f9bd9b0

File tree

3 files changed

+94
-105
lines changed

3 files changed

+94
-105
lines changed

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2389,13 +2389,13 @@ public final class com/facebook/react/fabric/FabricUIManagerProviderImpl : com/f
23892389
public fun createUIManager (Lcom/facebook/react/bridge/ReactApplicationContext;)Lcom/facebook/react/bridge/UIManager;
23902390
}
23912391

2392-
public class com/facebook/react/fabric/StateWrapperImpl : com/facebook/jni/HybridClassBase, com/facebook/react/uimanager/StateWrapper {
2392+
public final class com/facebook/react/fabric/StateWrapperImpl : com/facebook/jni/HybridClassBase, com/facebook/react/uimanager/StateWrapper {
23932393
public fun destroyState ()V
23942394
public fun getStateData ()Lcom/facebook/react/bridge/ReadableNativeMap;
23952395
public fun getStateDataMapBuffer ()Lcom/facebook/react/common/mapbuffer/ReadableMapBuffer;
23962396
public fun toString ()Ljava/lang/String;
23972397
public fun updateState (Lcom/facebook/react/bridge/WritableMap;)V
2398-
public fun updateStateImpl (Lcom/facebook/react/bridge/NativeMap;)V
2398+
public final fun updateStateImpl (Lcom/facebook/react/bridge/NativeMap;)V
23992399
}
24002400

24012401
public final class com/facebook/react/fabric/events/EventBeatManager : com/facebook/jni/HybridClassBase, com/facebook/react/uimanager/events/BatchEventDispatchedListener {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/StateWrapperImpl.java

Lines changed: 0 additions & 103 deletions
This file was deleted.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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.react.fabric
9+
10+
import android.annotation.SuppressLint
11+
import com.facebook.common.logging.FLog
12+
import com.facebook.jni.HybridClassBase
13+
import com.facebook.proguard.annotations.DoNotStripAny
14+
import com.facebook.react.bridge.NativeMap
15+
import com.facebook.react.bridge.ReadableNativeMap
16+
import com.facebook.react.bridge.WritableMap
17+
import com.facebook.react.common.mapbuffer.ReadableMapBuffer
18+
import com.facebook.react.uimanager.StateWrapper
19+
20+
/**
21+
* This class holds reference to the C++ EventEmitter object. Instances of this class are created on
22+
* the Bindings.cpp, where the pointer to the C++ event emitter is set.
23+
*/
24+
@SuppressLint("MissingNativeLoadLibrary")
25+
@DoNotStripAny
26+
public class StateWrapperImpl private constructor() : HybridClassBase(), StateWrapper {
27+
28+
private external fun initHybrid()
29+
30+
private external fun getStateDataImpl(): ReadableNativeMap?
31+
32+
private external fun getStateMapBufferDataImpl(): ReadableMapBuffer?
33+
34+
public external fun updateStateImpl(map: NativeMap)
35+
36+
public override val stateDataMapBuffer: ReadableMapBuffer?
37+
get() {
38+
if (!isValid) {
39+
FLog.e(TAG, "Race between StateWrapperImpl destruction and getState")
40+
return null
41+
}
42+
return getStateMapBufferDataImpl()
43+
}
44+
45+
public override val stateData: ReadableNativeMap?
46+
get() {
47+
if (!isValid) {
48+
FLog.e(TAG, "Race between StateWrapperImpl destruction and getState")
49+
return null
50+
}
51+
return getStateDataImpl()
52+
}
53+
54+
init {
55+
initHybrid()
56+
}
57+
58+
override fun updateState(map: WritableMap) {
59+
if (!isValid) {
60+
FLog.e(TAG, "Race between StateWrapperImpl destruction and updateState")
61+
return
62+
}
63+
updateStateImpl(map as NativeMap)
64+
}
65+
66+
override fun destroyState() {
67+
if (isValid) {
68+
resetNative()
69+
}
70+
}
71+
72+
override fun toString(): String {
73+
if (!isValid) {
74+
return "<destroyed>"
75+
}
76+
77+
val mapBuffer = getStateMapBufferDataImpl()
78+
if (mapBuffer != null) {
79+
return mapBuffer.toString()
80+
}
81+
82+
return getStateDataImpl()?.toString() ?: "<unexpected null: stateDataImpl>"
83+
}
84+
85+
private companion object {
86+
init {
87+
FabricSoLoader.staticInit()
88+
}
89+
90+
private const val TAG = "StateWrapperImpl"
91+
}
92+
}

0 commit comments

Comments
 (0)