Giter Site home page Giter Site logo

react-native-slick's Introduction

react-native-slick

The best Slick component for React Native.

JavaScript Style Guide npm version npm version PR Stats Issue Stats Join the chat

react-native-slick

Roadmap

see: ROADMAP.md

Changelogs

  • [v1.0.2]

    • Fix bugs and copy updates from original repo
  • [v1.0.1]

see more: CHANGELOG.md

Show Cases

Try these cases by yourself very easy, Just open examples/ios/slick.xcodeproj in Xcode, then press Cmd + R; you may edit examples/index.ios.js for switch cases.

with react-native-photo-view

Getting Started

Installation

$ npm i react-native-slick --save

Basic Usage

  • Install react-native first
$ npm i react-native -g
  • Initialization of a react-native project
$ react-native init AwsomeProject
  • Then, edit AwsomeProject/index.ios.js, like this:
import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View
} from 'react-native';

import Slick from 'react-native-slick';

var styles = StyleSheet.create({
  wrapper: {
  },
  slide1: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#9DD6EB',
  },
  slide2: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#97CAE5',
  },
  slide3: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#92BBD9',
  },
  text: {
    color: '#fff',
    fontSize: 30,
    fontWeight: 'bold',
  }
})

var slick = React.createClass({
  render: function() {
    return (
      <Slick style={styles.wrapper} showsButtons={true}>
        <View style={styles.slide1}>
          <Text style={styles.text}>Hello Slick</Text>
        </View>
        <View style={styles.slide2}>
          <Text style={styles.text}>Beautiful</Text>
        </View>
        <View style={styles.slide3}>
          <Text style={styles.text}>And simple</Text>
        </View>
      </Slick>
    )
  }
})

AppRegistry.registerComponent('AwsomeProject', () => slick);

Properties

Basic

Prop Default Type Description
horizontal true bool If true, the scroll view's children are arranged horizontally in a row instead of vertically in a column.
loop true bool Set to false to disable continuous loop mode.
index 0 number Index number of initial slide.
showsButtons false bool Set to true make control buttons visible.
autoplay false bool Set to true enable auto play mode.

Custom basic style & content

Prop Default Type Description
width - number If no specify default enable fullscreen mode by flex: 1.
height - number If no specify default fullscreen mode by flex: 1.
style {...} style See default style in source.
loadMinimal false bool Only load current index slide , loadMinimalSize slides before and after.
loadMinimalSize 1 number see loadMinimal
loadMinimalLoader <ActivityIndicator /> element Custom loader to display when slides aren't loaded

Pagination

Prop Default Type Description
showsPagination true bool Set to true make pagination visible.
paginationStyle {...} style Custom styles will merge with the default styles.
renderPagination - function Complete control how to render pagination with three params (index, total, context) ref to this.state.index / this.state.total / this, For example: show numbers instead of dots.
dot <View style={{backgroundColor:'rgba(0,0,0,.2)', width: 8, height: 8,borderRadius: 4, marginLeft: 3, marginRight: 3, marginTop: 3, marginBottom: 3,}} /> element Allow custom the dot element.
activeDot <View style={{backgroundColor: '#007aff', width: 8, height: 8, borderRadius: 4, marginLeft: 3, marginRight: 3, marginTop: 3, marginBottom: 3,}} /> element Allow custom the active-dot element.
dotStyle - object Allow custom the active-dot element.
dotColor - string Allow custom the active-dot element.
activeDotColor - string Allow custom the active-dot element.
activeDotStyle - object Allow custom the active-dot element.

Autoplay

Prop Default Type Description
autoplay true bool Set to true enable auto play mode.
autoplayTimeout 2.5 number Delay between auto play transitions (in second).
autoplayDirection true bool Cycle direction control.

Control buttons

Prop Default Type Description
showsButtons true bool Set to true make control buttons visible.
buttonWrapperStyle {backgroundColor: 'transparent', flexDirection: 'row', position: 'absolute', top: 0, left: 0, flex: 1, paddingHorizontal: 10, paddingVertical: 10, justifyContent: 'space-between', alignItems: 'center'} style Custom styles.
nextButton <Text style={styles.buttonText}>›</Text> element Allow custom the next button.
prevButton <Text style={styles.buttonText}>‹</Text> element Allow custom the prev button.

Props of Children

Prop Default Type Description
style {...} style Custom styles will merge with the default styles.
title {...} element If this parameter is not specified, will not render the title.

Basic props of <ScrollView />

Prop Default Type Description
horizontal true bool If true, the scroll view's children are arranged horizontally in a row instead of vertically in a column.
pagingEnabled true bool If true, the scroll view stops on multiples of the scroll view's size when scrolling. This can be used for horizontal pagination.
showsHorizontalScrollIndicator false bool Set to true if you want to show horizontal scroll bar.
showsVerticalScrollIndicator false bool Set to true if you want to show vertical scroll bar.
bounces false bool If true, the scroll view bounces when it reaches the end of the content if the content is larger then the scroll view along the axis of the scroll direction. If false, it disables all bouncing even if the alwaysBounce* props are true.
scrollsToTop false bool If true, the scroll view scrolls to top when the status bar is tapped.
removeClippedSubviews true bool If true, offscreen child views (whose overflow value is hidden) are removed from their native backing superview when offscreen. This canimprove scrolling performance on long lists.
automaticallyAdjustContentInsets false bool Set to true if you need adjust content insets automation.
scrollEnabled true bool Enables/Disables swiping

@see: http://facebook.github.io/react-native/docs/scrollview.html

Supported ScrollResponder

Prop Params Type Description
onScrollBeginDrag e / state / context function When animation begins after letting up
onMomentumScrollEnd e / state / context function Makes no sense why this occurs first during bounce
onTouchStartCapture e / state / context function Immediately after onMomentumScrollEnd
onTouchStart e / state / context function Same, but bubble phase
onTouchEnd e / state / context function You could hold the touch start for a long time
onResponderRelease e / state / context function When lifting up - you could pause forever before * lifting

Note: each ScrollResponder be injected with two params: state and context, you can get state and context(ref to slick's this) from params, for example:

var slick = React.createClass({
  _onMomentumScrollEnd: function (e, state, context) {
    console.log(state, context.state)
  },
  render: function() {
    return (
      <Slick style={styles.wrapper}
      onMomentumScrollEnd ={this._onMomentumScrollEnd}
     ...
      </Slick>
    )
  }
})

More ScrollResponder info, see: https://github.com/facebook/react-native/blob/master/Libraries/Components/ScrollResponder.js

Methods

scrollBy(index, animated)

Scroll by relative index.

Parameters:

Name Type default Description
index number undefined offset index
animated bool true offset index

Examples

$ cd examples
$ npm i
$ react-native run-ios

Quick start with examples.

Development

$ cd examples
$ npm i
$ npm run dev
$ react-native run-ios

Then launch simulator to preview. Note that you just need to edit the source file src/index.js, the change will auto sync to examples.

And now that this project follows the standard code style, you'd better prepare it for IDE.

Contribution

Questions

Feel free to contact me or create an issue

Inspired by nolimits4web/Slick & Design material from Dribbble & made with ♥.

react-native-slick's People

Contributors

aforty avatar ahmed3mar avatar allomov avatar almost avatar andrewthoughtmachine avatar aubsw avatar bilalbudhani avatar brianantonelli avatar brianreavis avatar dchartfield avatar dizlexik avatar eosterberg avatar exilz avatar faridsafi avatar getnashty avatar gitter-badger avatar greenkeeperio-bot avatar hypatiah avatar ibandominguez avatar jasonmerino avatar jukkatupamaki avatar leecade avatar martco avatar nemophrost avatar onchainguy-eth avatar rajkissu avatar skv-headless avatar sunnylqm avatar tsunammis avatar yazgazan avatar

Stargazers

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

Watchers

 avatar

react-native-slick's Issues

Partial slide?

Could you give us some examples for partial slide?
Basically when slide 1 is in front I want to see a little bit part of slide 2

array.map doesn't work on Slider

Which OS ?

Version

Which versions are you using:

  • react-native-slick v?
  • react-native v0.?.?

Expected behaviour

Actual behaviour

How to reproduce it>

To help us, please fork this component, modify one example in examples folder to reproduce your issue and include link here.

Steps to reproduce

Error by ViewPagerAndroid that's removed from RN 0.61

Which OS

Macos

Version

  • react-native-slick v1.0.2
  • react-native v0.61.1

Expected behaviour

No errors on Android

Actual behaviour

Current version raise error for "ViewPagerAndroid"

Error details:
Invariant Violation: VoewPagerAndroid has been removed from React Native.
It can now be installed and imported from 'react-native-viewpager' instead of 'react-native'

How to reproduce it>

It will only appear in Android platform

Images not show when set dynamically

Hi, when I set statics images its work well but when I try to load images from the server using API and try to set them it will not work here is my code

const self = this;
    var loadOrderList = {
        method: "GET",
        url: Location_URL,
        headers: {
            'Accept':'application/json',
            'Content-Type':'application/json'
        },
        json: true
    };

    axios(loadOrderList)
    .then(function (response) {
        self.setState({
          imageBanner: response.data.banneres,
          homeCategory: response.data.homeCategory
        })

        console.log(self.state.imageBanner, self.state.imgList);
    })
    .catch(function (error) {
      //console.log(error);
    });

Set images to slider

<Slick style={styles.wrapper} height={500} loop={true} autoplay={true}>
                  {
                    this.state.imageBanner.map((item, i) => <Slide
                      loadHandle={this.loadHandle}
                      loaded={!!this.state.loadQueue[i]}
                      uri={item}
                      i={i}
                      key={i} />)
                  }
                </Slick>

Output
screen shot 2018-05-24 at 1 57 30 pm

Plz tell me how to fix this issue thanks

question about "react-native init AwsomeProject"

I am looking for a slick library for my existing react app. I checked your example, however it needs "react-native init AwsomeProject" at the beginning. I wonder if it is possible to just use your slider as a component instead of "init" from the very beginning. If so, how should I do it? and how should I register at the end?

thank you.

active dot not working when item is dynamic

Which OS ? Iphone

Version

Which versions are you using:

  • react-native-slick v? 1.0.2
  • react-native v0.?.? 0.58.1

Expected behaviour

active dot must change when I change the page

Actual behaviour

active dot keep in first

<Slick height={'100%'} showsPagination={true} loop={true} activeDotStyle={{backgroundColor: '#000000', width: 13, height: 13, borderRadius: 13/2, overflow: 'hidden'}} dot={ <View style={{backgroundColor: '#bfbfbf', width: 13, height: 13, borderRadius: 13/2, overflow: 'hidden', marginLeft: 5, marginRight: 5}} /> } paginationStyle={{ top: -500, }} showsButtons={false}> { this.state.news.map((item)=> { return ( <View style={{width: '100%', height: '100%', alignItems: 'center', justifyContent: 'center'}}> <Image source={{uri: item.img_en}} style={{ width: 371, height: 576}} resizeMode={'contain'} /> </View> ) }) } </Slick>

Remove ViewProptypes from react-native import

Which OS ?

Version

Which versions are you using:

  • react-native-slick v?
  • react-native v0.?.?

Expected behaviour

Actual behaviour

How to reproduce it>

To help us, please fork this component, modify one example in examples folder to reproduce your issue and include link here.

Steps to reproduce

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.