react-native-tab-view icon indicating copy to clipboard operation
react-native-tab-view copied to clipboard

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

Open yasodha-r opened this issue 3 years ago • 15 comments

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

  • [X] Android
  • [X] 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

yasodha-r avatar Oct 08 '21 07:10 yasodha-r

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?

github-actions[bot] avatar Oct 08 '21 07:10 github-actions[bot]

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

  • [x] Android
  • [x] 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

TeyimPila avatar Oct 09 '21 12:10 TeyimPila

@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

yasodha-r avatar Oct 11 '21 13:10 yasodha-r

@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

TeyimPila avatar Oct 11 '21 13:10 TeyimPila

@TeyimPila Thanks, man. This works like magic

timi-codes avatar Oct 11 '21 21:10 timi-codes

thanks @TeyimPila

TheSalarKhan avatar Oct 23 '21 21:10 TheSalarKhan

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

#1178 #1198 #1237

jamesisaac avatar Dec 23 '21 13:12 jamesisaac

any updates on this?

sergey-king avatar Jan 07 '22 16:01 sergey-king

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.

leethree avatar Jan 10 '22 13:01 leethree

Any update?

vargajacint avatar Mar 08 '22 20:03 vargajacint

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

hope useful to you!

thuantvDr4 avatar Mar 22 '22 03:03 thuantvDr4

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} />

Deepa-Palani avatar Mar 30 '22 10:03 Deepa-Palani

Any update?

sergey-king avatar Jun 09 '22 23:06 sergey-king

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

IzaELK avatar Jun 23 '22 09:06 IzaELK

@IzaELK Please, have you found a solution to this

iamemmanuel-dev avatar Jul 26 '22 17:07 iamemmanuel-dev

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

leethree avatar Aug 16 '22 11:08 leethree

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 :)

Gguigre avatar Aug 26 '22 10:08 Gguigre

@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 https://github.com/callstack/react-native-pager-view/commit/d22414e06c56b9c707c61f86270881185584f44e#diff-fed4d75f8ae11fb98e76134b44730daee2a90bb6ed422d0ad418755853542d40). Now it works as a temporary workaround.

leethree avatar Aug 26 '22 12:08 leethree

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

patrickschmelter avatar Aug 26 '22 17:08 patrickschmelter

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

okwasniewski avatar Sep 01 '22 11:09 okwasniewski

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

devunt avatar Nov 01 '22 01:11 devunt

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

ThukuWakogi avatar Nov 12 '22 08:11 ThukuWakogi

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

vlkpa avatar Nov 18 '22 08:11 vlkpa