React-native-swiper: [Android] impossible to render list of elements

Created on 16 Aug 2017  ·  4Comments  ·  Source: leecade/react-native-swiper

Which OS ?

android

Version

Which versions are you using:

  • react-native-swiper v1.5.4
  • react-native v0.44

Expected behaviour

should display all the tabs

Actual behaviour

display only first tab

More:
When I display basic example, everything works fine. However when I try to use map over array to render simple view with text, it renders only first page, other pages of swiper are blank.

Most helpful comment

For me the solution was checking if an array is not empty before rendering. Data that I wanted iterate over was fetched asynchronously. At first render it was not fully fetched so the error with swiper occurred. The code that actually works:

render () {
    return (
        {data && data.length !== 0 &&
            <Swiper
                ref={this.setSwiperInstance}
                loop={false}
                height={this.state.height}
                removeClippedSubviews={false}
                showsPagination={false}
                onMomentumScrollEnd={this.onSlideEndHandler}
            >
                {
                    data.map((item, index) =>
                        <View>
                            <Text>{index}</Text>
                        </View>,
                    )
                }
            </Swiper>
        }
    )
}

All 4 comments

same complication bro.

same complication bro.

For me the solution was checking if an array is not empty before rendering. Data that I wanted iterate over was fetched asynchronously. At first render it was not fully fetched so the error with swiper occurred. The code that actually works:

render () {
    return (
        {data && data.length !== 0 &&
            <Swiper
                ref={this.setSwiperInstance}
                loop={false}
                height={this.state.height}
                removeClippedSubviews={false}
                showsPagination={false}
                onMomentumScrollEnd={this.onSlideEndHandler}
            >
                {
                    data.map((item, index) =>
                        <View>
                            <Text>{index}</Text>
                        </View>,
                    )
                }
            </Swiper>
        }
    )
}

You have to check data before rendering!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ruben-kasaz picture ruben-kasaz  ·  3Comments

tibic picture tibic  ·  3Comments

nomoreboredom picture nomoreboredom  ·  3Comments

kliuj picture kliuj  ·  3Comments

itinance picture itinance  ·  3Comments