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

Screens not visible when using Material Top Tab Navigator inside of FlatList.

Open jp-23 opened this issue 3 years ago • 22 comments
trafficstars

Current behavior

The tab screens are not visible - despite setting flex: 1.

Screen Shot 2022-02-17 at 12 18 22 AM
export default function TabsScreen() {
  return (
    <View style={{ flex: 1 }}>
      <Tab.Navigator>
        <Tab.Screen name="ScreenOne" component={ScreenOne} />
        <Tab.Screen name="ScreenTwo" component={ScreenTwo} />
      </Tab.Navigator>
    </View>
  );
}

It is not until I set a fixed height that the screen content appears:

Screen Shot 2022-02-17 at 12 20 10 AM
<View style={{ flex: 1, height: 100 }}>

Expected behavior

I expect the tab screens to be visible when using flex: 1. It is not acceptable to use a fixed height as I would like to include variable-height content in the tab screens - such as a FlatList. I also want to keep the parent-level FlatList - as I would like to utilize sticky headers. I've also tried using SectionList as the parent-level VirtualizedList, and I experience the same issue.

Here is the minimum structure:

|Stack Navigator |- Screen |-- FlatList |--- item 1 - component |--- item 2 - component |---- Material Top Tab Navigator |----- n-number of screens

Reproduction

https://snack.expo.dev/CCbZk7c0u

Platform

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

Packages

  • [ ] @react-navigation/bottom-tabs
  • [ ] @react-navigation/drawer
  • [ ] @react-navigation/material-bottom-tabs
  • [X] @react-navigation/material-top-tabs
  • [X] @react-navigation/stack
  • [ ] @react-navigation/native-stack

Environment

  • [] I've removed the packages that I don't use
package version
@react-navigation/native 6.0.8
@react-navigation/material-top-tabs 6.1.1
@react-navigation/stack 6.1.1
react-native-safe-area-context 3.3.2
react-native-screens 3.8.0
react-native-gesture-handler 1.10.2
react-native-tab-view 3.0.0
react-native-pager-view 5.4.6
react-native 0.63.4
node 15.8.0
npm or yarn yarn

jp-23 avatar Feb 17 '22 05:02 jp-23

Couldn't find version numbers for the following packages in the issue:

  • @react-navigation/bottom-tabs
  • @react-navigation/drawer
  • @react-navigation/material-bottom-tabs

Can you update the issue to include version numbers for those packages? The version numbers must match the format 1.2.3.

The versions mentioned in the issue for the following packages differ from the latest versions on npm:

  • @react-navigation/native (found: 6.0.6, latest: 6.0.8)
  • @react-navigation/material-top-tabs (found: 6.0.6, latest: 6.1.1)
  • @react-navigation/stack (found: 6.0.6, latest: 6.1.1)

Can you verify that the issue still exists after upgrading to the latest versions of these packages?

github-actions[bot] avatar Feb 17 '22 05:02 github-actions[bot]

Couldn't find version numbers for the following packages in the issue:

  • @react-navigation/bottom-tabs
  • @react-navigation/drawer
  • @react-navigation/material-bottom-tabs

Can you update the issue to include version numbers for those packages? The version numbers must match the format 1.2.3.

github-actions[bot] avatar Feb 17 '22 05:02 github-actions[bot]

The issue still exists after upgrading to the latest versions of the mentioned packages.

jp-23 avatar Feb 17 '22 15:02 jp-23

any update on this one?

KFrysztak avatar Mar 03 '22 19:03 KFrysztak

I have a screen with nested tabs that has the tabs in the middle of the page with the whole thing scrollable. Wrapping tabs inside a scrollview has the same effect, the tab page does not show unless the height is explicitly set.

This isn't a full solution but here's what I did.

create a state for the height

const [tabPageHeight, setTabPageHeight] = useState(0)

set the style to use the state

const styles = StyleSheet.create({
 tabsContainer:{
  minHeight: '100%',
  height: tabPageHeight,
 }
})

Then in the view of the tab page component, use onLayout

const tabPageScreen1 = () => {
   return (
      <View onLayout={updateTabHeight}>
      // some content
      </View>
  )
}

The onLayout event to set the height

const updateTabHeight = (event) => {
  const { height } = event.nativeEvent.layout;
  if(tabPageHeight === 0){
    setTabPageHeight(height);
  }
}

You may also want to set the TabNavigator to lazy to help with dynamic content, only loading the tab page when viewed.

<Tab.Navigator
  screenOptions={{
    lazy:true,
  }}>
  <Tab.Screen name="Tab 1" component={tabPageScreen1}/>
</Tab.Navigator>

Some pitfalls All the pages are the same height as the first. Might be able to to separate css styles for each tab page.

event.nativeEvent.layout height seems inconsistent on each device. Will have height perfect on Web, but iOS and Android cut off at the bottom. Might be able to detect the OS, then add extra height for each platform as necessary. ex setTabPageHeight(height + iOSOffset);

This seems like a hacky work around, it would be much easier if there was a way to tell the screen to fit-content

still experimenting with this.

kennethstarkrl avatar Mar 21 '22 15:03 kennethstarkrl

@kennethstarkrl did you came up with a different solution? I just stumbled across that very same problem and cant imagine that this is really the solution for this problem :-/... feels really hacky

RRaideRR avatar Apr 13 '22 14:04 RRaideRR

@kennethstarkrl did you came up with a different solution? I just stumbled across that very same problem and cant imagine that this is really the solution for this problem :-/... feels really hacky

I have not yet and yes totally agree its not a solution but a work-around.

kennethstarkrl avatar Apr 21 '22 20:04 kennethstarkrl

Hello, did anyone figure this out?

jeffngugi avatar Apr 25 '22 09:04 jeffngugi

Any update on this? Please do let know if there is any solution for the same.

awesome31 avatar May 13 '22 13:05 awesome31

Still stuck on this issue. Any update?

mustafaasif1 avatar May 24 '22 10:05 mustafaasif1

any updates on this ? fixing the height don't seem like a good solution, i tried with flexGrow and flex and sometimes it works and sometimes no

ahmed-khlifi avatar May 24 '22 15:05 ahmed-khlifi

Currently encountering this issue as well, but with ScrollView instead of Flatlist. I've created a reproduction:

Non-working (height not set): https://snack.expo.dev/@harrisr/funny-chip Working (height explicitly set): https://snack.expo.dev/@harrisr/quiet-sandwich

This issue occurs on ios and android.

Setting the height programmatically feels not-great, and I'd much prefer it if material-top-tabs properly calculated it's height based on children content.

DeveloperHarris avatar Jun 01 '22 00:06 DeveloperHarris

Dug into the code a bit. This seems to be related to an issue with react-native-tab-view, which is used by the material top tabs navigator.

There's an open issue their repo:

https://github.com/satya164/react-native-tab-view/issues/1349

DeveloperHarris avatar Jun 01 '22 02:06 DeveloperHarris

I think the solution is to add fixed height to Tab.Navigator, I propose to use minHeight so tab screen will be growing with the contents on it.

But the problem is that, all the screens in tabs inherits height from the first screen tab 🤔

danielaloycedaniel avatar Nov 15 '22 12:11 danielaloycedaniel

This is an issue with react-native-tab-view that was introduced in release 3.0.0. Here's issues related to it:

There doesn't seem to be a solution to it - although it seems like a very common use-case to want a tabview inside of a scroll view (Facebook, Instagram, etc.)

Would be greatly appreciated if this could be fixed - especially now that the package is housed under react-navigation.

alexdobson avatar Dec 01 '22 15:12 alexdobson

Bug still present, any solution?

aminta avatar Jan 16 '23 18:01 aminta

Would be greatly appreciated if this could be fixed. Who knows if there are any plans for it?

Dajust avatar Jan 26 '23 07:01 Dajust

I moved to this awesome library: https://github.com/PedroBern/react-native-collapsible-tab-view

If you don't need to stick implement tab on react-navigation way, I recommend react-native-collapsible-tab-view.

acro5piano avatar Jan 31 '23 15:01 acro5piano

Any one found a fix yet bug still here?

Judono avatar Feb 21 '23 11:02 Judono

just found a fix, it turns out that the bug is with react-native-pager-view v5.4.23 and to solve you need to upgrade to react-native-pager-view v2.4.25, you can fix with this command

yarn add react-native-pager-view@5

credits to @vlkpa for finding the solution here -> https://github.com/satya164/react-native-tab-view/issues/1178#issuecomment-1319737961

hope this helps

Judono avatar Feb 21 '23 13:02 Judono

This issue is a pain. I ve been more than 3 years trying to get this without tricky solutions.

victoriomolina avatar Aug 10 '23 08:08 victoriomolina

I don't know how people are still downloading this library with this issue

YASH6004 avatar Jan 22 '24 07:01 YASH6004