Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ public class ReactHostImpl(
* Native is reloading, it seems reasonable to assume that: (1) We must have navigated to a
* React Native screen in the past, or (2) We must be on a React Native screen.
*/
if (isReloading && !isManagerResumed) {
if (isReloading && !isManagerResumed && currentActivity != null) {
reactLifecycleStateManager.moveToOnHostResume(reactContext, currentActivity)
} else {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,38 @@ class ReactHostTest {
reactHost.onHostDestroy(activityController.get())
assertThat(reactHost.lifecycleState).isEqualTo(LifecycleState.BEFORE_CREATE)
}

@Test
fun testActivityDestroyedDuringReload() {
val bgTasks = ArrayDeque<Runnable>()
reactHost =
spy(
ReactHostImpl(
activityController.get().application,
reactHostDelegate,
mock(),
{ bgTasks.add(it) },
Task.IMMEDIATE_EXECUTOR,
false /* allowPackagerServerAccess */,
false /* useDevSupport */,
),
)
doReturn(null).whenever(reactHost).getOrCreateReactHostInspectorTarget()
doNothing().whenever(reactHost).unregisterInstanceFromInspector(any())

reactHost.start()
while (bgTasks.isNotEmpty()) bgTasks.removeFirst().run()
reactHost.onHostResume(activityController.get())

reactHost.reload("Reload from testing infra")
reactHost.onHostPause(activityController.get())
reactHost.onHostDestroy(activityController.get())
while (bgTasks.isNotEmpty()) bgTasks.removeFirst().run()
assertThat(reactHost.lifecycleState).isEqualTo(LifecycleState.BEFORE_CREATE)

val newActivity = Robolectric.buildActivity(Activity::class.java).create().start().resume()
reactHost.onHostResume(newActivity.get())
val newReactContext = mockedBridgelessReactContextCtor.constructed().last()
verify(newReactContext).onHostResume(newActivity.get())
}
}
Loading