meliorence / react-native-snap-carousel

Swiper/carousel component for React Native featuring previews, multiple layouts, parallax images, performant handling of huge numbers of items, and more. Compatible with Android & iOS.
BSD 3-Clause "New" or "Revised" License
10.32k stars 2.28k forks source link

How to use images in your local directory #731

Open sudonitin opened 4 years ago

sudonitin commented 4 years ago

Could not find an issue or instruction in the readme on how to use local images in the carousel.

pku-arun commented 3 years ago

I am facing same issue

dohooo commented 2 years ago

Sorry, please allow me to advertise for my open source library! ~ I think this library react-native-reanimated-carousel will solve your problem. It is a high performance and very simple component, complete with React-Native reanimated 2

realophobia commented 2 years ago

I was having the same issue and couldn't make it work in one project. But was able to make it work in my new project. I followed this guide. https://amanhimself.dev/blog/custom-preview-image-gallery-in-react-native/. I tried solutions suggested by others where they set the app name inside the package.json and then set the file path based on that app name but that did not work for me.

ShenyiHuang commented 3 weeks ago

I fixed this problem by change the image source

  const data = [
  { id:"1", image: require('filepath') },
  { id:"2", image: require('filepath') },
  { id:"3",  image: require('filepath') },
  ];

  const renderItem = ({ item }) => {
    return (
      <View style={styles.slide}>
        <Image source={item.url} style={styles.image} />
      </View>
    );
  };

In your Carousel component, set data={data} and renderItem={renderItem}.