1.4.0 • Published 1 year ago

@buhissopro/react-native-image-slider-show v1.4.0

Weekly downloads
-
License
-
Repository
github
Last release
1 year ago

react-native-image-slider-show

A quick and easy slideshow for react native. (Android & iOS)

GIF GIF


Installation with expo

expo install react-native-image-slider-show --save

Installation

npm install react-native-image-slider-show --save

Usage

import Slideshow from 'react-native-image-slider-show';

Autoplay Example

import Slideshow from 'react-native-image-slider-show';

const fetchImages = async (callback) => {
  try {
    axios.defaults.baseURL = API_BASE;
    const response = await axios.get('/');
    callback(response.data);
  } catch (error) {
    console.error(error);
  }
}

const SlideshowTest = () => {
  const [dataSource, setDataSource] = React.useState([]);
  const [position, setPosition] = React.useState(0);

  React.useEffect(() => {
    fetchImages((data) => { 
      setDataSource(data.map((url) => ({ url })))
    });  
  }, [])

  React.useEffect(()=>{
    const toggle = setInterval(() => {
      setPosition(
        position === dataSource.length - 1 ? 0 : position + 1
      );
    }, 10000);

    return () => clearInterval(toggle);
  })

  return (
    <Slideshow position={position} dataSource={dataSource} />
  )
}

Props

PropertyTypeisRequired?DefaultDescription
dataSourceboolrequired-slideshow data
heightnumberoptional200container height
positionnumberoptional-set position slideshow
scrollEnabledbooloptionaltrueenable / disable scrolling
overlaybooloptionalfalsebackground overlay
indicatorSizenumberoptional16indicator size
indicatorColorstringoptional#CCCCCCindicator color
indicatorSelectedColorstringoptional#FFFFFFindicator selected color
arrowSizenumberoptional16arrow size
arrowLeftobjectoptional-component arrow left
arrowRightobjectoptional-component arrow right
onPressfuncoptional-returns an object image and index of image pressed
onPositionChangedfuncoptional-called when the current position is changed
containerStyleobjectoptional-custom styles for container
titleStyleobject--custom styles for title
captionStyleobject--custom styles for caption

Forked Repo Extended Props

PropertyTypeisRequired?DefaultDescription
hideSideArrowsbooleanfalsechanging this allows you to hide the side arrows
hidePageIndicatorbooleanfalsechanging this allows you to hide the page indicators

Data Structure

// example data structure

dataSource: [
  {
    title: 'title 1',
    caption: 'caption 1',
    url: 'url 1',
  }, {
    title: 'title 1',
    caption: 'caption 1',
    url: 'url 2',
  },
]
PropertyTypeDescription
titlestringtitle
captionstringcaption
urlstring / numberimage (URL or a local file resource)

Credits

react-native-image-slider

License

MIT