1.0.2 • Published 8 years ago

ray-rn-swipe-view v1.0.2

Weekly downloads
1
License
MIT
Repository
-
Last release
8 years ago

ray-rn-swipe-view

author

ilex.h

install

$ npm install --save ray-rn-swipe-view

Usage

basic

import SwipeView from 'ray-rn-swipe-view';

const NativeButton = NativeButton;
const SwipeoutButton = SwipeViewBtn;

// Buttons
var swipeviewBtns = [
  {
    text: 'Button'
  }
]

// Swipeout component
<SwipeView right={swipeviewBtns}>
  <View>
    <Text>Swipe me left</Text>
  </View>
</SwipeView>

With List

import SwipeView from 'ray-rn-swipe-view';
import { AppColors } from './styles/colors';

const NativeButton = NativeButton;
const SwipeoutButton = SwipeViewBtn;

// Buttons
const btnsDefault = [{ text: 'Button' }];

const btnsTypes = [
  { text: 'Primary', type: 'primary' },
  { text: 'Secondary', type: 'secondary' },
  { text: 'Delete', type: 'delete' }
];

const rows = [
  { text: '基础使用', right: btnsDefault },
  {
    text: '按钮事件',
    right: [
      {
        text: '点击试试',
        onPress(){ alert('button pressed'); },
        type: 'primary'
      }
    ]
  },
  { text: '按钮 types', right: btnsTypes },
  { text: '自定义按钮样式',
    right: [
      {
        text: 'Button',
        backgroundColor: AppColors.buttonGreen,
        color: AppColors.snow,
        underlayColor: AppColors.bloodOrange
      }
    ]
  },
  {
    text: '自定义滑动超出部分颜色',
    right: btnsDefault,
    backgroundColor: AppColors.bloodOrange
  },
  {
    text: 'SwipeView autoClose={true}',
    right: btnsDefault,
    autoClose: true
  },
  {
    text: 'Five buttons (full-width) + autoClose={true}',
    right: [
      { text: '按钮1' },
      { text: '按钮2' },
      { text: '按钮3' },
      { text: '按钮4' },
      { text: '按钮5' }
    ],
    autoClose: true
  },
  {
    text: '自定义Button',
    right: [
      {
        component: <Image style={{ flex: 1 }} source={require('./../images/avatar/ilex.png')} />
      }
    ]
  },
  { text: 'Swipe me right (buttons on left side)', left: btnsDefault},
  { text: 'Buttons on both sides',  left: btnsTypes,  right: btnsTypes }
];

constructor() {
  super();

  //  datasource rerendered when change is made (used to set swipeout to active)
  var ds = new ListView.DataSource({ rowHasChanged: (row1, row2) => true });

  this.state = {
    dataSource: ds.cloneWithRows(rows),
    sectionID: null,
    rowID: null
  };
}

_renderRow = (rowData, sectionID, rowID) => {
  return (
    <SwipeView
      close={!(this.state.sectionID === sectionID && this.state.rowID === rowID)}
      left={rowData.left}
      right={rowData.right}
      rowID={rowID}
      sectionID={sectionID}
      autoClose={rowData.autoClose}
      backgroundColor={rowData.backgroundColor}
      onOpen={(sectionID, rowID) => {
        this.setState({
          sectionID,
          rowID
        });
      }}
      onClose={() => console.log('close')}
      scroll={event => console.log('scroll event')}
    >
      <TouchableWithoutFeedback onPress={() => console.log('press item')}>
        <View style={styles.li} >
          <Text style={styles.liText}>{rowData.text}</Text>
        </View>
      </TouchableWithoutFeedback>
    </SwipeView>
  );
}

// Swipeout component
<ListView
  scrollEnabled
  dataSource={this.state.dataSource}
  renderRow={this._renderRow}
  style={styles.listview}
/>

Props

PropTypeDefaultDescription
autoCloseboolfalseauto close on button press
backgroundColorstring'#dbddde'
closeboolclose swipeview
disabledboolfalsewhether to disable the swipeview
leftarray[]swipeview buttons on left
onOpenfunc(sectionID, rowId, direction: string) => void
onClosefunc(sectionID, rowId, direction: string) => void
rightarray[]swipeview buttons on right
scrollfuncprevent parent scroll
stylestylestyle of the container
sensitivitynumber50change the sensitivity of gesture
buttonWidthnumbereach button width
SwipeView Button props
PropTypeDefaultDescription
backgroundColorstring'#b6bec0'background color
colorstring'#ffffff'按钮内容颜色
componentNode or elementnull按钮自定义内容
onPressfuncnull按钮按下事件
textstring'Click'按钮内容
typestring'default'可取的值:default, delete, primary, secondary
underlayColorstringnull按下按钮的颜色
disabledboolfalse禁用
1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago