Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix InteropUIBlockListener to support react-native-view-shot on Bridgeless #43594

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -2539,7 +2539,7 @@ public class com/facebook/react/fabric/FabricSoLoader {
public static fun staticInit ()V
}

public class com/facebook/react/fabric/FabricUIManager : com/facebook/react/bridge/LifecycleEventListener, com/facebook/react/bridge/UIManager {
public class com/facebook/react/fabric/FabricUIManager : com/facebook/react/bridge/LifecycleEventListener, com/facebook/react/bridge/UIManager, com/facebook/react/fabric/interop/UIBlockViewResolver {
public static final field ENABLE_FABRIC_LOGS Z
public static final field ENABLE_FABRIC_PERF_LOGS Z
public static final field IS_DEVELOPMENT_ENVIRONMENT Z
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import com.facebook.react.fabric.events.FabricEventEmitter;
import com.facebook.react.fabric.internal.interop.InteropUIBlockListener;
import com.facebook.react.fabric.interop.UIBlock;
import com.facebook.react.fabric.interop.UIBlockViewResolver;
import com.facebook.react.fabric.mounting.MountItemDispatcher;
import com.facebook.react.fabric.mounting.MountingManager;
import com.facebook.react.fabric.mounting.SurfaceMountingManager;
Expand Down Expand Up @@ -99,7 +100,7 @@
*/
@SuppressLint("MissingNativeLoadLibrary")
@DoNotStripAny
public class FabricUIManager implements UIManager, LifecycleEventListener {
public class FabricUIManager implements UIManager, LifecycleEventListener, UIBlockViewResolver {
public static final String TAG = FabricUIManager.class.getSimpleName();

// The IS_DEVELOPMENT_ENVIRONMENT variable is used to log extra data when running fabric in a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ internal class InteropUIBlockListener : UIManagerListener {
}

override fun willMountItems(uiManager: UIManager) {
if (beforeUIBlocks.isEmpty()) {
return
}
beforeUIBlocks.forEach {
if (uiManager is UIBlockViewResolver) {
it.execute(uiManager)
Expand All @@ -48,6 +51,9 @@ internal class InteropUIBlockListener : UIManagerListener {
}

override fun didMountItems(uiManager: UIManager) {
if (afterUIBlocks.isEmpty()) {
return
}
afterUIBlocks.forEach {
if (uiManager is UIBlockViewResolver) {
it.execute(uiManager)
Expand All @@ -56,9 +62,9 @@ internal class InteropUIBlockListener : UIManagerListener {
afterUIBlocks.clear()
}

override fun willDispatchViewUpdates(uiManager: UIManager) = Unit
override fun didDispatchMountItems(uiManager: UIManager) = didMountItems(uiManager)

override fun didDispatchMountItems(uiManager: UIManager) = Unit
override fun willDispatchViewUpdates(uiManager: UIManager) = willMountItems(uiManager)

override fun didScheduleMountItems(uiManager: UIManager) = Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ class InteropUiBlockListenerTest {
assertEquals(1, underTest.afterUIBlocks.size)
}

@Test
fun willDispatchViewUpdates_emptiesBeforeUIBlocks() {
val underTest = InteropUIBlockListener()
underTest.prependUIBlock {}
underTest.addUIBlock {}

underTest.willDispatchViewUpdates(FakeUIManager())

assertEquals(0, underTest.beforeUIBlocks.size)
assertEquals(1, underTest.afterUIBlocks.size)
}

@Test
fun didMountItems_emptiesAfterUIBlocks() {
val underTest = InteropUIBlockListener()
Expand All @@ -57,6 +69,18 @@ class InteropUiBlockListenerTest {
assertEquals(0, underTest.afterUIBlocks.size)
}

@Test
fun didDispatchMountItems_emptiesAfterUIBlocks() {
val underTest = InteropUIBlockListener()
underTest.prependUIBlock {}
underTest.addUIBlock {}

underTest.didDispatchMountItems(FakeUIManager())

assertEquals(1, underTest.beforeUIBlocks.size)
assertEquals(0, underTest.afterUIBlocks.size)
}

@Test
fun willMountItems_deliversUiManagerCorrectly() {
val fakeUIManager = FakeUIManager()
Expand All @@ -69,6 +93,18 @@ class InteropUiBlockListenerTest {
assertEquals(1, fakeUIManager.resolvedViewCount)
}

@Test
fun willDispatchViewUpdates_deliversUiManagerCorrectly() {
val fakeUIManager = FakeUIManager()
val underTest = InteropUIBlockListener()

underTest.prependUIBlock { uiManager -> uiManager.resolveView(0) }

underTest.willDispatchViewUpdates(fakeUIManager)

assertEquals(1, fakeUIManager.resolvedViewCount)
}

@Test
fun didMountItems_deliversUiManagerCorrectly() {
val fakeUIManager = FakeUIManager()
Expand All @@ -80,4 +116,16 @@ class InteropUiBlockListenerTest {

assertEquals(1, fakeUIManager.resolvedViewCount)
}

@Test
fun didDispatchMountItems_deliversUiManagerCorrectly() {
val fakeUIManager = FakeUIManager()
val underTest = InteropUIBlockListener()

underTest.addUIBlock { uiManager -> uiManager.resolveView(0) }

underTest.didDispatchMountItems(fakeUIManager)

assertEquals(1, fakeUIManager.resolvedViewCount)
}
}
Loading