zbtang/React-Native-ViewPager

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

infaz opened this issue · 3 comments

infaz commented

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.

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

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>

Ok thanks. I will try this.