react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[android][bugfix] Move destroyed callback to onDestroyView()

Open DanielGrech opened this issue 3 years ago • 3 comments

Summary

Currently, when navigating back to a ReactFragment instance that is on the fragment backstack, we trigger an IllegalStateException from within ReactDelegate.loadApp():

"Cannot loadApp while app is already running."

ReactFragment calls ReactDelegate#loadApp() from onCreateView() ReactFragment calls ReactDelegate#onHostDestroyed() from onDestroy()

This is a mismatch - onCreateView() can be called multiple times before onDestroy() is called.

For example, consider the case where:

  • The ReactFragment is shown on screen. onCreateView() is called.
  • The fragment is replaced (with a FragmentTransaction#replace() call) and added to the fragment backstack. ReactFragment#onDestroyView() is called
  • The user navigates back. ReactFragment#onCreateView() will be called again.

onDestroyView() here is the lifecycle method that matches onCreateView(), so it's more appropriate to do this teardown here, given the setup is done in onCreateView()

Changelog

[Android] [Fixed] - Fix crash when navigating back to a ReactFragment in the backstack

Test Plan

  • Open ReactFragment instance
  • Replace original ReactFragment using fragmentTransaction.replace().addToBackStack()
  • Press system back button
  • Observe no more crash

DanielGrech avatar Sep 07 '22 22:09 DanielGrech

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,638,534 +0
android hermes armeabi-v7a 7,050,858 +0
android hermes x86 7,940,286 +0
android hermes x86_64 7,912,304 +0
android jsc arm64-v8a 9,512,236 +0
android jsc armeabi-v7a 8,287,856 +0
android jsc x86 9,451,567 +0
android jsc x86_64 10,042,631 +0

Base commit: b6bf1fd373c7bfe1e96d82458a1e7de6c5897af7 Branch: main

analysis-bot avatar Sep 07 '22 22:09 analysis-bot

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: b6bf1fd373c7bfe1e96d82458a1e7de6c5897af7 Branch: main

analysis-bot avatar Sep 07 '22 23:09 analysis-bot

This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Mar 07 '23 00:03 github-actions[bot]

This PR was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar Mar 16 '23 06:03 github-actions[bot]