Giter VIP home page Giter VIP logo

intellidev1991 / react-native-image-slider-box Goto Github PK

View Code? Open in Web Editor NEW
261.0 4.0 96.0 1.16 MB

A simple and fully customizable React Native component that implements an Image Slider UI.

License: MIT License

JavaScript 24.59% Java 17.22% Ruby 18.22% Objective-C 27.41% Starlark 12.57%
react-native react-components react-native-image react-native-image-slider react-native-image-slider-box react-native-library react-native-component

react-native-image-slider-box's Introduction

react-native-image-slider-box

npm npm

If you would like to support me, please consider buying me a coffee

Crypto donation button by NOWPayments

How to send a pull-request for this lib??? > Please Read this section before send a pull request


SliderBox

SliderBox

Install

  1. First, install our library | use below npm script

    npm i react-native-image-slider-box

    yarn add react-native-image-slider-box

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

    npm i react-native-fast-image

    yarn add react-native-fast-image

Well-done.

Usage :

list of available props for customization SliderBox:

Props Value Type Description
ImageComponent Image component, default as Image default value is React-native Image, if you use third-party library like FastImage use this property
images Array of image path(or url) as string Set array of images path- these paths can contain http url link or local images path using require('./pathOfImage')
onCurrentImagePressed handler function callback callback for get pressed image index (index start from 0)
currentImageEmitter handler function callback callback for get current image index (index start from 0)
disableOnPress boolean if present, then onCurrentImagePressed will be disabled
activeOpacity number default value = 0.85, Determines the opacity when touch is active. The value should be between 0 and 1
sliderBoxHeight int value default value = 200, you can change height of image slider box
parentWidth int default = screen.width ; in advance mode, if parent is smaller, you can change it. best practice is use onLayout handler in parent component or screen.
dotColor color string code change color of paging dot
inactiveDotColor color string code change color of inactive paging dot
dotStyle style object default style is : {width: 10,height: 10,borderRadius: 5,marginHorizontal: 0,padding: 0,margin: 0,} change style of paging dots if you want
paginationBoxVerticalPadding int value default = 10 ; change the height of paging dots from bottom of Slider-Box
autoplay bool value default = false
circleLoop boolean - attribute if set, when user swiped to last image circularly return to the first image again.
paginationBoxStyle object,default values use lib style customize pagination box
dotStyle object,default use lib style customize dot styles
resizeMethod string default is resize
resizeMode string default is cover
ImageComponentStyle object {} style object for ImageComponent
imageLoadingColor string default is #E91E63 , image loading indicator color
ImageLoader React component, default as ActivityIndicator default value is React-native ActivityIndicator.
firstItem number default is 0 , index of image to display when slider box loads
LoaderComponent component default is ActivityIndicator , you can pass any component to show as Loader
autoplayInterval number default is 3000ms

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", // Network image
        require('./assets/images/girl.jpg'),          // Local image
      ]
    };
  }
  // 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 and currentImageEmitter

SliderBox

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

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 autoplay and circleLoop attribute for jump to the first image after swipe the last one.

SliderBox

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

Example 8 : use Custom Image Component, customize pagination, image modes and dotStyles:

SliderBox

<SliderBox
  ImageComponent={FastImage}
  images={this.state.images}
  sliderBoxHeight={200}
  onCurrentImagePressed={index => console.warn(`image ${index} pressed`)}
  dotColor="#FFEE58"
  inactiveDotColor="#90A4AE"
  paginationBoxVerticalPadding={20}
  autoplay
  circleLoop
  resizeMethod={'resize'}
  resizeMode={'cover'}
  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)"
  }}
  ImageComponentStyle={{borderRadius: 15, width: '97%', marginTop: 5}}
  imageLoadingColor="#2196F3"
/>

Example 9 : SliderBox with activeOpacity:

SliderBox

<SliderBox
  images={this.state.images}
  sliderBoxHeight={200}
  activeOpacity={0.5}
/>

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",
        require('./assets/images/girl.jpg'),
      ]
    };
  }

  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
  }
});

Contribute And Update the Library

Please Edit and use dist/SliderBox.js file as src component file.

How to send a pull-request

To send a pull-request please follow these rules for naming the commit message. Based on the commit messages, increment the version from the lastest release.

  • If the string "BREAKING CHANGE" is found anywhere in any of the commit messages or descriptions the major version will be incremented.
  • If a commit message begins with the string "feat" then the minor version will be increased. b"feat: new API" and "feature: new API".
  • All other changes will increment the patch version.

! Important: Please update the README.MD file corresponding with your added features.

Please subscribe and contribute with me to develop this lib


Notice:

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

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)


License MIT

react-native-image-slider-box's People

Contributors

caiomendes23 avatar chandramohannegi avatar diogo84 avatar ersenkaya avatar iiagodias avatar intellidev1991 avatar klodha avatar luan-tecnobit avatar meenabassem avatar mfix22 avatar moathothman avatar mrlibya avatar myckhel avatar renovate-bot avatar renovate[bot] avatar sebovs avatar stevieoj avatar toritsejufo avatar xlash5 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

react-native-image-slider-box's Issues

images prop Should support Immutable types

images prop should support Immutable types.

Currently, the List Immutable type (such as Immutable.List) has to be converted to javascript objects using the .toJSON() function.

Image show blank when reducing items amount in images array

Hi,
I need to show slider images through call api to get images array. I'm facing a bug when reload page and api recall to get images array. Images don't show (blank) when reducing items amount in images array (array change)

how to fix this problem ?

Dots not being displayed

Hello, I just installed and tried this component.

While it has everything that we need for this project, it just missing dots
Below is my code.

import React, { useState, useEffect } from "react";
import { FlatList, View, StyleSheet,Dimensions } from "react-native";
import firestore from "@react-native-firebase/firestore";
import { useSelector, shallowEqual, useDispatch } from "react-redux";
import { theme } from "../../utils/theme";
import {
  emailValidator,
  passwordValidator,
  firstNameValidator,
  lastNameValidator
} from "../../utils/utils";
import styles from "../../utils/styles";
import {
  Surface,
  Text,
  TextInput,
  ActivityIndicator,
  Button
} from "react-native-paper";
import { SliderBox } from "react-native-image-slider-box";
const deviceWidth = Dimensions.get("window").width;
const deviceHeight = Dimensions.get("window").height;

export default function RetailScreen() {

  const [images, setImages] = useState([]);
  useEffect(() => {
    setImages([
      "https://source.unsplash.com/1024x768/?nature",
      "https://source.unsplash.com/1024x768/?water",
      "https://source.unsplash.com/1024x768/?girl",
      "https://source.unsplash.com/1024x768/?tree", 
    ])

  }, []);


  return (
    <Surface style={styles.containerHome}>
      <View style={styles.flex1}>
        <SliderBox images={images}
          // onCurrentImagePressed={index => console.warn(`image ${index} pressed`)}
          // currentImageEmitter={index => console.warn(`current pos is: ${index}`)}
          sliderBoxHeight={deviceHeight/3}
          dotColor="red"
          inactiveDotColor="blue"
          dotStyle={{
            width: 15,
            height: 15,
            borderRadius: 15,
            marginHorizontal: 10,
            padding: 0,
            margin: 0
          }} />

      </View>
    </Surface>
  );
}

Let me know if you find any issue? .Thanks

disableOnPress: Invalid prop `onPress` of type `boolean` supplied to `TouchableHighlight`, expected `function`

Hello,

I use a prop disableOnPress and meet the warning below. Please help me fix it.

Warning: Failed prop type: Invalid prop `onPress` of type `boolean` supplied to `TouchableHighlight`, expected `function`.
- node_modules/prop-types/checkPropTypes.js:20:20 in printWarning
- node_modules/prop-types/checkPropTypes.js:83:12 in checkPropTypes
- node_modules/react/cjs/react.development.js:1501:19 in validatePropTypes
- node_modules/react/cjs/react.development.js:1590:22 in createElementWithValidation
- node_modules/react-native-image-slider-box/dist/SliderBox.js:58:7 in _renderItem
- node_modules/react-native-image-slider-box/dist/SliderBox.js:130:47 in renderItem
- node_modules/react-native-snap-carousel/src/carousel/Carousel.js:1224:29 in _renderItem

adjusting autoplay interval

Hi, is there any way to increase the autoplay interval? its currently about 2500ms i guess and i think its a bit quick.

some changes need in react native 0.62.1

Calling getNode() on the ref of an Animated component is no longer necessary. You can now directly use the ref instead. This method will be removed in a future release. FlatList

Cutom Footer

Is there a way to render our own footer instead of rendering dots? something like 2/5 instead of dots.

Remove Gradient Image

hi, im using this library and my package already installed react native linear gradient, and result this view.

image

Code

    <KeyboardAvoidingView behavior='position'>
      <Text>TestSliderScreen</Text>
      <SliderBox images={this.state.images} />
    </KeyboardAvoidingView>
 </ScrollView>

how to remove gradient over image ?

UI

I see dot is slower than image

Cant slide between photos on IOS

<SliderBox images={imageList} circleLoop sliderBoxHeight={200} ImageComponentStyle={{ borderBottomLeftRadius: 6, borderBottomRightRadius: 6 }} imageLoadingColor="#90A456" dotColor="#22A4AE" inactiveDotColor="#90A4AE" />

Hi, I can't slide between two photos on IOS, Android works just fine. I don't want autoplay props so I need to slide between photos. Maybe some additional props are required to enable this?

autoplay On memory leaking?

I tried to test the autoplay with circleLoop and I saw the memory usage becomes like following image.

Then I off the autoplay and it is linear. Would be nice if you can take a look :D

Btw, thanks for the great library.

Screenshot 2020-02-15 at 6 38 07 PM

Disabling the scale effect

Can we disable the scaling effect when image is changing?

I want it slide horizontally without scaling..

Crashing on release

When I have more than one image it's working perfectly on debug mode , but when I tried to generate a signed apk , it crashed when I have more than one image in the box.
I am using the latest version of the library.

my code is so simple :
state={
width: Dimensions.get('window').width,
height: Dimensions.get('window').height,
ads:[ "https://source.unsplash.com/1024x768/?nature",
"https://source.unsplash.com/1024x768/?water",
"https://source.unsplash.com/1024x768/?girl",]
}
render(){
return(<SliderBox resizeMode="cover" images={this.state.ads}
parentWidth={this.state.width} sliderBoxHeight={60} paginationBoxStyle={{opacity: 0}}
/>);
}_

Know current image index

Is there any way to know the current image index? I want to load a new screen if a user tries to slide the last image of the gallery.

Remove dynamically images

Hi

As seen on title i would like to remove dynamically images from slide, when i choose one image and remove it all images gone, i used index variable and put it in state to get current index, and just slice the item in array:
setState({ images: this.state.images.splice(i, 1) })

get position ?

I've never seen a fonskion called getPosition. how to get a position without clicking?

ResizeMode

Hi!

Is there a way to use the resizeMode props for Images?

circleloop has error

when use circleloop console log show this error.
VirtualizedList: You have a large list that is slow to update - make sure your renderItem function renders components that follow React performance best practices like PureComponent, shouldComponentUpdate, etc. {"contentLength": 5760, "dt": 2091, "prevDt": 1034}

Autoplay Time

Hello,

How can i set time for the AutoPlay ?

Thanks

Adjust spacing between dots

Is there a way to define the space between each dot. I am scaling the size of my dost with respect ti number of images. when count is large (more than 10) dost are so small to fit in the screen but spacing between them is ridiculous.

It would be nice if i can set the horizontal spacing between dots.

Position

Hi!
is it possible to assign a position to the slide? for example if I put position={2}, I have the second image that appears

VirtualizedList: You have a large list that is slow to update - make sure your renderItem function renders components that follow React performance best practices like PureComponent, shouldComponentUpdate, etc.

I am experiencing this issue with the sliderbox.I am only loading 6 images.

full warning message.
VirtualizedList: You have a large list that is slow to update - make sure your renderItem function renders components that follow React performance best practices like PureComponent, shouldComponentUpdate, etc. Object {
"contentLength": 6283.63623046875,
"dt": 2370,
"prevDt": 509,
}

can't set marginStart and marginEnd for the container

 <View
              styles={{
                marginTop: 20,
                marginLeft: 10,
                marginEnd: 10,
                alignItems: 'center',
                flexDirection: 'row',
                justifyContent: 'center',
              }}>
              <SliderBox
                images={this.state.images}
                sliderBoxHeight={200}
                parentWidth={Dimensions.get('window').width - 20}
           
    
              />
            </View>

There is no margin start

Calling `getNode()` on the ref of an Animated component is no longer necessary.

I am using this package in "react-native": "0.62.2", which brings up that warning. Below is the complete warning

Calling getNode() on the ref of an Animated component is no longer necessary. You can now directly use the ref instead. This method will be removed in a future release. Personally i think it's something to do with Reanimated being included by default now.

Screenshot

calling getNode() is no longer necessary

Is this a bug report, a feature request, or a question?
Bug

Is the bug reproducible in a production environment (not a debug one)?
Yes

Environment
"react": "16.11.0",
"react-native": "0.62.2",
"react-native-snap-carousel": 3.8.4

Target Platform:
Android (9.0)

Bug:
Warning : Calling 'getNode()' on the ref an Animated Component is no longer necessary.

Sometimes Images Are not Loading

Screenshot_1

hi, really thanks for the component. working perfectly for me but some times images are not loading showing loading indicator like the image shown. my code is as follows.

<SliderBox
images={this.state.photos}
sliderBoxHeight={500}
dotColor="#FFEE58"
inactiveDotColor="#90A4AE"
paginationBoxVerticalPadding={20}
circleLoop
autoplay
resizeMethod={'resize'}
resizeMode={'contain'}
ImageComponentStyle={{ borderRadius: 15, width: '100%' }}
/>

when i browse the link i am able to view the image. please help. thanks

version : "react-native-image-slider-box": "^1.0.12"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.