f111fei / react-native-banner-carousel

a carousel component for React Native
103 stars 47 forks source link

Not able to load images from API(asynchronous) #2

Closed keatwei closed 6 years ago

keatwei commented 6 years ago

Hi I'm currently having problem loading images from API, here is my StackOverflow. https://stackoverflow.com/questions/48009345/how-to-make-react-native-banner-carousel-load-images-from-apiasynchronous

Any suggestion on the asynchronous issue?

f111fei commented 6 years ago

Sorry, so late to response. Here is my suggestion.

render(){
    const images = this.props.carousels;
    if (!images || images.length === 0) {
        return null;
    }

    return(
        ......
        <Carousel
            autoplay
            autoplayTimeout={5000}
            loop
            index={0}
            showsPageIndicator={ false }
            pageSize={BannerWidth}
        >
        { images.map((image, index) => this.renderPage(image, index))}
        </Carousel>
        ......
    );
}

Don't render carousel when the image list length is 0.

keatwei commented 6 years ago

@f111fei yup. its working. thx

shivamtiwari8736 commented 5 years ago

Hi @keatwei , Can you help me in passing JSON of array consisting of Objects as datasource. Please have a look at the issue opened by me: How to pass JSON of Images as Data Source?