Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-image-slider-box

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-image-slider-box

A simple and fully customization React Native component that implements a ImageSlider UI.

  • 1.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.3K
decreased by-8.24%
Maintainers
1
Weekly downloads
 
Created
Source

react-native-image-slider-box

This library use react-native-snap-carousel and make easier way to create image slider box with full customization ability.

Notice:

See original Library https://github.com/archriss/react-native-snap-carousel

We don't edit or modify original library, we just use it with some additional style.


SliderBox

Install

  1. First install this library : https://github.com/archriss/react-native-snap-carousel | use below npm script (Thank you so much to provide snap-carousel lib. please see the original lib)

    npm i react-native-snap-carousel

  2. Second install our library | use below npm script

    npm i react-native-image-slider-box

  3. (Optional) : if you want to use third-party image library such as FastImage

    npm i react-native-fast-image;

Well-done.

Usage :

list of available props for customization SliderBox:

PropsValue TypeDescription
ImageComponentImage component, default as Imagedefault value is React-native Image, if you use third-party library like FastImage use this property
imagesArray of image path(or url) as stringSet array of images path- these paths can contain http url link or local images path
onCurrentImagePressedhandler function callbackcallback for get pressed image index (index start from 0)
sliderBoxHeightint valuedefault value = 200, you can change height of image slider box
parentWidthintdefault = screen.width ; in advance mode, if parent is smaller, you can change it. best practice is use onLayout handler in parent component or screen.
dotColorcolor string codechange color of paging dot
inactiveDotColorcolor string codechange color of inactive paging dot
dotStylestyle objectdefault style is : {width: 10,height: 10,borderRadius: 5,marginHorizontal: 0,padding: 0,margin: 0,} change style of paging dots if you want
paginationBoxVerticalPaddingint valuedefault = 10 ; change the height of paging dots from bottom of Slider-Box
circleLoopboolean - attributeif set, when user swiped to last image circularly return to first image again.
paginationBoxStyleobject,default valuse use lib stylecustomize pagination box
dotStyleobject,default use lib stylecustomize dot styles

1- add below import in your code :


import { SliderBox } from 'react-native-image-slider-box';

2- Define your image array source, for below examples i create array in state.

export default class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      images: [
        'https://source.unsplash.com/1024x768/?nature',
        'https://source.unsplash.com/1024x768/?water',
        'https://source.unsplash.com/1024x768/?girl',
        'https://source.unsplash.com/1024x768/?tree'
      ]
    };
  }
// other component code ...
}

3- Use SliderBox such as these below examples :

Example 1 : SliderBox without and handler or customization

<SliderBox images={this.state.images} />

Example 2 : SliderBox with image press handler

SliderBox


<SliderBox
    images={this.state.images}
    onCurrentImagePressed={index =>
        console.warn(`image ${index} pressed`)
    }
/>

Example 3 : SliderBox with image press handler and change slider height (default is 200)

SliderBox


<SliderBox
    images={this.state.images}
    sliderBoxHeight={400}
    onCurrentImagePressed={index =>
        console.warn(`image ${index} pressed`)
    }
/>

Example 4 : SliderBox with custom width from parent. use onLayout function by calling it from root View of component.

onLayout = e => {
    this.setState({
        width: e.nativeEvent.layout.width
    });
};
render() {
    return (
        <View style={styles.container} onLayout={this.onLayout}>
            <SliderBox
                images={this.state.images}
                sliderBoxHeight={200}
                onCurrentImagePressed={index =>
                    console.warn(`image ${index} pressed`)
                }
                parentWidth={this.state.width}
            />
        </View>
    );
  }

Example 5 : SliderBox with custom dots color

SliderBox

<SliderBox
    images={this.state.images}
    sliderBoxHeight={200}
    onCurrentImagePressed={index =>
        console.warn(`image ${index} pressed`)
    }
    dotColor="#FFEE58"
    inactiveDotColor="#90A4AE"
/>

Example 6 : SliderBox with custom dot style

SliderBox

<SliderBox
    images={this.state.images}
    sliderBoxHeight={200}
    onCurrentImagePressed={index =>
        console.warn(`image ${index} pressed`)
    }
    dotColor="#FFEE58"
    inactiveDotColor="#90A4AE"
    dotStyle={{
        width: 15,
        height: 15,
        borderRadius: 15,
        marginHorizontal: 10,
        padding: 0,
        margin: 0
    }}
/>

Example 7 : SliderBox with change paging box padding (Vertical height from bottom of SliderBox) + add circleLoop attribute for jump to first image after swipe the last image.

SliderBox

<SliderBox
    images={this.state.images}
    sliderBoxHeight={200}
    onCurrentImagePressed={index =>
        console.warn(`image ${index} pressed`)
    }
    dotColor="#FFEE58"
    inactiveDotColor="#90A4AE"
    paginationBoxVerticalPadding={20}
    circleLoop
/>

Example 8 : use Custom Image Component and customize pagination and dotStyles:

<SliderBox
  ImageComponent={FastImage}
  images={this.state.images}
  sliderBoxHeight={200}
  onCurrentImagePressed={index =>
    console.warn(`image ${index} pressed`)
  }
  dotColor="#FFEE58"
  inactiveDotColor="#90A4AE"
  paginationBoxVerticalPadding={20}
  paginationBoxStyle={{
    position: 'absolute',
    bottom: 0,
    padding: 0,
    alignItems: 'center',
    alignSelf: 'center',
    justifyContent: 'center',
    paddingVertical: 10
  }}
  dotStyle={{
    width: 10,
    height: 10,
    borderRadius: 5,
    marginHorizontal: 0,
    padding: 0,
    margin: 0,
    backgroundColor: 'rgba(128, 128, 128, 0.92)'
  }}
  circleLoop
/>

Full-Component(Screen) Example:

import React, { Component } from 'react';
import { StyleSheet, Text, View } from 'react-native';

import { SliderBox } from 'react-native-image-slider-box';

export default class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      images: [
        'https://source.unsplash.com/1024x768/?nature',
        'https://source.unsplash.com/1024x768/?water',
        'https://source.unsplash.com/1024x768/?girl',
        'https://source.unsplash.com/1024x768/?tree'
      ]
    };
  }

  render() {
    return (
      <View style={styles.container}>
        <SliderBox
          images={this.state.images}
          onCurrentImagePressed={index =>
            console.warn(`image ${index} pressed`)
          }
        />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1
  }
});

License MIT

Please subscribe and contribute me to develop this lib


Notice:

See original Library https://github.com/archriss/react-native-snap-carousel

we dont edit or modify original library, we just use it with some additional style. (BSD 3 License)

Keywords

FAQs

Package last updated on 31 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc