Giter Club home page Giter Club logo

react-swipe's Introduction

react-swipe

build status npm version Download Count Buy Me A Coffee

Brad Birdsall's Swipe.js as a React component.

Demo

Check out the demo from a mobile device (real or emulated).

Install

npm install react swipe-js-iso react-swipe --save

Usage

Examples

import React from 'react';
import ReactDOM from 'react-dom';
import ReactSwipe from 'react-swipe';

const Carousel = () => {
  let reactSwipeEl;

  return (
    <div>
      <ReactSwipe
        className="carousel"
        swipeOptions={{ continuous: false }}
        ref={el => (reactSwipeEl = el)}
      >
        <div>PANE 1</div>
        <div>PANE 2</div>
        <div>PANE 3</div>
      </ReactSwipe>
      <button onClick={() => reactSwipeEl.next()}>Next</button>
      <button onClick={() => reactSwipeEl.prev()}>Previous</button>
    </div>
  );
};

ReactDOM.render(<Carousel />, document.getElementById('app'));

Props

  • swipeOptions: ?Object - supports all original options from Swipe.js config. If passed object differs from the previous one react-swipe will re-initiate underlying Swipe.js instance with fresh options

  • style: ?Object - object with 3 keys (see defaults):

    • container: ?Object
    • wrapper: ?Object
    • child: ?Object
  • regular props as className, id for root component are also supported

  • childCount: ?Number - use it to explicitely tell react-swipe that it needs to re-initiate underlying Swipe.js instance. For example, by setting the childCount prop to the length of the images array that you pass into react-swipe, re-rendering will take place when the images.length differs from the previous render pass:

<ReactSwipe childCount={images.length}>{images}</ReactSwipe>

Methods

Component proxies all Swipe.js instance methods.

Playground

Configure the ReactSwipe component in a sandbox environment at CodeSandbox.


MIT Licensed

react-swipe's People

Contributors

alirezavalizade avatar ambroos avatar antono avatar auser avatar bell-steven avatar bloomca avatar carly-lee avatar christiaanderidder avatar chrisvoll avatar dazld avatar elyobo avatar gareys avatar hburrows avatar iuriikozuliak avatar jed avatar llernestal avatar madjam002 avatar morajabi avatar mr-taco avatar rhavenz avatar shaharz avatar shoaibkalsekar avatar tbo avatar tomconroy avatar vinhlh avatar vond avatar vongohren avatar voronianski avatar wildhoney avatar yn5 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-swipe's Issues

continuous=true causes Two valid but unequal nodes with the same `data-reactid`

If I use option continuous set on true, I get an error:

Uncaught Error: Invariant Violation: ReactMount: Two valid but unequal nodes with the same `data-reactid`: .1.0.1.0.0.0.2.0.0.0.$0/=1$0.0.0

As I found, my components, which I put as childern to ReactSwipe are doubled, but reactId is not changed. Is there any solution for this problem?

-- Edit --

So, after checking the main Swipe library, I found the children are doubled there and only in case if there are only 2 child elements. I made a fix in my code, so I never have only 2 elements

Two copies of React on the page?

I'm trying to splice this component into an existing project and am curious if anyone has seen this sort of error before?

Warning: React can't find the root component node for data-reactid value `.0.0:$SnapPage3.0`. If you're seeing this message, it probably means that you've loaded two copies of React on the page. At this time, only a single copy of React can be loaded at a time.warning @ e93b7f3c.js:56195ReactMount.findComponentRoot @ e93b7f3c.js:57071ReactMount.findReactNodeByID @ e93b7f3c.js:57038getNodeFromInstance @ e93b7f3c.js:56539findDOMNode @ e93b7f3c.js:64687React.createClass.componentDidMount @ e93b7f3c.js:54121assign.notifyAll @ e93b7f3c.js:10282ON_DOM_READY_QUEUEING.close @ e93b7f3c.js:20036Mixin.closeAll @ e93b7f3c.js:10643Mixin.perform @ e93b7f3c.js:10590batchedMountComponentIntoNode @ e93b7f3c.js:6490Mixin.perform @ e93b7f3c.js:10577ReactDefaultBatchingStrategy.batchedUpdates @ e93b7f3c.js:14610batchedUpdates @ e93b7f3c.js:10082ReactMount._renderNewRootComponent @ e93b7f3c.js:6684wrapper @ e93b7f3c.js:5278ReactMount._renderSubtreeIntoContainer @ e93b7f3c.js:6758ReactMount.render @ e93b7f3c.js:6778wrapper @ e93b7f3c.js:5278renderPageContent @ e93b7f3c.js:111(anonymous function) @ e93b7f3c.js:117__webpack_require__ @ e93b7f3c.js:30(anonymous function) @ e93b7f3c.js:50(anonymous function) @ e93b7f3c.js:53webpackUniversalModuleDefinition @ e93b7f3c.js:7(anonymous function) @ e93b7f3c.js:10
e93b7f3c.js:57074 Uncaught TypeError: Cannot read property 'firstChild' of undefined

Unlike the provided examples, I am attempting to embed the control in another JSX component (just copied the simple example from the README.md to test this out) that looks like this:

const snaprt = require('./__snaprt.jsx');
const React = snaprt.react;
const ReactSwipe = require('react-swipe');

module.exports = React.createClass({
    render: function () {
        return (
            <ReactSwipe
                continuous={false}
            >
                <div>'PANE 1'</div>
                <div>'PANE 2'</div>
                <div>'PANE 3'</div>
            </ReactSwipe>
        );
    }

});

In my example, the page's JavaScript bundle is created using webpack, not browserify. Based on the stack trace, I suspect that somehow the generated bundle is not what I anticipate. But this is just a guess.

Anyone else run into this? Thanks.

Can't get next() working.

I'm trying to modify swipe.js to support next/prev, but can't figure out how to call this.swipe.next() in render(). Any ideas?

How to center images with different unknow height vertically?

<ReactSwipe
  continuous={false}
  disableScroll={true}
  transitionEnd={this.transitionEnd}
  startSlide={start}
  style={{verticalAlign: 'middle', display: 'table-cell'}}
  key={images.length}
>
{
  images.map(function(image, index) {
    return (
       <img src={image} alt="" key={index} />
    );
  })
}
</ReactSwipe>

The images contains different unknow height image, I want to center the image but fail. It seems the image container has the max height of the images. How can I do it?

Uncaught TypeError: (0 , _swipeJsIso2.default) is not a function

Description

react-swipe.js:95 Uncaught TypeError: (0 , _swipeJsIso2.default) is not a functioncomponentDidMount @ react-swipe.js:95invokeComponentDidMountWithTimer @ react.js:5735notifyAll @ react.js:840close @ react.js:13341closeAll @ react.js:16734perform @ react.js:16681batchedMountComponentIntoNode @ react.js:11717perform @ react.js:16668batchedUpdates @ react.js:10161batchedUpdates @ react.js:14385_renderNewRootComponent @ react.js:11876_renderSubtreeIntoContainer @ react.js:11962render @ react.js:11983(anonymous function) @ app.js:29

Demo link

Demo Code not working

Hi,

I am slightly unsure why but the Demo Code is not working for me.

One of the things that is somehow weird is this line:
var carousel = Swipe({id: "mySwipe"}, panes)

Because it actually renders "mySwipe" into the page and does not apply it as ID. And I think this is only for styling all the other entries, but when I render the carousel, I always see all 20 entries and the css which should "hide" them is not applied. I am not sure if this is related to the mySwipe problem, but I thought it isn't.

It might be related to swipe / react versions.

Next/prev buttons over the swipable area

Hey,
I tried to add next/prev arrows out of Swipe tag, Positioned them with css on top of swipable area. If you try to start swiping from arrows - it not possible. Of course, swipe is only available when over images there are no external tags with higher z-index.

Is it possible to extend component with arrows (add additional property in config to toggle their visibility)?
...and continue use swipe even if you start the action from red area?
screen shot 2016-04-07 at 15 22 51

Can't stop swipe for inside range input

Hi,

I have a range input in one on the swipe page, which user can slide from left to right to increase decrease values. Due to the swipe component as a parent component when someone try to slide the range input, page get swiped.

I have tried the disableScroll={true} on the range input component but issue is still the same.

Can anyone please help to find a way to stop the swip if event occur or certain inside elements.

Callback is called 3 times when changing direction

This might not have to be anything to do with this component, but i wonder if you have experienced it or have a better way of working with the callback.
For some reason when I work with actual swiping the callback is called 3 times and this screws up what card is show when I set state in the callback. Have you ever experienced this?

    callback: function(index) {
        this.props.setNewState(index);
    },

Will not calculate the width again if add children Component

Hi ! These days I need to dynamically reload the resources,but the width will not be resized when state changes. I don't know how to descript it in my poor English. There are a part of Codes below.

class SceneCard extends Component{
    constructor(props){
        super(props)
        this.handleFetch=this.handleFetch.bind(this);
    }

    handleFetch(index){
        const {dispatch,page,sceneslist} = this.props;
        let slide_length=sceneslist.length;
        if(index==slide_length-1){
            dispatch(fetchScenelist(page+1));
        }
    render(){
        const {sceneslist} = this.props;
        return <div>
                    {sceneslist&&
                    <ReactSwipe ref="swiper" swipeOptions={{continuous: false,callback:this.handleFetch}}>
                    {sceneslist.map(v=>
                        <div  key={v.id}>
                                   123
                            </div>
                        )}
                    </ReactSwipe>
                    }
                    </main>
        </div>
    }
}

Did I do something wrong?

`shouldUpdate` dont work

shouldUpdate dont work. Cant disable update by return false, because in shouldComponentUpdate used or condition after calling shouldUpdate where (nextProps.children!==this.props.children) always be true.
Use local copy of component with equaling children.length.
Also componentWillReceiveProps always reinit Swiper ((( also patched localy.

Swiping is broken when it is two slides?

Have you ever tried two slides? I just got a case where I have two slides and it duplicates and breaks.
It seems to be broken because of these lines

      //special case if two slides
      if (browser.transitions && options.continuous && slides.length < 3) {
        element.appendChild(slides[0].cloneNode(true));
        element.appendChild(element.children[1].cloneNode(true));
        slides = element.children;
      }

next() & prev() refs reactSwipe shows undefined

reactSwipe as undefined

I'm using Meteor as a framework. Swiping works great!
But I cant seem to figure out the next() & prev() buttons to work.

next() { this.refs.reactSwipe.next() }

Is there a way to trigger next() & prev() without using

refs

How to use slideToIndex

For example I Have 3 tabs, if tab 1 is clicked should slideToIndex 1, if tab 2 is clicked should slidetoindex 2 and so on. I dont know how to use it, please give more example

Why return `React.addons.cloneWithProps(container, ...)`

When trying to use this component and passing a ref to props this causes a warning:

Warning: You are calling cloneWithProps() on a child with a ref. This is dangerous because you're creating a new child which will not be added as a ref to its parent.

Changing the render function like so doesn't break anything and gets rid of the warning:

render: function() {
  this.props.style = styles.container

  var container = React.DOM.div(this.props,
    React.DOM.div({style: styles.wrapper},
      React.Children.map(this.props.children, function(child) {
        return React.addons.cloneWithProps(child, {style: styles.child})
      })
    )
  )

  return container
}

Unless there is a way to call .next() and .prev() without having to keep a ref around.

dynamic content for swipe

Hello,
What I try to make: I have a lot of items to swipe (they can't be splited), and loading all swipe take several seconds, that is very annoying. So I decided to load 3-4 items on init, and then load others if needed while user swipe existing items.

I tried to change state on callback, it changes, but swipe component doesn't want to rerender with new state. I take a look inside react-swipe and saw script working with dom directly.

Quesiton: Is it possible to change swipe data dynamically with your component?

Desktop Swipe support

Hi! Thanks for this component!

I'm currently using another carousel component on a React project but having a few issues on iOS. I just tried this one and it works GREAT! I just noticed that the swipe is limited to touch devices only. Do you have any plans to add swipe support on desktop too?

Tks!

IE9

Your current demo HTML has this downgrade tag,

<meta http-equiv="X-UA-Compatible" content="IE=8">

Which forces IE9 to use an IE8 engine and then nothing works.

Changing this to,

<meta http-equiv="X-UA-Compatible" content="IE=Edge" />

Will make it work just fine in IE9.

slide with multiple elements.

I want to integrate slider with multiple element in a single window. Currently we can show only one element at time. Please help me.

Non-zero "slideToIndex" while mounting breaks the sync.

I wanted to slide to a dynamic index(n) on load/mount. The view displayed the first slide but when I clicked next it moved to n+1 slide. Is this expected? Tweaking the code a bit, I found if the .slide() is called inside componentDidMount it serves the purpose. But is this advisable? Is this an issue with the swipe library?

How to make part of swipe area NOT affect the swipe?

I want to have only the top and bottom of my page allow swiping, so any swipes in the center don't transition. Reason is the middle section will have a game that uses swiping. Top and bottom will be header & footer stuff.

How can I continue swipe when I swipe to last slide with endpoints?

Say I want to create a welcome page on mobile, when I swipe to the last image(welcome3.jpg), I want my next swipe to a new page, but because of the endpoints(continuous={false}), I can't start my next swipe when I swipe to the last image, any helps? Or is react-swipe meet this situation?

<ReactSwipe
  continuous={false}
  transitionEnd={this.transitionEnd}
>
  <img src="welcome1.jpg" alt=""/>
  <img src="welcome2.jpg" alt=""/>
  <img src="welcome3.jpg" alt=""/>
</ReactSwipe>

Shouldn't swipe-js-iso be a dependency?

Since it's absolutely required to function, swipe-js-iso should be declared as a dependency in package.json. Is there any particular reason it's declared as a devDependency, but not a peerDependency or ordinary dependency?

recalculate on componentDidUpdate?

Hi,

swipe.js supports to recalculate dimensions and positions via another call to setup(), if anything in the DOM changes, that makes it necessary.

Could react-swipe support that via something like:

componentDidUpdate() { this.swipe.setup(); }

?

Transition effect

Is there any way to add a transition effect for the incoming element? E.g. incoming element enters screen at 70% size and grows to 100% when it reaches the center of the screen (and reverse if the swipe is not completed)?
I am pretty sure there isn't an already implemented solution for transition effects, I am just asking for some ideas/direction for this.

render 2 items into 4

Description

I used this for a photo lightbox. Weird things happened when I put 2 photos in this component.
1, 2+ are working fine. ONLY 2 photos will be duplicated into 4(repeat one time).

children in react-swipe display in the wrong position

Description

i'm using the react swipe for my application,suppose there are 4 children in ReactSwipe component,each one has a with of 300px,however, when i debug my project on chrome, i found that the whole height is 300*4,and the second one is on the position of (300,300), just like in the diagonal line. can anyone point out where the problem is ?

screenshot link

Support for react-0.14

react-swipe has a hard dependency on react-0.13.3, so I'm unable to update my project to use react-0.14.

Can you suggest a quick-fix for this, until you come up with an upgrade?

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.