Giter Club home page Giter Club logo

react-native-smooth-swipe-list's Introduction

react-native-smooth-swipe-list

A swipe-able ListView component modeled after the list view in the iOS Mail app.

  • React Native >= 0.47.0 use 1.4.0

  • React Native < 0.47.0 use 1.3.2

Example

example gif

Running example

git clone [email protected]:ProvataHealth/react-native-smooth-swipe-list.git
cd react-native-smooth-swipe-list
cd Example
npm install
react-native run-ios #or react-native run-android

Installation

npm install --save react-native-smooth-swipe-list

Usage

A SwipeList builds a ListView.DataSource from its props.rowData. The DataSource is primarily the views provided by rowData wrapped by a SwipeRow

...
import SwipeList from 'react-native-smooth-swipe-list';

const ListParent = React.createClass({
    
    propTypes: {
        // takes in array of todo objects
        ...
    },
    
    componentDidMount() {
        // it's a good idea to store the derived rowData to prevent 
        // unnecessary re-renders of the rows in the ListView 
        this.rowData = this.props.todos.map(this.constructRowData);
    },
    
    componentWillReceiveProps(nextProps) {
        // however if you store the derived data you will need to handle the 
        // logic for whether a rowData element needs to be replaced
        ...
    },
    
    constructRowData(todo) {
        return {
            id: todo.id,
            rowView: this.getRowView(todo),
            leftSubView: this.getMarkCompleteButton(), //optional
            rightSubView: this.getArchiveButton(), //optional
            style: styles.row //optional but recommended to style your rows
        };
    },
        
    getRowView() {
        // return the view that will be the face of the row
        ...
    },
    
    getMarkCompleteButton() {
        // return your touchable view, it can be whatever 
        ...
    },
    
    getArchiveButton() {
        ...
    },
    
    render() {
        return <SwipeList rowData={this.rowData} />;
    }
});

API

SwipeList Component

Props

  • FlatList props...
  • rowData - Object with the follow properties:
    • id(required) - Used to identify the rowData
    • setRef - get a reference to the component for this row, receives component, rowData, index
    • rowView(required) - View to use as the row face, rendered inside a SwipeRow
    • [left/right]SubView - View to show when swiping left or right rendered inside a SwipeRow below the rowView
    • [left/right]leftSubViewOptions - Options to customize left and right subviews
      • fullWidth - Will the view span the full width of the row (default false)
      • closeOnPress - Whether the row should close on a press if not followed by a valid gesture (default true)
    • style - Style to apply to the row root view
    • props - Any additional props you want to be set on the SwipeRow
  • gestureTensionParams - Provide to tweak the tension of gestures
    • threshold - The point at which tension will begin to be applied (default subViewWidth)
    • stretch - How far past length the gesture can go (default 1)
    • resistanceStrength The resistance of the gesture past length (between 0-1, default 0.5)
  • scrollEnabled Whether to allow scrolling the ListVIew (default: true)
  • onScrollStateChange - Hook for responding to scroll enabled (true) or disabled (false)
  • swipeRowProps - Props to be set on all SwipeRow's
  • rowStyle - Style to apply to all rows root views
  • onSwipeStateChange - callback for receiving updates about swipe state (SWIPE_START, SWIPE_END, OPEN_ROW_START, OPEN_ROW_END, CLOSE_ROW_START, CLOSE_ROW_END)
  • style - Style applied to the ListView

Methods

  • tryCloseOpenRow() - Close any open row
  • calloutRow(rowNumber, amount):Promise - Open the row by amount and then closes it

SwipeRow Component

Note: In most cases you will want to use the SwipeList and not directly render a SwipeRow. The SwipeList will handle wrapping the various rendered views from your rowData

See React Native PanResponder for information about gesture events.

Props passed into row rendered

  • open - whether the row is open or not
  • openRow - opens the row

Props

  • id - id of the rows data
  • style - Style to apply to the row container
  • rowViewStyle - Style to apply the the inner row view
  • gestureTensionParams - Provide to tweak the tension of gestures
    • threshold - The point at which tension will begin to be applied (default subViewWidth)
    • stretch - How far past length the gesture can go (default 1)
    • resistanceStrength The resistance of the gesture past length (between 0-1, default 0.5)
  • swipeEnabled - Where the row should respond to gestures
  • onGestureStart - Called on initial gesture, before 'onSwipeStart'
  • onSwipeStart - Called when a gesture starts
  • onSwipeUpdate - Called each update of the gesture after start and before end
  • onSwipeEnd - Called when the gesture ends
  • onOpenStart - Called when the row open animation begins
  • onOpenEnd - Called when the row animation ends
  • onCloseStart - Called when the row close animation begins
  • onCloseEnd - Called when the row close ends
  • onCapture - Called when a gesture capture happens
  • [left/right]SubView - View to be rendered for left / right gestures
  • [left/right]SubViewOptions - Option for configuring left and right sub views
    • fullWidth - Will the view span the full width of the row (default false)
    • closeOnPress - Whether the row should close on a press if not followed by a valid gesture (default true)
  • startOpen - Whether the row should start open
  • blockChildEventsWhenOpen - If true will capture gesture events before they reach the rowView (default: true)
  • closeOnPropUpdate - Whether to close the row if new props come in (default true)
  • animateRemoveSpeed - Speed (ms) at which to animate the row when it is removed (default: 150ms)
  • animateAddSpeed - Speed (ms) at which to animate the row when it is removed (default: 150ms)

Methods

  • close(skipAnimation) - Close row. Optionally skip animating
  • open(side, skipAnimation) - Open row on side. Optionally skip animating

Feature Checklist

  • Support left/right sub views of arbitrary size
  • Support basic inertia
  • Minimize the number of renders / updates
  • Animate removal of SwipeRows from SwipeList
  • Animate adding of SwipeRows to SwipeList
  • Passing left/right button props instead of views for ease of use
  • Multi sub view staggered position translation
  • Passing pan information to sub views (e.g. for animating icons, bg color, etc)

react-native-smooth-swipe-list's People

Contributors

andrewgrewell avatar connor-ricks avatar rnmss avatar wswoodruff 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

react-native-smooth-swipe-list's Issues

Remove particular row

I'm having trouble removing a particular row and having that one animate while the others stay put.

What am I doing wrong here?:

swipe-list-demo

Programatically opening row doesn't work

What I have:

image
(the row has been opened by swiping)

What I'm trying to achieve:
Open row when pressing the icon on the right of each row (the three vertical dots icon)

My code:

rowData = this.state.commands.map((x, i) => ({
        id: x.id + '',
        rowView: this.getRowView(x, i),
        rightSubView: this.getOptionsButton(x),
        style: styles.row
}))

getRowView(command, i) {
    return (
         <SwipeableCommand command={command} />
    );
}

render() {
     <SwipeList ref={x => this.swipeList = x} rowData={this.rowData} style={styles.listStyle} />
}

SwipeableCommand.js:

export default class SwipeableCommand extends Component {
    open = () => {
        //This doesn't work!
        this.row.open('right');
    }

    render() {
        return (
            <SwipeRow
                ref={x => this.row = x}
                startCloseTimeout={() => { }}
                clearCloseTimeout={() => { }}
            >
                <View style={styles.viewWrap}>
                   ...markup
                </View>
            </SwipeRow >
        )
    }
}

And whenever I press the '...' button the row just becomes frozen (the touchableopacity button doesnt even work anymore). I have looked inside the source code and couldn't figure out how to solve this, but I found out that animateOpenOrClose(toValue, vx, noBounce) { receives an undefined value for the toValue so it's going to try to animate the row towards undefined.

What am I missing/doing incorrectly?

Update to use FlatList

Yo! Are there plans to update this to use react-native's more performant FlatList?
It's faster, you no longer need to manage a dataSource, the api is much simpler!

Right Button Edge Shrinking

Absolutely stunning implementation! I haven't seen anything come close to the quality of this!

I have this weird case where the rowView shrinks when swiping on the rightSubView

Nothing fancy going on here. I made a simple code snippet for testing and attached a gif. The rowView is a black box containing a white box. When swiping the rightSubView you can see the white view inside the rowView shrink.

Any thoughts?

  constructRowData(job) {
    return {
      style: {flex: 1},
      id: job.jobnumber,
      rowView: (
        <View style={{flex: 1, height: 150, backgroundColor: 'black', marginVertical: 8}}>
          <View style={{flex: 1, margin: 8, backgroundColor: 'white'}} />
        </View>
      ),
      rightSubView: <View style={{height: 150, width: 150, backgroundColor: 'red', marginVertical: 8}} />
    }
  }
 
  render() {
    return <SwipeList rowData={this.rowData} style={style.list}/>
  }

edge_shrinking

Crash in release mode.

environment

react-native: 0.50.3
react: 16.0.0
react-native-smooth-swipe-list: 0.13.1

how to reproduce

Import something from react-native-smooth-swipe-list. Build iOS in release mode, and run. App crashes. (Android not tested.)

Works fine in dev mode.

causes

View.propTypes is undefined.

see: facebook/react-native#16542

[Typescript error] Swipelist not showing

i just implement this library, i follow each step, but list is not showing. if i render something else it will render successfully, but swipelist not working. is this because of this error?

screen shot 2018-11-14 at 3 41 51 pm

here is the complete code in case if i missing something:

import React from 'react';
import createReactClass from 'create-react-class';
import { View, Text, StyleSheet } from 'react-native';
import {Icon} from 'native-base';
import SwipeList from 'react-native-smooth-swipe-list';


const RowList = createReactClass({

    componentDidMount() {
      this.rowData = this.props.array.map(this.constructRowData);
    },

  constructRowData(item) {
      return {
          id: item,
          rowView: this.getRowView(item),
          rightSubView: this.getRemoveButton(),
          style: styles.rowFront //optional but recommended to style your rows
      };
  },
      
  getRowView(item) {
      console.log("Item>> ", item)
      return (
        <View style={styles.rowFront}>
            <Text>{`I am  a SwipeListView`}</Text>
        </View>
      );
  },

  getRemoveButton() {
    return(
      <View style={styles.rowBack}>
          <Icon name="close" style={styles.iconClose} type="FontAwesome" />
          <Text style={{ color: '#FFF', fontFamily: 'Gilroy-extrabold', marginLeft: 5}}>Remove</Text>
      </View>
    );
  },

  render() {
    return <SwipeList rowData={this.rowData}  />;
  }

});

const styles = StyleSheet.create({
  rowBack: {
    backgroundColor: "#5E368E",
    alignItems: 'center',
    justifyContent: 'center',
    flexDirection: 'row'
  },
  iconClose: {
    color: '#FFF',
    fontSize: 24,
    fontWeight: 'bold',
  },
  rowFront: {
    borderBottomColor: '#EEE',
    borderBottomWidth: 1,
    paddingHorizontal: 100,
    paddingVertical: 15,
  }
});

export default RowList;
import RowList from './rowList';
class Watch extends Component {
  state = {
    array: [1,2,3,4,5]
  }

  render() {
    const { flexOne } = styles;
    const {array} = this.state;
    return (
      <View style={flexOne}>
          { array && array.length > 0 ? <RowList array={array} /> : <EmptyView title="watch" text="stories" />}
      </View>
    );
  }
}

version:

"react-native-smooth-swipe-list": "^1.4.7"

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.