New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@softmedialab/react-native-web-swiper

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@softmedialab/react-native-web-swiper

Simple swiper / slider. Works both on React-Native and React-Native-Web.

  • 0.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
decreased by-69.23%
Maintainers
1
Weekly downloads
 
Created
Source

react-native-web-swiper

Simple swiper / slider. Works both on React-Native and React-Native-Web.

Demo

Hybrid Snack: https://snack.expo.io/@oxyii/react-native-web-swiper

Installation

$ npm i react-native-web-swiper --save

Usage

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import Swiper from 'react-native-web-swiper';

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  slideContainer: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  slide1: {
    backgroundColor: 'rgba(20,20,200,0.3)',
  },
  slide2: {
    backgroundColor: 'rgba(20,200,20,0.3)',
  },
  slide3: {
    backgroundColor: 'rgba(200,20,20,0.3)',
  },
});

export default class Screen extends React.Component {
  render() {
    return (
      <View style={styles.container}>
        <Swiper>
          <View style={[styles.slideContainer,styles.slide1]}>
            <Text>Slide 1</Text>
          </View>
          <View style={[styles.slideContainer,styles.slide2]}>
            <Text>Slide 2</Text>
          </View>
          <View style={[styles.slideContainer,styles.slide3]}>
            <Text>Slide 3</Text>
          </View>
        </Swiper>
      </View>
    );
  }
}

With props

<Swiper
  vertical {/* slide up / down instead left / right */}
  from={1} {/* initial slide is second */}
  loop {/* back to first slide after last */}
  timeout={2} {/* autoplay duration (2 secs) */}
  springConfig={{ speed: 11 }} {/* RN Animated.spring config */}
  minDistanceForAction={0.15} {/* Swipe less that 15% keep active slide */}
  positionFixed {/* Fix mobile safari vertical bounces */}
  controlsProps={{
    DotComponent: ({ index, isActive, onPress }) => <Text onPress={onPress}>Your Custom Dot {index+1}</Text>
  }}
>
  <View style={{ flex: 1 }} /> {/* Slide 1 */}
  <View style={{ flex: 1 }} /> {/* Slide 2 */}
  {/* ... */}
</Swiper>

Dynamic content

The Swiper will not be re-rendered if slides state or props have changed. Slides must control their condition.

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

export class SomeDynamicSlide extends React.Component {
  state = {
    someStateItem: 'someValue',
  };

  render() {
    return (
      <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
        <Text onPress={() => this.setState({ someStateItem: 'newValue' })}>
            {this.state.someStateItem}
        </Text>
      </View>
    );
  }
}

...

import React from 'react';
import { Text, View } from 'react-native';
import Swiper from 'react-native-web-swiper';
import { SomeDynamicSlide } from 'someDynamicSlideFile';

class SwiperWrapper extends React.Component {
  render() {
    return (
      <Swiper>

        <SomeDynamicSlide />

        <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
          <Text>This is static content slide</Text>
        </View>

      </Swiper>
    );
  }
}


Props

PropDefaultTypeDescription
alternatePanfalsebooleanAlternate PAN area
verticalfalsebooleanSwiper vertical layout
from0numberInitial slide index
loopfalsebooleanSet to true to enable continuous loop mode
loopAnimationspringspring | extensionLoop animation variant
timeout0numberDelay between auto play transitions (in second). Set negative value for reverse autoplay :satisfied:. Autoplay disabled by default
gesturesEnabledtruebooleanFunction that returns boolean value. Set to false to disable swiping mechanism. Allow to use Prev / Next buttons only
springConfigAnimated.springTune spring animation on autoplay, touch release or slides changes via buttons
minDistanceToCapture5numberInitiate animation after swipe this distance. It fix gesture collisions inside ScrollView
minDistanceForAction0.2numberMinimal part of swiper width (or height for vertical) must be swiped for changing index. Otherwise animation restore current slide. Default value 0.2 means that 20% must be swiped for change index
positionFixedfalsebooleanSwiper inner container position fixed instead relative. Fix mobile safari vertical bounce
containerStyleViewPropTypes.styleOuter (root) container style
innerContainerStyleViewPropTypes.styleInner container style
swipeAreaStyleViewPropTypes.styleSwipe area style
slideWrapperStyleViewPropTypes.styleEach slide wrapper style
slidesPerView1numberNumber of slides per view (slides visible at the same time on slider's container).
controlsEnabledtruebooleanDots and control buttons visible and enabled
ControlsReact.ComponentCustom controls component
onAnimationStartfunctionAny swiper animation start
onAnimationEndfunctionAny swiper animation end
onIndexChangedfunctionCalled when active index changed
controlsPropsobjectsee below
autoHeightfalsebooleanCalculate height from children elements

Controls Props

Over the swiper we need to create a controls layer. But this layer will block the possibility of swiper layer control. We created 9 controls placeholders to solve this problem: top-left, top, top-right, left, center, right, bottom-left, bottom and bottom-right. You can adjust controls position by placing into relevant placeholder:

<Swiper
  ...
  controlsProps={{
    prevTitle: 'prev button title',
    nextTitle: 'next button title',
    dotsTouchable: true, {/* touch over dot will make swiper move to rel slide */}
    dotsPos: 'top',
    prevPos: false, {/* hide prev button */}
    nextPos: 'top-right',
    cellsStyle: {
      'top': { padding: 5, backgroundColor: 'rgba(0, 0, 0, .3)' },
      'top-left': { /* any custom placeholder style */ },
    },
    cellsContent: {
      'bottom-right': <AnyComponent /> {/* Additional content in placeholder */}
    }
  }}
/>
PropDefaultTypeDescription
cellsStyleobjectControls corners placeholders styles. Allowed keys is: top-left, top, top-right, left, center, right, bottom-left, bottom and bottom-right, allowed values is ViewPropTypes.style
cellsContentobjectControls corners placeholders additional content. Allowed keys is: top-left, top, top-right, left, center, right, bottom-left, bottom and bottom-right, allowed values is string OR React element
dotsPos'bottom' OR 'right' if verticalboolean OR enum('top-left', 'top', 'top-right', 'left', 'center', 'right', 'bottom-left', 'bottom', 'bottom-right')Dots position
prevPos'bottom-left' OR 'top-right' if verticalboolean OR enum('top-left', 'top', 'top-right', 'left', 'center', 'right', 'bottom-left', 'bottom', 'bottom-right')Prev button position
nextPos'bottom-right'boolean OR enum('top-left', 'top', 'top-right', 'left', 'center', 'right', 'bottom-left', 'bottom', 'bottom-right')Next button position
prevTitle'Prev'stringPrev button title
nextTitle'Next'stringNext button title
prevTitleStyleText.propTypes.styleCustomize prev button title
nextTitleStyleText.propTypes.styleCustomize next button title
PrevComponentReact.ComponentCustom prev button component
NextComponentReact.ComponentCustom next button component
firstPrevElementelementCustom prev element on first slide (if not loop)
lastNextElementelementCustom next element on last slide (if not loop)
dotsTouchablefalsebooleanTouches over dots will move swiper to relative slide
dotsWrapperStyleViewPropTypes.styleDots wrapper View style
dotPropsobjectreact-native-elements Badge props
dotActiveStyleobjectAdditional style to active dot. Will be added to dot badgeStyle
DotComponentReact.ComponentCustom dot component
topRowtruebooleanRender top row
centerRowtruebooleanRender center row
bottomRowtruebooleanRender bottom row

Interaction methods

Store a reference to the Swiper in your component by using the ref prop provided by React (see docs):

const swiperRef = useRef(null);

...

<Swiper
  ref={swiperRef}
  ...
/>

Then you can manually trigger swiper from anywhere:

() => {
  swiperRef.current.goTo(1);
  swiperRef.current.goToPrev();
  swiperRef.current.goToNext();
  const index = swiperRef.current.getActiveIndex();
};

Keywords

FAQs

Package last updated on 15 Dec 2020

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