-
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
Summary: 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 Differential Revision: D47600094 fbshipit-source-id: a051eaf145cacaa275f520c46aeea95165f842a0
- Loading branch information
1 parent
2d3348e
commit 8d0684a
Showing
4 changed files
with
117 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
52 changes: 52 additions & 0 deletions
52
.../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,52 @@ | ||
package com.facebook.react.fabric | ||
|
||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.fabric.events.EventBeatManager | ||
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.Assert.assertTrue | ||
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) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...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,12 @@ | ||
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