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

I find why this component cannot be nested

Open zjhsd2007 opened this issue 10 years ago • 14 comments

the reason is ViewPagerAndroid!!! see this test code:

'use strict';
import React,{
    Component,
    View,
    Text,
    ViewPagerAndroid
} from 'react-native';

export default class TestCpt extends Component {
    constructor(props){
        super(props);
    }
    render(){
        return (
            <ViewPagerAndroid
                initialPage={1}
                style={{flex:1}}
            >
                <View>
                    <ViewPagerAndroid
                        initialPage={1}
                        style={{flex:1}}
                    >
                        <View><Text>page1-1</Text></View>
                        <View><Text>page1-2</Text></View>
                        <View><Text>page1-3</Text></View>
                    </ViewPagerAndroid>
                </View>
                <View>
                    <ViewPagerAndroid
                        style={{flex:1}}
                    >
                        <View><Text>page2-1</Text></View>
                        <View><Text>page2-2</Text></View>
                        <View><Text>page2-3</Text></View>
                    </ViewPagerAndroid>
                </View>
                <View>
                    <ViewPagerAndroid
                        style={{flex:1}}
                    >
                        <View><Text>page3-1</Text></View>
                        <View><Text>page3-2</Text></View>
                        <View><Text>page3-3</Text></View>
                    </ViewPagerAndroid>
                </View>
            </ViewPagerAndroid>
        )
    }
}

In this test, the inital page(page2-1) can not display,need rota device. the react-native-scrollable-tab-view can not nested is this reason

zjhsd2007 avatar Mar 28 '16 02:03 zjhsd2007

There are few issues for that like #187.

skv-headless avatar Mar 29 '16 20:03 skv-headless

So, is there no workaround this issue? Using ScrollableTabView inside a View?

GelaniNijraj avatar Apr 15 '16 09:04 GelaniNijraj

same issue, can anybody help?

happyming9527 avatar Apr 23 '16 13:04 happyming9527

A lot of people asking about this. I'm just curious how your ui looks like?

skv-headless avatar May 03 '16 12:05 skv-headless

My UI consists of one primary TabBar and each tab has an optional secondary TabBar. That's simply a nested tab navigation. This mostly works out of the box, but the initial tab's scrollable content (either on app start or after changing to another primary tab) is not displayed until the user switches to another secondary tab and back to this one. For the last days I tried to come up with something, but the best I could do by now is a hack, which quickly switches to the (secondary) tab -1 and back, which loads the scrollable content properly:

componentDidMount() {
    if (!this.primaryTabView) {
      this.goToPage(-1);
      setTimeout(() => this.goToPage(0), 0);
    }
},

I think I'm going to work with this. If you are interested in such a hacky PR, which optionally enables this hack, i'll prepare one :)

maikokuppe avatar May 04 '16 07:05 maikokuppe

Could please make a screenshot? It will help me a lot.

skv-headless avatar May 04 '16 07:05 skv-headless

Now it is like this after starting the app or after switching to primary tab 'Custom' screenshot2 resized

After the hack it looks like this screenshot1 resized

Edit: My secondary tabs look weird because i made them scrollable. But thats not the cause of the issue (I tested it with default tabs)

maikokuppe avatar May 04 '16 07:05 maikokuppe

same problem. can you resolve it, @skv-headless ?

btconfig avatar May 24 '16 15:05 btconfig

https://material.google.com/components/tabs.html#tabs-usage quote from there Tabs should not be nested.

skv-headless avatar Jun 20 '16 07:06 skv-headless

Well, that seems to be a list of conventions for material design, which is probably wide-spread. Still, there might be cases where material design is not desired/necessary. I think this is a reason for allowing nested tabs, though it is understandable if you are not willing to put your time in a feature not matching general conventions, while there are probably many other (maybe more important) issues to handle.

PS: We intentionally break the material design conventions

maikokuppe avatar Jun 20 '16 10:06 maikokuppe

seems to solved working for me screen shot 2016-09-09 at 2 56 46 pm

chromonav avatar Sep 09 '16 09:09 chromonav

@maikokuppe same issue as you as a nested tab not initialised, after see this discuss, i try not to have nested tabs through placing a button on top to change state then update the tab list below, but seems same issue of cannot initialised after i update the existing tab.....so could you tell me more about this hack... the this.goToPage(-1) should be put to which part...Thx

update: Seems adding a reference to the tab view then the hack works.Thx

summersky92 avatar Oct 12 '16 03:10 summersky92

@maikokuppe is right, but in last version the code should be

      this.props.goToPage(-1);
      setTimeout(() => this.props.goToPage(0), 0);

mataoct avatar Oct 27 '16 08:10 mataoct

@maikokuppe how have you defined goToPage? I'm have the problem with the first view not being rendered.

aljux avatar Nov 02 '16 08:11 aljux