Skip to content

Commit ab73f3e

Browse files
alanleedevfacebook-github-bot
authored andcommitted
Convert StateWrapperImpl.java to Kotlin
Summary: Convert Java to Kotlin Changelog: [Internal] Differential Revision: D72752437
1 parent e424a57 commit ab73f3e

File tree

3 files changed

+96
-105
lines changed

3 files changed

+96
-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: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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 val stateDataImpl: ReadableNativeMap?
31+
external get
32+
33+
private val stateMapBufferDataImpl: ReadableMapBuffer?
34+
external get
35+
36+
public external fun updateStateImpl(map: NativeMap)
37+
38+
public override val stateDataMapBuffer: ReadableMapBuffer?
39+
get() {
40+
if (!isValid) {
41+
FLog.e(TAG, "Race between StateWrapperImpl destruction and getState")
42+
return null
43+
}
44+
return stateMapBufferDataImpl
45+
}
46+
47+
public override val stateData: ReadableNativeMap?
48+
get() {
49+
if (!isValid) {
50+
FLog.e(TAG, "Race between StateWrapperImpl destruction and getState")
51+
return null
52+
}
53+
return stateDataImpl
54+
}
55+
56+
init {
57+
initHybrid()
58+
}
59+
60+
override fun updateState(map: WritableMap) {
61+
if (!isValid) {
62+
FLog.e(TAG, "Race between StateWrapperImpl destruction and updateState")
63+
return
64+
}
65+
updateStateImpl(map as NativeMap)
66+
}
67+
68+
override fun destroyState() {
69+
if (isValid) {
70+
resetNative()
71+
}
72+
}
73+
74+
override fun toString(): String {
75+
if (!isValid) {
76+
return "<destroyed>"
77+
}
78+
79+
val mapBuffer = stateMapBufferDataImpl
80+
if (mapBuffer != null) {
81+
return mapBuffer.toString()
82+
}
83+
84+
return stateDataImpl?.toString() ?: "<unexpected null: stateDataImpl>"
85+
}
86+
87+
private companion object {
88+
init {
89+
FabricSoLoader.staticInit()
90+
}
91+
92+
private const val TAG = "StateWrapperImpl"
93+
}
94+
}

0 commit comments

Comments
 (0)