-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fabric Interop - Properly dispatch integer commands (#38527)
Summary: Pull Request resolved: #38527 This fixes a bug that got reported for the Fabric Interop for Android with Command dispatching. (See terrylinla/react-native-sketch-canvas#236) The problem is that libraries that were receiving commands as ints with: ``` public void receiveCommand( int surfaceId, int reactTag, int commandId, Nullable ReadableArray commandArgs) { ``` would not receive command with the Fabric Interop for Android. The problem is that with Fabric, events are dispatched as string always. cipolleschi took care of this for iOS, but we realized that the Android part was missing. I'm adding it here. The logic is, if the event is dispatched as a string that represents a number (say `"42"`) and the user has Fabric Interop enabled, then we dispatch the event as `int` (so libraries will keep on working). Changelog: [Android] [Fixed] - Fabric Interop - Properly dispatch integer commands Reviewed By: cipolleschi Differential Revision: D47600094 fbshipit-source-id: ee4b4829610c42304bcbf50bd27d2b4093dae760
- Loading branch information
1 parent
f6197cd
commit c83792c
Showing
4 changed files
with
127 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
.../react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/FabricUIManagerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* 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.react.fabric | ||
|
||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.uimanager.ViewManagerRegistry | ||
import com.facebook.react.uimanager.events.BatchEventDispatchedListener | ||
import com.facebook.testutils.fakes.FakeBatchEventDispatchedListener | ||
import com.facebook.testutils.shadows.ShadowSoLoader | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
import org.robolectric.RuntimeEnvironment | ||
import org.robolectric.annotation.Config | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
@Config(shadows = [ShadowSoLoader::class]) | ||
class FabricUIManagerTest { | ||
|
||
private lateinit var reactContext: ReactApplicationContext | ||
private lateinit var viewManagerRegistry: ViewManagerRegistry | ||
private lateinit var batchEventDispatchedListener: BatchEventDispatchedListener | ||
private lateinit var underTest: FabricUIManager | ||
|
||
@Before | ||
fun setup() { | ||
reactContext = ReactApplicationContext(RuntimeEnvironment.getApplication()) | ||
viewManagerRegistry = ViewManagerRegistry(emptyList()) | ||
batchEventDispatchedListener = FakeBatchEventDispatchedListener() | ||
underTest = FabricUIManager(reactContext, viewManagerRegistry, batchEventDispatchedListener) | ||
} | ||
|
||
@Test | ||
fun createDispatchCommandMountItemForInterop_withValidString_returnsStringEvent() { | ||
val command = underTest.createDispatchCommandMountItemForInterop(11, 1, "anEvent", null) | ||
|
||
// DispatchStringCommandMountItem is package private so we can `as` check it. | ||
val className = command::class.java.name.substringAfterLast(".") | ||
assertEquals("DispatchStringCommandMountItem", className) | ||
} | ||
|
||
@Test | ||
fun createDispatchCommandMountItemForInterop_withValidInt_returnsIntEvent() { | ||
val command = underTest.createDispatchCommandMountItemForInterop(11, 1, "42", null) | ||
|
||
// DispatchIntCommandMountItem is package private so we can `as` check it. | ||
val className = command::class.java.name.substringAfterLast(".") | ||
assertEquals("DispatchIntCommandMountItem", className) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...actAndroid/src/test/java/com/facebook/testutils/fakes/FakeBatchEventDispatchedListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* 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.testutils.fakes | ||
|
||
import com.facebook.react.uimanager.events.BatchEventDispatchedListener | ||
|
||
/** A fake [BatchEventDispatchedListener] for testing that does nothing. */ | ||
class FakeBatchEventDispatchedListener : BatchEventDispatchedListener { | ||
override fun onBatchEventDispatched() { | ||
// do nothing | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters