react-native 侧滑组件 react-native-swipe-list-view
来源:互联网 发布:追溯软件 编辑:程序博客网 时间:2024/06/05 02:43
一。由于项目需要支持左滑&右滑的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-view
/** * 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}> <SwipeRow leftOpenValue={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}}/> <SwipeListView dataSource={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:
<SwipeList renderHiddenRow={ (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
阅读全文
1 0
- react-native 侧滑组件 react-native-swipe-list-view
- react-native-swipe-list-view侧滑删除组件使用
- React-Native滑动删除react-native-swipe-list-view
- React Native View组件实例
- React Native控件之View组件
- ReactNative组件-react-native-scrollable-tab-view
- React-native View组件transform样式
- React-Native基础_4.View组件
- React-Native-swiper React Native 轮播类组件
- React Native]React Native组件之Navigator
- React Native View Style
- React Native 组件生命周期
- react-native 自定义组件
- React native Image组件
- react native 组件生命周期
- react-native 组件demo
- react-native组件笔记
- React Native--组件Component
- mybatis判断相等的问题
- ThreadPoolExecutor(线程池的构建)
- 集合框架—— Collections之sort()、max()、binarySearch()方法
- requireJS多页面应用实例
- mysql索引总结----mysql 索引类型以及创建
- react-native 侧滑组件 react-native-swipe-list-view
- 1170: 最长字符串(指针专题)
- UnicodeDecodeError: 'utf8' codec can't decode byte 0xd6 in position 0: invalid continuation byte
- Android 通过adb发广播的形式开启activity
- QNX system architecture 3
- .NET图像处理库ImageGear for .NET v23.2发布,增加新的PDF压缩功能
- csu1815
- 非常见降维方法:Laplacian Eigenmaps 拉普拉斯特征映射
- 全国省市列表SQL格式