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

[Android] Tab Screens use fragment transactions instead of ViewPager

Open eamon-mallon opened this issue 1 year ago • 2 comments

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

  • [ ] iOS
  • [X] Android
  • [ ] Web
  • [ ] Windows
  • [ ] tvOS

Package versions

package version
react-native 0.65.2
@react-navigation/native ^6.0.10
react-native-screens ^3.13.1

eamon-mallon avatar Jul 28 '22 00:07 eamon-mallon

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?

github-actions[bot] avatar Jul 28 '22 00:07 github-actions[bot]

Any update on this issue?

brandenfung2 avatar Oct 04 '22 17:10 brandenfung2