zbtang / React-Native-ViewPager

ViewPager and Indicator component for react-native on both android and ios.
950 stars 276 forks source link

How to load the page only when user selects the tab ? #163

Open infaz opened 5 years ago

infaz commented 5 years ago

How to load the page only when user selects the tab. Currently, It loads all the views initially. I want to load each view when user select each tab.

shivamtiwari8736 commented 5 years ago

Hi @infaz have you find any the solution for this. I am also going through the same problem.

r0b0t3d commented 5 years ago

You can create a placeholder view first. Then observe for current page changed then init the component yourself.

<IndicatorViewPager
    onPageSelected={params => {
        setCurrentPage(params.position);
    }}
>
                <View style={{ width }}>
                    <YourFirstPage />
                </View>
                <View style={{ width }}>
                    {isSecondPageInitialized && <YourSecondPage />}
                </View>
</IndicatorViewPager>
shivamtiwari8736 commented 5 years ago

Ok thanks. I will try this.