GithubHelp home page GithubHelp logo

react-swiper's Introduction

react-swiper

Detects and triggers touch events for swiping such as onSwipeLeft, onSwipeDown, etc. with ReactJS

Installation

npm install --save react react-swiper

Usage

Example with defaults

Creating an example component:

var React = require('react');
var Swiper = require('react-swiper');

React.initializeTouchEvents(true);

var Example = React.createClass({

  render: function() {
    return (
      <Swiper className="swipe-container" onSwipeLeft={this.handleLeftSwipe}>
        Hello world!
      </Swiper>
    );
  },

  handleLeftSwipe: function (e) {
    console.log(e);
  }

});

module.exports = Example;

The Swiper component will render a <div/> element by default, this can be changed either by providing the tagName property or the component property.

Example with custom element

Creating a Swiper link (i.e. a swipeable <a/> element):

var React = require('react');
var Swiper = require('react-swiper');

React.initializeTouchEvents(true);

var Example = React.createClass({

  render: function() {
    return (
      <Swiper tagName="a" href="http://example.com" onSwipe={this.handleSwipe}>
        Swipe or click me...
      </Swiper>
    );
  },

  handleSwipe: function (e) {
    console.log(e);
  }

});

module.exports = Example;

Example with custom component

Creating a Swiper from another component:

var React = require('react');
var Swiper = require('react-swiper');
var MyComponent = require('./my-component');

React.initializeTouchEvents(true);

var Example = React.createClass({

  render: function() {
    return (
      <Swiper component={MyComponent} propForMyComponent="hello world!" onSwipe={this.handleSwipe} />
    );
  },

  handleSwipe: function (e) {
    console.log(e);
  }

});

module.exports = Example;

Properties

tagName

Type String

Default "div"

Specifies what type of element the Swiper component should be rendered as. See component below as well.

component

Type ReactComponent

Default undefined

Specifies what component Swiper should be rendered as. See tagName above as well. If both tagName and component are specified the later takes precedence.

onSwipe

Type Function(event)

Default undefined

If provided it's called on all swipes.

Example event:

{
  type: String, // The type of swipe, e.g. "swipeLeft", "swipeUp" or "swipeDownRight"
  timeStampStart: Date, // Timestamp for when the swipe was initiated
  timeStampEnd: Date, // Timestamp for when the swipe was finished,
  initialTouch: Touch, // A Touch object for the initial touch position - https://developer.mozilla.org/en-US/docs/Web/API/Touch
  finalTouch: Touch, // A Touch object for the final touch position
}

onSwipe<direction>

Direction Up, UpRight, Right, DownRight, Down, DownLeft, Left and UpLeft

Type Function(event)

Default undefined

If provided it's called with a swipe event (see example in onSwipe above) for a swipe in the wanted direction. E.g. onSwipeUp is called for swipes in the up direction.

minSwipeLength

Type Number

Default 75

The minimum swipe length that's required for a swipe event to be triggered.

moveThreshold

Type Number

Default 10

The minimum move length in one direction to be considered as the swipe direction, this also affects the required velocity in which the swipe must occur.

License

MIT

react-swiper's People

Contributors

aurelioderosa avatar jamuhl avatar joakimbeng 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  avatar

react-swiper's Issues

Swipe delay on iPod touch

Hello there,

there is about a 2s delay in the pagination dots when swiping on an iPod touch. Swiping two pages fast results in laggy behaviour and being stuck on page 2 (swiping two times to go from page 1 to 3, i.e. fast swiping 1->2->3 goes only to page 2). Everything is smooth on Android. Can anyone reproduce the issue on an iOS device?

Getting a Cannot Find Module 'react/lib/merge' from ... error

I'm trying to incorporate your library into my React project. I installed it through NPM using your recommended command:
npm install --save react react-swiper.
It installs without error.
When I do my build via browserify, I'm getting this error: Getting a Cannot Find Module 'react/lib/merge' from c:\users\212026075\dropbox\textdon\node_modules\react-swiper
I'm using react v0.14.0. I can see that react was not put into a subdirectory of react-swiper (don't know if that was supposed to happen). And when I look at my react folder under node_modules it doesn't have a merge file under lib.

Please advise.

"merge" has been deprecated

I get the error "react/lib/merge" has been depracated. It´s not included in the latest React lib so the module doesn´t work.

Tried installing merge and manually adding merge.js to react/lib but without success.

Not working on iPhone and iPad

onSwipeLeft and onSwipeRight are not working on iPhone and iPad.

Trying to figure out what the root cause is, but I have moved on to use react-swipeable till then.

FYI: react-swipeable does fire multiple events, so be aware. react-swiper seems to be trying to catch the single swiping event.

Overall great component, just not working on these devices for some reason.

Source doesn't match delivered code

Hi there,
I had trouble trouble shooting using this module with React 0.13.3 because your source doesn't match the compiled code you deliver. The source (jsx) using require('object-assign') which is good. Maybe your package.json needs to indicate that - I didn't check. However the transpiled code (js) uses require('react/lib/merge') which doesn't exist in .0.13.3. If you update this repository with your currently transpiled code it should be fixed. I would do it but don't know how to do a pull request. Thanks.
Don

demo

hello ,thanks for your project,but i want to ask have a demo?

Scrolling support

Hello
Great plugin, thanks for sharing! This is not an issue but a use-case question:
Say I use react-swiper on a mobile client. I want the right/left swipe events to pull in/out a menu. Also, I want the up/down swipes to work normally - scroll the page. That's for viewing content which does not fit in one screen, obviously.

I've implemented the left right swipes and noticed that when up/down swipes are ignored they do not bubble to the browser/viewport (as expected), thus up/down scrolling is not working.
In the swipeUp and swipeDown events I can call window.scrollBy(0,y) to force the scroll but the result is a step-by-step scrolling and not a smooth experience as implemented by the browser/viewport.

What would be the best way to use react-swiper and have the up/down scrolling delegated to the browser/viewport, for a smooth user experience?

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.