react-native 侧滑组件 react-native-swipe-list-view
2017-08-02 17:31
423 查看
一。由于项目需要支持左滑&右滑的list组件,所以上网看了一下,发现了 react-native-swipe-list-view 觉得不错,分享给大家。(1).此库支持单个组件的左滑右滑,也支持list组件的左滑右滑首先看一下效果图:1.支持左滑和右滑,2.支持设置禁止左滑和右滑。3.list组件支持点击其他item时关闭当前item左滑/右滑等等。二。使用1. 安装npm install --save react-native-swipe-list-view或yarn add react-native-swipe-list-view2.使用
/*** Created by zhuoyuan93@gmail.com on 2017/7/2.*/import React from 'react';import {View,Text,ListView,StyleSheet,TouchableOpacity} from 'react-native';import {SwipeListView, SwipeRow} from 'react-native-swipe-list-view';export default class Item extends React.PureComponent {render() {const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});const dataSource = ['a', 'b', 'c'];return (<View style={styles.outView}><SwipeRowleftOpenValue={75}rightOpenValue={-75}disableRightSwipe={true} //禁止向右滑动><View style={styles.rowBack}><Text allowFontScaling={false}>加入</Text><Text allowFontScaling={false}>购物车</Text></View><View style={{alignItems: 'center', backgroundColor: '#CCC', height: 50, justifyContent: 'center'}}><Text>I am a standalone SwipeRow</Text></View></SwipeRow><View style={{height: 20}}/><SwipeListViewdataSource={ds.cloneWithRows(dataSource)}renderRow={ data => (<View style={styles.rowFront}><Text>I am {data} in a SwipeListView</Text></View>)}renderHiddenRow={ data => (<View style={styles.rowBack}><TouchableOpacity onPress={() => alert('left')}><View style={styles.leftView}><Text style={{backgroundColor: 'red'}}>Left</Text></View></TouchableOpacity><View style={styles.leftView}><Text style={{backgroundColor: 'red'}}>Right</Text></View></View>)}leftOpenValue={75}rightOpenValue={-75}/></View>)}}const styles = StyleSheet.create({outView: {flex: 1,marginTop: 22},rowBack: {alignItems: 'center',backgroundColor: '#DDD',flexDirection: 'row',justifyContent: 'space-between',flex: 1},rowFront: {alignItems: 'center',backgroundColor: '#CCC',borderBottomColor: 'black',borderBottomWidth: 1,justifyContent: 'center',height: 50,},leftView: {width: 75,alignItems: 'center',backgroundColor: 'green',height: 50,justifyContent: 'center'}})手动关闭rows在使用的时候如果需要 关闭row,可以使用以下方法调用
closeRow()方法关闭row:
<SwipeListrenderHiddenRow={ (data, secdId, rowId, rowMap) => {<TouchableOpacity onPress={ _ => rowMap[`${secId}${rowId}`].closeRow() }><Text>I close the row</Text></TouchableOpacity>}}/>
rowMap是一个object,结构如下:
{row_hash_1: ref_to_row_1,row_hash_2: ref_to_row_2}每一个
row_hash是一个
<section_id><row_id>结构的字符串如果你使用的是一个单独的
<SwipeRow>,你一个通过定义
ref去调用
closeRow()关闭row
<SwipeRow>的属性:
leftOpenValue
rightOpenValue
stopLeftSwipe
stopRightSwipe
closeOnRowPress
disableLeftSwipe
disableRightSwipe
recalculateHiddenLayout
相关文章推荐
- react-native-swipe-list-view侧滑删除组件使用
- react-native-swipe-list-view侧滑删除组件使用
- react-native-swipe-list-view(二)
- React-Native滑动删除react-native-swipe-list-view
- React Native之常用组件(View)
- ReactNative WebView组件详解
- react-native-scrollable-tab-view组件的简单使用
- React-Native之截图组件view-shot的介绍与使用
- React Native组件(二)View组件解析
- 支持android&ios高度自适应及JS相互调用的组件react-native-webview2
- ReactNative-WebView组件
- ReactNative中SectionList组件
- React-Native系列——自定义View组件开发
- React-native FlatList 组件的下拉刷新onEndReached异常
- ReactNative之FlatList组件使用方法总结
- 【React Native开发】 - ViewParger轮播组件
- ReactNative WebView组件通信
- ReactNative WebView组件详解
- React Native View 组件通过阴影渲染实现组件浮现效果
- React-Native系列Android——自定义View组件开发