Skip to content

Commit 87fc3cf

Browse files
split StateWrapper.updateState overloads and mark UpdateMode unstable
1 parent 0c868e1 commit 87fc3cf

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import com.facebook.proguard.annotations.DoNotStripAny
1414
import com.facebook.react.bridge.NativeMap
1515
import com.facebook.react.bridge.ReadableNativeMap
1616
import com.facebook.react.bridge.WritableMap
17+
import com.facebook.react.common.annotations.UnstableReactNativeAPI
1718
import com.facebook.react.common.mapbuffer.ReadableMapBuffer
1819
import com.facebook.react.uimanager.ReferenceStateWrapper
1920
import com.facebook.react.uimanager.StateWrapper
@@ -24,6 +25,7 @@ import com.facebook.react.uimanager.StateWrapper
2425
*/
2526
@SuppressLint("MissingNativeLoadLibrary")
2627
@DoNotStripAny
28+
@OptIn(UnstableReactNativeAPI::class)
2729
internal class StateWrapperImpl private constructor() : HybridClassBase(), ReferenceStateWrapper {
2830

2931
private external fun initHybrid()
@@ -67,6 +69,10 @@ internal class StateWrapperImpl private constructor() : HybridClassBase(), Refer
6769
initHybrid()
6870
}
6971

72+
override fun updateState(map: WritableMap) {
73+
updateState(map, StateWrapper.UpdateMode.Asynchronous)
74+
}
75+
7076
override fun updateState(map: WritableMap, updateMode: StateWrapper.UpdateMode) {
7177
if (!isValid) {
7278
FLog.e(TAG, "Race between StateWrapperImpl destruction and updateState")

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/StateWrapper.kt‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package com.facebook.react.uimanager
99

1010
import com.facebook.react.bridge.ReadableNativeMap
1111
import com.facebook.react.bridge.WritableMap
12+
import com.facebook.react.common.annotations.UnstableReactNativeAPI
1213
import com.facebook.react.common.mapbuffer.ReadableMapBuffer
1314

1415
/**
@@ -20,6 +21,7 @@ public interface StateWrapper {
2021
/**
2122
* Maps to EventQueue::UpdateMode in C++. Controls how state updates are flushed (Async or Sync).
2223
*/
24+
@UnstableReactNativeAPI
2325
public enum class UpdateMode(public val value: Int) {
2426
Asynchronous(0),
2527
unstable_Immediate(1),
@@ -39,9 +41,15 @@ public interface StateWrapper {
3941

4042
/**
4143
* Pass a map of values back to the C++ layer. The operation is performed synchronously and cannot
42-
* fail. updateMode controls whether the update is queued asynchronously or flushed immediately.
44+
* fail.
4345
*/
44-
public fun updateState(map: WritableMap, updateMode: UpdateMode = UpdateMode.Asynchronous)
46+
public fun updateState(map: WritableMap)
47+
48+
/**
49+
* Pass a map of values back to the C++ layer. updateMode controls whether the update is queued
50+
* asynchronously or flushed immediately.
51+
*/
52+
@UnstableReactNativeAPI public fun updateState(map: WritableMap, updateMode: UpdateMode)
4553

4654
/**
4755
* Mark state as unused and clean up in Java and in native. This should be called as early as

‎packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/StateWrapperUpdateModeTest.kt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
package com.facebook.react.uimanager
99

10+
import com.facebook.react.common.annotations.UnstableReactNativeAPI
1011
import com.facebook.react.uimanager.StateWrapper.UpdateMode
1112
import org.assertj.core.api.Assertions.assertThat
1213
import org.junit.Test
@@ -18,6 +19,7 @@ import org.robolectric.RobolectricTestRunner
1819
* must match its order (Asynchronous = 0, unstable_Immediate = 1). A mismatch silently flips
1920
* async/sync state updates.
2021
*/
22+
@OptIn(UnstableReactNativeAPI::class)
2123
@RunWith(RobolectricTestRunner::class)
2224
class StateWrapperUpdateModeTest {
2325

0 commit comments

Comments
 (0)