software-mansion / react-native-screens

Native navigation primitives for your React Native app.
https://docs.swmansion.com/react-native-screens/
MIT License
3.01k stars 511 forks source link

[Android] Tab Screens use fragment transactions instead of ViewPager #1548

Open eamon-mallon opened 2 years ago

eamon-mallon commented 2 years ago

Description

In Android projects, using the Tab Screens navigation causes fragments to be removed and added every time a user navigates. This causes the fragment to be recreated each time it is navigated to. This can be seen in the gif provided below showing that the document view is recreated each time it is navigated to by the user.

After debugging the project I noticed that ScreenContainer.kt in react-native-screens uses fragment transactions and removes the fragment each time a navigation event is called. Is it possible prevent the fragment from being removed every time we navigate or is there a view pager implementation with a bottom bar navigation for Tab Screens ?

Screenshots

Steps To Reproduce

  1. Open an app using tab screens
  2. Navigate between fragments Result: fragments are created each time the user navigates

Expected behavior

Fragments should not be recreated every time they are navigated to, the navigation should preform like a view pager

Actual behavior

Fragments are recreated every time the user navigates

Reproduction

See STR section, this happens on all projects using Tab Screen

    <NavigationContainer>
      <Tab.Navigator>
        <Tab.Screen name="Home" component={HomeScreen}/>
        <Tab.Screen name="Document" component={DocumentScreen}/>
      </Tab.Navigator>
    </NavigationContainer>

Platform

Package versions

package version
react-native 0.65.2
@react-navigation/native ^6.0.10
react-native-screens ^3.13.1
github-actions[bot] commented 2 years ago

Hey! 👋

The issue doesn't seem to contain a minimal reproduction.

Could you provide a snippet of code, a snack or a link to a GitHub repository that reproduces the problem?

brandenfung2 commented 1 year ago

Any update on this issue?