leecade / react-native-swiper

The best Swiper component for React Native.
MIT License
10.42k stars 2.34k forks source link

swiper image not showing #609

Open callmejm opened 7 years ago

callmejm commented 7 years ago

Swiper image not showing, only can see the dot changing the position. Saw this https://github.com/leecade/react-native-swiper/issues/416 but i added removeClippedSubviews={false} also have same issue. Every time i have to delete <swiper/> and save and reload and paste back it only show up. I try to export as apk also have same issue. Any idea to fix this ?

  <View style={styles.container}>
    <ScrollView>
      <Swiper height={Dimensions.get('window').width / 1.3} showsButtons={false} removeClippedSubviews={false} autoplay={true} autoplayTimeout={3} autoplayDirection={true}
        dot={<Swiperdot/>} activeDot={<Swiperactivedot/>} paginationStyle={{bottom: 10}}>
        <SwiperImgItem pathuri={this.state.path1}/>
        <SwiperImgItem pathuri={this.state.path2}/>
        <SwiperImgItem pathuri={this.state.path3}/>
      </Swiper>
    </ScrollView>
  </View>

const styles = StyleSheet.create({
   container: {
    flex: 1,
    backgroundColor:'#000000'
  },
});
arribbar commented 7 years ago

is it only for android or also for iOS ?

cyperus commented 7 years ago

Same issue. Mine is only for android

koansang commented 7 years ago

+1, only Android

callmejm commented 7 years ago

@arribbar @cyperus @koansang guys, I have solution, I try using setTimeout to delay some time for swiper render. This worked for me, hope u guys also.

constructor(props) {
  super(props);

  this.state = { 
    startswiper:false,
  };
}

componentWillMount(){
  setTimeout(() => {this.setState({startswiper:true})}, 500);
}

_renderSwiper(){
  return(
    <Swiper height={300} showsButtons={false} removeClippedSubviews={false} autoplay={true} autoplayTimeout={3} autoplayDirection={true}
      dot={<Swiperdot/>} activeDot={<Swiperactivedot/>} paginationStyle={{bottom: 10}}>
      <SwiperImgItem />
      <SwiperImgItem />
      <SwiperImgItem />
    </Swiper>
  );
}

render() {
  const { navigate } = this.props.navigation;
  return(
    <View style={styles.container}>
        {
         this.state.startswiper === true ?
         this._renderSwiper()
         : null
        }
    </View>
  );
}
wu928320442 commented 7 years ago

@JayricMok Using your solution, I can run normally on Android, IOS No.

arribbar commented 7 years ago

It worked for me changing width from 99% to 100%, for both iOS and Android

    constructor(props) {
      super(props);

      this.state = {
        width: '99%',
      };
    }

    componentWillMount() {
        setTimeout(() => {
            this.setState({
                width: '100%'
            });
        }, 500);
    }

    render() {
        console.log(' about to render swiper');
        const slides = this.props.dataList.map(this.renderView.bind(this));
        return (
            <Swiper
                width={this.state.width}
                dotColor={LIGHT_GREY_3}
                activeDotColor={YELLOW}
                containerStyle={this.props.style}
                style={styles.scrollStyle}
            >
                { slides }
            </Swiper>
        );
    }
tonygentilcore commented 7 years ago

+1, same issue here. It only repros in Android, iOS works fine for me. Sometimes the contents render, sometimes they don't. When they don't render, the inspector show that the children of Swiper are empty.

tonygentilcore commented 7 years ago

This is a sad, sad hack, but adding this to a parent of Swiper fixes the issue for me:

  componentDidMount() {
    this.forceUpdate()
  }

Hopefully this gives a clue as to the proper solution, I really can't find a library I'd like to use as an alternative to this.

Update: The above hack made it happen less frequently, but it was still flaky at a lower rate. So I ended up switching to https://github.com/archriss/react-native-snap-carousel (which works great).

adamnator92 commented 7 years ago

+1, images didnt show on android device

dylancom commented 7 years ago

+1, same here. A lot of times the images won't shop up in Android.

jordyvanraaij commented 7 years ago

I'm experiencing this issue on Android as well. Sometimes the images won't show at all and sometimes it only renders the first 3 images (loadMinimalSize = 2). I these cases the pagination doesn't update properly either.. Can we give this problem some priority as a lot of people seem to have issues on Android devices?

PerspectivesLab commented 7 years ago

having the same here on android with all latest versions, needed the trick of @arribbar , but it shows double slides now ...

cotra commented 7 years ago

same too

legend27sg commented 6 years ago

same problem i facing now

teh-obeng commented 6 years ago

@JayricMok's solution fixed my problem In my case, you also need to set height property for Swiper if you run on iOS

haowangcxy commented 6 years ago

+1, images didnt show on android device

YanHong1997 commented 6 years ago

I added swiper in my project,sometimes it was wrong.Specifically,it didn't work.The fact is images and dots all missing.Why?

wk1017553772 commented 6 years ago

I use blow code resolve this problem,but why?

componentDidMount(){
    //to fix react-native-swiper in android bug
        if (Platform.OS === 'android') {
            setTimeout(() => {
                this.setState({ visiableSwiper: true })
            }, 0)
        }
}

{this.state.visiableSwiper&&<Swiper/>}
srshah19 commented 6 years ago

Guys, sometimes when the parent View has a flex-direction or align-items then it does not render correctly. Try to remove those flex properties from the parent and see if it renders correctly.

aesyungan commented 6 years ago

Solution the problem is by the height in Swiper

export default class App extends Component { constructor() { super(); this.state = { auterScrollEnable: true, } }

render() { return ( <View style={{height: ScreenHeight}}>

      <Swiper  showsButtons={true}>
        <View style={styles.slideDefault}>
          <Text style={styles.text}>Hello Swiper</Text>
        </View>
      </Swiper>

  </View>
);

} }

const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, slideDefault: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#9DD6EB' }, text: { color: 'white', fontSize: 30, fontWeight: 'bold', } });

rafaelgrilli92 commented 6 years ago

@aesyungan it does the trick but it's still not good enough... Once you have a component that needs to scroll, the screen height cut the view and it messes up with the scrolling.

Johncy1997 commented 6 years ago
             <Swiper
                autoplay
                autoplayTimeout={5}
                height={240}
                showsButtons={false}
                showsPagination={true}
                loop={true}
                backgroundColor='transparent'
                activeDotColor='black'
                // dotColor='white'
            >
         {
           this.props.data.banner.map((item,i)=>{
                console.log("the image url is"+item.BannerUrl);
                <View>
              <Image style={{flex:1,width,resizeMode:'contain'}} source={{uri: 'https://facebook.github.io/react-native/docs/assets/favicon.png'}}/>
              </View>
            })
            }
            </Swiper>

I have to display item.BannerUrl in Image component.The url is passing required times to item.BannerUrl.But i am not getting the images.It shows only 7dots.Please anyone tell me what is the problem here?

rizalibnu commented 6 years ago

I get the same problem. Thanks @wk1017553772 for temporary solution.

maulikakapure commented 6 years ago

I tried following and worked for me, hope it helps you:

<Swiper
showsPagination={true} autoplay={true} width={width-20} loop={true} backgroundColor='#00FF00' showsButtons={false} dot={ } activeDot={ }

I have wrapped swiper in a view tag.

tuthanh82 commented 6 years ago

I experienced a problem on iOS with RN 0.55.3. Using with images, only 2 first items are shown, the third one is blank.

Does anyone else have the same problem?

UPDATE: it turns out that my styles is not good enough. I use the styles provided on the example "Swiper Number" and it works properly now.

chasecs commented 6 years ago

I don't know if this issue has something to do with the "resizeMode" of component. In my situation. when resizeMode="stretch", like below

<Swiper style={{flex: 1}} >
          {
              wallpapers.map((imgsrc, index) => (
                <TouchableWithoutFeedback
                  key={index}
                  style={{flex: 1}}
                >
                  <Image source={imgsrc} style={styles.image} resizeMode="stretch"/>
                </TouchableWithoutFeedback>
              ))
          }
        </Swiper>

one of images will not show up, only one of them. But, every thing woks fine if you change the props to resizeMode="cover".

ggepenyan commented 6 years ago

Why There Is No Solution Yet?????

bingxuelover commented 6 years ago

For me, in Android is fine, but in IOS only show the first image. I checked my codes, i write height={h} like this, but i write width in style, <Swiper height={h} style={{width:w}} > then i write width like height , <Swiper height={h} width={w} > it's ok for me in ios.

tandat2209 commented 6 years ago

any updates for this

hpmax00 commented 6 years ago

+1, change to react-native-snap-carousel

gobinmateo commented 6 years ago

try setting removeClippedSubviews prop to false. <Swiper removeClippedSubviews={false}>

abdymm commented 5 years ago

in my case, you guys only need to add a timeout to the swiper

psglee commented 5 years ago

My solution for this. You must set 'height' & 'width' for image. Example (render dynamic):

function

return (
  <View style={styles.container}>
    <Swiper showsButtons={true} index={photoViewIndex}>
      {list.map((item) => {
        return (
          <View style={styles.slide}>
            <Image source={{ uri: item.uri }} style={styles.img} resizeMode='center' />
          </View>
        )
      })}
    </Swiper>
  </View>
)

styles

const styles = StyleSheet.create({ container: { flex: 1 }, slide: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#FFFFFF', }, img: { height: WINDOW_SIZE.HEIGHT - verticalScale(50), // Ex: 300, 400, ... width: WINDOW_SIZE.WIDTH // Ex: 300, 400, ... } });

nguyenvanphuc2203 commented 5 years ago
loadMinimal
loadMinimalSize={2}

resolve for me!

guaizi149 commented 5 years ago

574

add key={pages.length}.

sterswift commented 4 years ago

Tried everything above but nothing helps.

  1. Added overflow: 'hidden' to swiper View parent
  2. Removed "position: absolute" from swiper style
  3. Added width: '100%', height: 180, resizeMode: 'cover' to swiper item

And it works!

davebrewer commented 4 years ago

Persevered with this a day or so, seems overly difficult to get sliders working performantly in android. I have a nested slider use case, however switching to the attached package (which has similar UI design) has been much more straight forward: https://www.npmjs.com/package/react-native-web-swiper

Sorry "react-native-swiper".

lexycole commented 3 years ago

My Error was the fact that all three of the images were sized 1227 x 2778, so I switch to images with dimensions: 1260 x 675; 1536 x 2310, and 5184 x 3456, Hope it solve yours.

CyberAakash commented 1 year ago

Everything is not working for me. The one works for me is this.

Solution : -------->

Add [ width:100% to the .swiper-slide class ]. Thats it. IT WORKS FOR ME.

i.e.,

.swiper-slide { width: 100% !important; }