Skip to content
This repository has been archived by the owner on Nov 27, 2022. It is now read-only.

Embedding react-native-tab-view in scrollview is not working #1274

Closed
2 of 5 tasks
yasodha-r opened this issue Oct 8, 2021 · 23 comments
Closed
2 of 5 tasks

Embedding react-native-tab-view in scrollview is not working #1274

yasodha-r opened this issue Oct 8, 2021 · 23 comments

Comments

@yasodha-r
Copy link

Current behavior

It perfectly works fine with non scrollable views. But when it is wrapped inside Scrollview, tabview route contents disappearing. But it is already mentioned in Readme as - 'Avoid rendering TabView inside ScrollView' and 'So avoid doing it if possible'. My question is it possible to wrap it in Scrollview like this,

<ScrollView style={styles.scrollView}> <View style={{flex: 1}}> <TabView renderTabBar={renderTabBar} navigationState={{index, routes}} renderScene={renderScene} onIndexChange={setIndex} initialLayout={initialLayout}/> </View> </ScrollView>

Expected behavior

To be able to run inside Scrollview

Reproduction

https://snack.expo.dev/kv0RZ0qCK

Platform

  • Android
  • iOS
  • Web
  • Windows
  • MacOS

Environment

package version
react-native-tab-view 3.1.1
react-native-pager-view 5.4.6
react-native 0.64.2
expo NA
node v12.22.1
npm or yarn 7.19.1
@github-actions
Copy link

github-actions bot commented Oct 8, 2021

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

  • expo

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-native (found: 0.64.2, latest: 0.66.0)

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

@TeyimPila
Copy link

Current behavior

It perfectly works fine with non scrollable views. But when it is wrapped inside Scrollview, tabview route contents disappearing. But it is already mentioned in Readme as - 'Avoid rendering TabView inside ScrollView' and 'So avoid doing it if possible'. My question is it possible to wrap it in Scrollview like this,

<ScrollView style={styles.scrollView}> <View style={{flex: 1}}> <TabView renderTabBar={renderTabBar} navigationState={{index, routes}} renderScene={renderScene} onIndexChange={setIndex} initialLayout={initialLayout}/> </View> </ScrollView>

Expected behavior

To be able to run inside Scrollview

Reproduction

https://snack.expo.dev/kv0RZ0qCK

Platform

  • Android
  • iOS
  • Web
  • Windows
  • MacOS

Environment

package version
react-native-tab-view 3.1.1
react-native-pager-view 5.4.6
react-native 0.64.2
expo NA
node v12.22.1
npm or yarn 7.19.1

Trying to get this to work has consumed my entire day. Please, let me know if anyone finds a solution to this. I am now considering react-native-collapsible-tab-view which seems to work in scrollview but it is not as popular as this

@yasodha-r
Copy link
Author

@TeyimPila Thanks for the response. But react-native-collapsible-tab-view animations are not smooth as this. Another option could be react-native-scrollable-tab-view

@TeyimPila
Copy link

TeyimPila commented Oct 11, 2021

@TeyimPila Thanks for the response. But react-native-collapsible-tab-view animations are not smooth as this. Another option could be react-native-scrollable-tab-view

I was able to find a hack for this. I achieved it by giving the TabView style prop a height. The problem with this is that the hight is fixed and thus not suitable for variable-length content

@timi-codes
Copy link

@TeyimPila Thanks, man. This works like magic

@TheSalarKhan
Copy link

thanks @TeyimPila

@jamesisaac
Copy link

Related issues and PRs (aiming to fix the variable-length content use case):

#1178
#1198
#1237

@sergey-king
Copy link

any updates on this?

@leethree
Copy link

we have dynamic content inside the tabs. it was working in v2. but the height shrinks to 0 with v3.

would greatly appreciate any workaround that allows for variable-height content.

@vargajacint
Copy link

Any update?

@thuantvDr4
Copy link

change style ={{flex:1}} inside scrollview to contentContainerStyle={{flex:1}}

hope useful to you!

@Deepa-Palani
Copy link

If anyone want to make a tabview with scrollview when there is more than three tabs please enable scroll in tabbar.it made my tabview scrollable.i have followed below code
<TabBar
{...props}
scrollEnabled
indicatorStyle={styles.indicator}
style={styles.tabbar}
tabStyle={styles.tab}
labelStyle={styles.label}
/>

@sergey-king
Copy link

Any update?

@IzaELK
Copy link

IzaELK commented Jun 23, 2022

Hello,
I have the same issue. I want to have my tab bar and tab view in a scrollView. I have a component above my tab view.
You can see what I want to achieve in the following diagram.
I cannot fix the height of my scrollView because my content's length is variable.
Do you have any updates or fixes?
goal_diagram

@iamemmanuel-dev
Copy link

@IzaELK Please, have you found a solution to this

@leethree
Copy link

@turhansel the issue is about having TabView inside ScrollView. not the other way around.

@Gguigre
Copy link

Gguigre commented Aug 26, 2022

On our side we decided to use patch-package to apply those changes until they are validated/merged.
https://github.com/satya164/react-native-tab-view/pull/1237/files

For us it works like a charm. We had the same usecase as @IzaELK :)

@leethree
Copy link

@Gguigre I applied the patch and found that we also needed to revert a recent react-native-pager-view change of childrenWithOverriddenStyle (by removing the additional layer of View. see callstack/react-native-pager-view@d22414e#diff-fed4d75f8ae11fb98e76134b44730daee2a90bb6ed422d0ad418755853542d40). Now it works as a temporary workaround.

@patrickschmelter
Copy link

I can't seem to get it working using above pull request. I use the tab view inside a screen of react-navigation/native which forces me to use a { flex: 1 } on the contentContainerStyle of the ScrollView

@okwasniewski
Copy link
Collaborator

Closing as it is a duplicate of #1349 which is resolved.

@devunt
Copy link

devunt commented Nov 1, 2022

It is not resolved yet, the same as #1349.

@ThukuWakogi
Copy link

After days of trying to find a solution, I decided to settle with react-native-collapsible-tab-view.

@vlkpa
Copy link

vlkpa commented Nov 18, 2022

Migrating react-navigation and updating react-native-tab-view from 2.16.0 to 3.3.0 causes this problem.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests