RN changes to enable fragment-based navigation [1/3] (#43789)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43789

This diff introduces some changes to React Native needed to enable fragment-based navigation (see next diff for usage).

Fragment-based navigation will enable us to, instead of re-creating the entire main activity on navigation, create a fragment instead - allowing us to bypass a lot of unnecessary onCreate() logic in our main activity to improve user experience and performance.

Changelog:
[Internal] [Changed] - Add option to skip calling delegate on ReactFragment lifecycle events

Reviewed By: keoskate

Differential Revision: D55646221

fbshipit-source-id: 45b148cb9ecdb1484f1ac714ac2b93ce09c52237
This commit is contained in:
Jane Li
2024-04-03 08:18:46 -07:00
committed by Facebook GitHub Bot
parent d855974dae
commit 79e5e64b9a
3 changed files with 17 additions and 3 deletions
@@ -92,6 +92,7 @@ public abstract class com/facebook/react/ReactActivity : androidx/appcompat/app/
protected fun <init> ()V
protected fun createReactActivityDelegate ()Lcom/facebook/react/ReactActivityDelegate;
protected fun getMainComponentName ()Ljava/lang/String;
public fun getReactActivityDelegate ()Lcom/facebook/react/ReactActivityDelegate;
public fun getReactDelegate ()V
protected final fun getReactInstanceManager ()Lcom/facebook/react/ReactInstanceManager;
protected final fun getReactNativeHost ()Lcom/facebook/react/ReactNativeHost;
@@ -178,6 +179,7 @@ public class com/facebook/react/ReactFragment : androidx/fragment/app/Fragment,
protected static final field ARG_FABRIC_ENABLED Ljava/lang/String;
protected static final field ARG_LAUNCH_OPTIONS Ljava/lang/String;
protected field mReactDelegate Lcom/facebook/react/ReactDelegate;
protected field shouldCallDelegateLifecycleEvents Z
public fun <init> ()V
public fun checkPermission (Ljava/lang/String;II)I
public fun checkSelfPermission (Ljava/lang/String;)I
@@ -69,6 +69,10 @@ public abstract class ReactActivity extends AppCompatActivity
mDelegate.getReactDelegate();
}
public ReactActivityDelegate getReactActivityDelegate() {
return mDelegate;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
@@ -32,6 +32,8 @@ public class ReactFragment extends Fragment implements PermissionAwareActivity {
protected ReactDelegate mReactDelegate;
protected boolean shouldCallDelegateLifecycleEvents = true;
@Nullable private PermissionListener mPermissionListener;
public ReactFragment() {
@@ -99,19 +101,25 @@ public class ReactFragment extends Fragment implements PermissionAwareActivity {
@Override
public void onResume() {
super.onResume();
mReactDelegate.onHostResume();
if (shouldCallDelegateLifecycleEvents) {
mReactDelegate.onHostResume();
}
}
@Override
public void onPause() {
super.onPause();
mReactDelegate.onHostPause();
if (shouldCallDelegateLifecycleEvents) {
mReactDelegate.onHostPause();
}
}
@Override
public void onDestroy() {
super.onDestroy();
mReactDelegate.onHostDestroy();
if (shouldCallDelegateLifecycleEvents) {
mReactDelegate.onHostDestroy();
}
}
// endregion