1.0.1 • Published 5 years ago

react-native-slick-slider v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

react-native-slick

Roadmap

see: ROADMAP.md

Changelogs

  • v1.0.0
    • Fix bugs and copy updates from original repo
    • 52b7023, 61a189d Update: using PropTypes from prop-types and Change View.propTypes to ViewPropTypes (@thanks @ahmed3mar).
    • 84840b3 Update README.md - fix links image readme (@thanks @Eric013).
    • react-natie-swiper Fork original repository and change name to react-native-slick.

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.

examples/components/Basic

npm.io

examples/components/Slick

npm.io

examples/components/SlickNumber

npm.io

examples/components/Phone

npm.io

examples/components/LoadMinimal

npm.io

examples/components/PhotoView

npm.io

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

PropDefaultTypeDescription
horizontaltrueboolIf true, the scroll view's children are arranged horizontally in a row instead of vertically in a column.
looptrueboolSet to false to disable continuous loop mode.
index0numberIndex number of initial slide.
showsButtonsfalseboolSet to true make control buttons visible.
autoplayfalseboolSet to true enable auto play mode.

Custom basic style & content

PropDefaultTypeDescription
width-numberIf no specify default enable fullscreen mode by flex: 1.
height-numberIf no specify default fullscreen mode by flex: 1.
style{...}styleSee default style in source.
loadMinimalfalseboolOnly load current index slide , loadMinimalSize slides before and after.
loadMinimalSize1numbersee loadMinimal
loadMinimalLoader<ActivityIndicator />elementCustom loader to display when slides aren't loaded

Pagination

PropDefaultTypeDescription
showsPaginationtrueboolSet to true make pagination visible.
paginationStyle{...}styleCustom styles will merge with the default styles.
renderPagination-functionComplete 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,}} />elementAllow custom the dot element.
activeDot<View style={{backgroundColor: '#007aff', width: 8, height: 8, borderRadius: 4, marginLeft: 3, marginRight: 3, marginTop: 3, marginBottom: 3,}} />elementAllow custom the active-dot element.
dotStyle-objectAllow custom the active-dot element.
dotColor-stringAllow custom the active-dot element.
activeDotColor-stringAllow custom the active-dot element.
activeDotStyle-objectAllow custom the active-dot element.

Autoplay

PropDefaultTypeDescription
autoplaytrueboolSet to true enable auto play mode.
autoplayTimeout2.5numberDelay between auto play transitions (in second).
autoplayDirectiontrueboolCycle direction control.

Control buttons

PropDefaultTypeDescription
showsButtonstrueboolSet 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'}styleCustom styles.
nextButton<Text style={styles.buttonText}>›</Text>elementAllow custom the next button.
prevButton<Text style={styles.buttonText}>‹</Text>elementAllow custom the prev button.

Props of Children

PropDefaultTypeDescription
style{...}styleCustom styles will merge with the default styles.
title{...}elementIf this parameter is not specified, will not render the title.

Basic props of <ScrollView />

PropDefaultTypeDescription
horizontaltrueboolIf true, the scroll view's children are arranged horizontally in a row instead of vertically in a column.
pagingEnabledtrueboolIf true, the scroll view stops on multiples of the scroll view's size when scrolling. This can be used for horizontal pagination.
showsHorizontalScrollIndicatorfalseboolSet to true if you want to show horizontal scroll bar.
showsVerticalScrollIndicatorfalseboolSet to true if you want to show vertical scroll bar.
bouncesfalseboolIf 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.
scrollsToTopfalseboolIf true, the scroll view scrolls to top when the status bar is tapped.
removeClippedSubviewstrueboolIf 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.
automaticallyAdjustContentInsetsfalseboolSet to true if you need adjust content insets automation.
scrollEnabledtrueboolEnables/Disables swiping

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

Supported ScrollResponder

PropParamsTypeDescription
onScrollBeginDrage / state / contextfunctionWhen animation begins after letting up
onMomentumScrollEnde / state / contextfunctionMakes no sense why this occurs first during bounce
onTouchStartCapturee / state / contextfunctionImmediately after onMomentumScrollEnd
onTouchStarte / state / contextfunctionSame, but bubble phase
onTouchEnde / state / contextfunctionYou could hold the touch start for a long time
onResponderReleasee / state / contextfunctionWhen 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:

NameTypedefaultDescription
indexnumberundefinedoffset index
animatedbooltrueoffset 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 ♥.