Skip to content

Commit

Permalink
RN changes to enable fragment-based navigation [1/3] (#43789)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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
  • Loading branch information
janeli-100005636499545 authored and facebook-github-bot committed Apr 3, 2024
1 parent d855974 commit 79e5e64
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public void getReactDelegate() {
mDelegate.getReactDelegate();
}

public ReactActivityDelegate getReactActivityDelegate() {
return mDelegate;
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class ReactFragment extends Fragment implements PermissionAwareActivity {

protected ReactDelegate mReactDelegate;

protected boolean shouldCallDelegateLifecycleEvents = true;

@Nullable private PermissionListener mPermissionListener;

public ReactFragment() {
Expand Down Expand Up @@ -99,19 +101,25 @@ public View onCreateView(
@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
Expand Down

0 comments on commit 79e5e64

Please sign in to comment.