Git Product home page Git Product logo

react-swipe-views's Introduction

WARNING DEPRECATION NOTICE

This library is not maintained anymore. Do not use it.

It has not been updated since React 0.14 and breaks with versions of React Router higher than 0.13.

Check out react-swipeable-views instead.

React Swipe Views deprecated

A React component for binded Tabs and Swipeable Views

See Swipe Views on the Android Design Patterns website for inspiration.

Works with optional React Router (v0.13.x only), as a pure component or as a standalone component.

Demo

Live example

Demo

Quick Example

'use strict';

import React from 'react';
import SwipeViews from 'react-swipe-views';

export default class App extends React.Component {
  render() {
    return (
      <SwipeViews>
        <div title="Tab 1">
          Page 1
        </div>
        <div title="Tab 2">
          Page 2
        </div>
        <div title="Tab 3">
          Page 3
        </div>
      </SwipeViews>
    );
  }
}

Install

This component is available as an npm module or a bower component:

npm install react-swipe-views --save

or

bower install react-swipe-views --save

Examples

There are two example projects in the /examples folder. One is using the npm module and webpack as a build tool with react-router, the other uses bower and brunch as a pure component.

TODO List

  • Allow for content to be inserted in the header
  • Write tests

Thanks

License

MIT

react-swipe-views's People

Contributors

captainn avatar damusnet avatar devmessias 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

react-swipe-views's Issues

Routing (react-router) and selectedIndex

First of all thanks for this! It was exactly what I was looking for. I am writing a small web using material-ui and I am hitting all the time the wall with their tabs: http://material-ui.com/#/components/tabs

In order to make this to work with routing, I think it is needed to things: initialSelectedIndex (which the above library just added, so we can route the user when goes to the link directly or refresh the page) and some methodology to keep the tab consistent when the user navigates back and forward (which the library above doesn't handle).

For the first case, it can be handled passing a prop for the initial state (which is not an anti-pattern in this case https://facebook.github.io/react/tips/props-in-getInitialState-as-anti-pattern.html)

constructor(props) {
  super(props);
  this.state = { 
    selectedIndex: this.props.initialSelectedIndex,
    ...
  };
}

For the second case, I am not sure... Here is a pull-request with a proposed solution: https://github.com/jdinard/material-ui/commit/4aad7475877cd3ec425f8b14b009915fda7e8fe8 (but this one looks quite smelly).

The swipe views have different height, so the white empty space will be shown on some swipe views.

Hello damusnet:
I tried to use react-swipe-views to build my mobile web page and it worked well in most of time.

But I encountered a problem that if all the swipe views have different height which determined by the contents of themselves and the difference height value between the one view to another view was significant, so there was a large empty space shown on the view which have few content.

I knew that you used flex property of CSS3 to design the layout ,I thought that it was hard to solve the problem with pure CSS methods if I would still use the flex property as the basis of layout implementation.In consideration of that, I tried to reset the parent of swipe views height value as the current selected swipe view height in the componentDidUpdate callback function but I noticed that the performance seems not good as it caused the div layout repainted.

How do you think about the problem?

Key Tab option

Hello!

first, we have to say you've made a great work!

So here is the problem. When we use the TAB key to "validate" something in a form included in a Swipeview, it bugs, making a swipe to the next tab and SwipeViewsTab disappear .

So is there a possibility to add an option to disable this shortcut in your component?

Doesn't work on Safari when using Webpack and babel-loader

When using Webpack and bebel-loader and let babel-loader handle the polyfilling react-swipe-views fails to work because Number.isInteger does not get polyfilled. The reason is that when using Webpack you normally exclude the node_modules folder as it causes a great slow down on the build if webpack has to parse all the files in that folder.

I'm not sure if there exists a solution for this that doesn't involve polluting my app code with polyfilling or adding a special loader for react-swipe-views alone.

For now i did the later by adding this to my webpack loaders:

{ test: /\.(js|jsx)$/, include: /react\-swipe\-views/, loader: 'babel?cacheDirectory&optional[]=runtime' }

Dynamically changing the number of tabs

Hey,

I realized that when the state changes such that the number of children is dynamic (based on state). The component uses this.props.children.length to measure pageWidthPerCent value. So, it uses the initial number of children and the page width math goes wrong.

Have you considered putting children length in state and update it at right times to calculate the page width.

If you are interested, I can pitch in with a PR.

Thanks

Can react-swipe-views be a pure component?

It would be awesome to use react-swipe-views as a pure component. This means it would not use state to change views, but props.

We would need a way to set the current view and to add a handler to the onChange event.

This makes it easier to test, easier to manage with a router and easier to use in flux apps.

Suggestions for lower end mobile devices. ?

  1. Can we lazy render the tabs somehow ? maybe by adding an addtional async parameter that tells the view to only render the content once the view has been first viewed this will save performance.
  2. Maybe use native snap scroll implementations when available
    for instance :http://dev.w3.org/csswg/css-snappoints/ Allows snapping of points natively in the scrollview, and saves performance on extremely low powered devices. *(Currently only supported by Microsoft devices)

Failed Context Types:

I am trying to use react swipe view in my project. but It is showing these error
bundle.js:11327Warning: Failed Context Types: Invalid context router of type object supplied to SwipeViews, expected function. Check the render method of Tabs.

Can you help me to resolve these ?
error

Unable to load CSS properties

I tried loading this using webpack. It shows like
bug

I tried to include CSS manually by using link tag from node_modules. Still, it was the same.

Any pointers on how do I make this work with webpack ?

I want to use this as a separate component. Gives an Error

My code is the following.

var React = require('react');


var SwipeViews = require('react-swipe-views');
var Tabs = React.createClass({

  componentWillMount : function(){
    this.setState({
      index: 0
    });
  },


  _onIndexChange(selectedIndex) {
    this.setState({
      index: selectedIndex
    });
  },

  render() {
    return (
      <SwipeViews selectedIndex={this.state.index} onIndexChange={this._onIndexChange.bind(this)}>
        <div title="Intro">
          <h1>A React component for binded Tabs and Swipeable Views</h1>
          <p>See <a href="http://developer.android.com/design/patterns/swipe-views.html">
          Swipe Views</a> on the Android Design Patterns website to understand the desired effect.</p>
          <p>This demo is best viewed on a touch enabled device (real or emulated).</p>
          <p style={{textAlign: 'center'}}><a href="https://github.com/damusnet/react-swipe-views"><button>Download</button></a></p>
        </div>
        <div title="Code">
          <h1>Gist</h1>
        </div>
        <div title="Thanks">
          <ul id="thanks">
            <li><a href="https://twitter.com/davidbruant">David Bruant</a> for making me believe in JavaScript</li>
            <li><a href="http://facebook.github.io/react/">React</a> for being awesome</li>
            <li><a href="http://babeljs.io/">Babel</a> for removing so much pain from transpiling/compiling/bundling</li>
            <li><a href="https://github.com/gaearon">Dan Abramov</a> for all the useful ressources, in this case <a href="https://github.com/gaearon/react-hot-boilerplate">React Hot Boilerplate</a></li>
            <li><a href="https://github.com/TheSeamau5">Hassan Hayat</a>'s <a href="https://github.com/TheSeamau5/swipe-pages">Swipe Pages WebComponent</a> for inspiration</li>
            <li><a href="https://github.com/ferrannp">Ferran Negre</a> for helping me debug</li>
          </ul>
          <p style={{textAlign: 'center'}}><a href="#" onClick={(e) => {
            e.preventDefault();
            this.setState({
              index: 0
            });
          }}><button>Back to Intro</button></a></p>
        </div>
      </SwipeViews>
    );
  }
});

module.exports = `Tabs;`

then I am using this in the following

<div><h1> Property Name {this.props.params.property_uuid}</h1> <Tabs></Tabs></div>

this is showing up like the following

image

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.