0.1.3 • Published 5 years ago

@manjiz/react-native-swiper v0.1.3

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

This swiper is modified based on leecade/react-native-swiper. Not the best Swiper component for React Native.

  • Fixed some remained bugs.
  • Both iOS and android use ScrollView.
  • Removed some inessentials.
  • Used typescript.
  • Be Tested in one online project (lack of test...need more...)
  • Dependencies Versions:
    • react-native@^0.55.4
    • react@^16.3.1

Example

Installation

npm i @manjiz/react-native-swiper --save

Basic Usage

import React, { Component } from 'react'
import {
  View,
  Text
} from 'react-native'
import Swiper from '@manjiz/react-native-swiper'

class Example extends Component {
  onIndexChanged = (index: number) => {
  }

  onMomentumScrollEnd = (e, state) => {
  }

  render () {
    const slideStyle = { flex: 1, justifyContent: 'center', alignItems: 'center' }

    return (
      <Swiper
        autoplay={true}
        autoplayTimeout={6}
      >
        <View style={[slideStyle, { backgroundColor: 'red' }]}>
          <Text>Red</Text>
        </View>
        <View style={[slideStyle, { backgroundColor: 'green' }]}>
          <Text>Green</Text>
        </View>
        <View style={[slideStyle, { backgroundColor: 'blue' }]}>
          <Text>Blue</Text>
        </View>
      </Swiper>
    )
  }
}

export default Example

Properties

Basic

PropTypeDefaultDescription
horizontalbooleantrueIf true, the scroll view's children are arranged horizontally in a row instead of vertically in a column
loopbooleantrueSet to false to disable continuous loop mode
autoplaybooleanfalseSet to true enable auto play mode
indexnumber0Index number of initial slide. And real index would be sync as it changed
loadMinimalbooleanfalseOnly load current index slide , loadMinimalSize slides before and after
loadMinimalSizenumber1see loadMinimal
showsPaginationbooleantrueSet to false make pagination invisible.
autoplayTimeoutnumber2.5Delay between auto play transitions (in second)
autoplayDirectionbooleantrueCycle direction control

Element

PropTypeDefaultDescription
loadMinimalLoaderElementCustom loader to display when slides aren't loaded
dotElement<View ... />Allow custom the dot element
activeDotElement<View ... />Allow custom the active-dot element
renderPagination(index: number, total: number, swiper: any) => JSX.Elementsee source code

Styleus

PropTypeDefaultDescription
widthnumber-If no specify default enable fullscreen mode by flex: 1
heightnumber-If no specify default fullscreen mode by flex: 1
dotColorstring-Allow custom the dot element
activeDotColorstring-Allow custom the active-dot element
containerStyleViewStyle-See default container style in source
scrollViewStyleViewStyle-Style set to ScrollView
styleViewStyle-Style set to ScrollView contentContainerStyle
paginationStyleViewStyle-pagination wrapper style
dotStyleViewStyle-Allow custom the dot element
activeDotStyleViewStyle-Allow custom the active-dot element

Native ScrollView Props

No need to change them.

Event

PropTypeDescription
onIndexChangedindexCalled with the new index when the user swiped

Supported ScrollResponder

PropTypeDescription
onScrollBeginDrage / state / contextWhen animation begins after letting up
onMomentumScrollEnde / state / contextMakes no sense why this occurs first during bounce
onTouchStartCapturee / state / contextImmediately after onMomentumScrollEnd
onTouchStarte / state / contextSame, but bubble phase
onTouchEnde / state / contextYou could hold the touch start for a long time
onResponderReleasee / state / contextYou could hold the touch start for a long time

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

Methods

scrollBy

Scroll by relative index.

Parameters:

NameTypedefaultDescription
indexnumberundefinedoffset index
animatedbooltrueoffset index

Contribution

Local Development

rsync -avr ~/react-native-swiper/dist ~/MyApp/node_modules/@manjiz/react-native-swiper