React-native-swiper: Warning: Failed prop type: Invalid prop `style` supplied to `_class`.

Created on 28 Aug 2017  路  11Comments  路  Source: leecade/react-native-swiper

Version

  • react-native-swiper v1.5.10

Code

<Swiper loop={false}>XXXXX</Swiper>
I didnot write any styles, but it warning.

image

Need answer from author 馃攷investigate

Most helpful comment

I get the same warning with styled-components.

All 11 comments

I do not have any warning with no style in my swiper.
Can you fork the project and reproduce your warning in an example ?

I second @xiaobai1990zhan problem, I'm using the styled components lib, I'm not sure if it's related.

// tslint:disable-next-line:no-var-requires
const ViewPager = require('react-native-swiper');

export const OnboardTutorialViewPager: any = styled(ViewPager)`
`;

And in the component render method

render() {
    return (
      <OnboardTutorialViewPager>
        <OnboardTutorialPageStyled>
          <OnboardTutorialImageStyled
            source={{ uri: 'https://upload.wikimedia.org/wikipedia/commons/thumb/f/f4/Nietzsche187c.jpg/170px-Nietzsche187c.jpg' }}
          />
        </OnboardTutorialPageStyled>
        <OnboardTutorialPageStyled>
          <OnboardTutorialImageStyled
            source={{ uri: 'https://upload.wikimedia.org/wikipedia/commons/thumb/f/f4/Nietzsche187c.jpg/170px-Nietzsche187c.jpg' }}
          />
        </OnboardTutorialPageStyled>
        <OnboardTutorialPageStyled>
          <OnboardTutorialImageStyled
            source={{ uri: 'https://upload.wikimedia.org/wikipedia/commons/thumb/f/f4/Nietzsche187c.jpg/170px-Nietzsche187c.jpg' }}
          />
        </OnboardTutorialPageStyled>
      </OnboardTutorialViewPager>
    );
  }

It also complains about array of styles.

I'm experiencing a similar issue here. No warnings without any style though. But it complains if I assign custom styles, either style, activeDotStyle, or dotStyle.

Having the same issue
<Swiper .... style={[styles.swiperImg]} .... </Swiper>
Should be: style={ styles.swiperImg }

Don't know what's the issue with array of styles, but here is a workaround:
This piece of code

style={[firstStyle, secondStyle]}

is equivalent to

style={StyleSheet.flatten([firstStyle, secondStyle])}

and the warning is gone.

I get the same warning with styled-components.

@arribbar
This warning showing up when using styled-components (not with style prop).
I'm also facing that warning,

Warning: Failed prop type: Invalid prop `style` supplied to `_class`.

const SwiperView = styled(Swiper)``;

versions
RN: 0.55.4,
React: 16.3.1,
react-native-swiper: 1.5.13

I'm also having this issue with styled-components. Any update on this?

@leecade sorry to bring you up here, but I'm pretty sure this fix is something really quick for someone skilled enough to put this lib together. this warning has been haunting my console for a while now. could you please help out the poors using styled components together with swiper?

thanks a lot!

That is still a thing

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nicolabortignon picture nicolabortignon  路  3Comments

agzuniverse picture agzuniverse  路  3Comments

commit-master picture commit-master  路  3Comments

gwhite-dayspring picture gwhite-dayspring  路  3Comments

AndriiBoiko picture AndriiBoiko  路  3Comments