react-native-swiper images not displaying

581 Views Asked by At

I am using the react native swiper and am unable to see the photos I am requiring. Am I calling the photos incorrectly? When I try and display the photo like normal with an Image tag it works so I know I am importing the photo from the correct directory.

....
import Swiper from 'react-native-swiper';
....
const ProfileCardScreen = ({navigation}) => {

  var profilePhotos=[{image:require('../images/NYE.jpg')},{image:require('../images/hiking.jpg')},{image:require('../images/baseball.jpg')}];

  return (
    <View style = {styles.container}>
        <Text style={styles.profilePageUserName}>User Name Here</Text>
        <Swiper showsButtons={true}>
            <View style={styles.slide1}>
                <Image style={{flex:1, height: undefined, width: undefined}}
                    resizeMode="contain"
                    source={require('../images/NYE.jpg')}/>
            </View>
            <View style={styles.slide2}>
                <Image style={{flex:1, height: undefined, width: undefined}}
                    resizeMode="contain"
                    source={require('../images/hiking.jpg')}/>    
            </View>
            <View style={styles.slide3}>
                <Image style={{flex:1, height: undefined, width: undefined}}
                    resizeMode="contain"
                    source={require('../images/baseball.jpg')}/>          
            </View>
        </Swiper>

enter image description here

1

There are 1 best solutions below

1
On

The Syntax is correct, Try importing images in import statement like

import Swiper from 'react-native-swiper';
import Image1 from '../images/NYE.jpg';
import Image2 from '../images/hiking.jpg';
import Image3 from '../images/baseball.jpg';
....
const ProfileCardScreen = ({navigation}) => {

var profilePhotos=[{image:require('../images/NYE.jpg')}, 
{image:require('../images/hiking.jpg')}, 
{image:require('../images/baseball.jpg')}];

 return (
<View style = {styles.container}>
    <Text style={styles.profilePageUserName}>User Name Here</Text>
    <Swiper showsButtons={true}>
        <View style={styles.slide1}>
            <Image style={{flex:1, height: undefined, width: undefined}}
                resizeMode="contain"
                source={Image1}/>
        </View>
        <View style={styles.slide2}>
            <Image style={{flex:1, height: undefined, width: undefined}}
                resizeMode="contain"
                source={Image2)}/>    
        </View>
        <View style={styles.slide3}>
            <Image style={{flex:1, height: undefined, width: undefined}}
                resizeMode="contain"
                source={Image3}/>          
        </View>
    </Swiper>

If the above code also doesn't works then there must be any problem in your styling. That's all I can do.