左右滑动出现按钮,类似iOS的cell,
可以自定义滑动出来的component
地址:https://github.com/dancormier/react-native-swipeout
导入
npm install --save react-native-swipeout
使用非常简单,多的就不说了,毕竟github上写的很清楚,看看就知道怎么用了,贴一下代码示例
支持左右滑动,left和right两个属性为数组类型的,支持多个按钮
数组里面是一个对象吧(理解为),支持多个属性,下面的代码只是写了部分的,文字、颜色、背景色等
import SwipeView from 'react-native-swipeout'
constructor(props){
super(props);
this.state={
Rightbuttons:[
{
backgroundColor:'red',
color:'white',
text:'Rbutton1',
onPress:()=>{this.aaaa()}
// 自定义component
component: [<View style={{justifyContent: 'center', height: 130}}>
</View>],
},
{
backgroundColor:'blue',
color:'white',
text:'Rbutton2',
onPress:()=>{this.aaaa()}
},
{
backgroundColor:'green',
color:'white',
text:'Rbutton3',
onPress:()=>{this.aaaa()}
},
],
Leftbuttons:[
{
backgroundColor:'red',
color:'white',
text:'Lbutton1',
onPress:()=>{this.aaaa()}
},
{
backgroundColor:'blue',
color:'white',
text:'Lbutton2',
onPress:()=>{this.aaaa()}
},
{
backgroundColor:'green',
color:'white',
text:'Lbutton3',
onPress:()=>{this.aaaa()}
},
]
}
this.aaaa = this.aaaa.bind(this);
}
aaaa(){
console.log('123');
}
render() {
return (
<View style={styles.container}>
<SwipeView right={this.state.Rightbuttons}>
<View style={styles.swipeStyle}>
<Text>swipe me left</Text>
</View>
</SwipeView>
<SwipeView left={this.state.Leftbuttons}>
<View style={styles.swipeStyle}>
<Text style={{right:10,position:'absolute'}}>swipe me right</Text>
</View>
</SwipeView>
</View>
);
}
更多属性如图:
1F45CDA6-D757-49FD-BFF4-17266B1D7F7F.png EC36A7BA-C0E5-41C2-8CA5-80D6F498FFC7.png swipe.gif DDBDBB7C-A4EA-4D92-9D72-A3FCB039FF2E.png
网友评论
close={!(this.state.sectionID === sectionID && this.state.rowID === rowID)}
right={swipeoutBtns}
rowID={rowID}
sectionID={sectionID}
onOpen={(sectionID, rowID) => {
this.setState({
sectionID,
rowID,
});
}}
onClose={() => console.log('===close') }
scroll={event => console.log('scroll event') }
>
重点应该是 close这个方法
close={!(this.state.sectionID === sectionID && this.state.rowID === rowID)}//关闭滑动拖拽
// left={rowData.left}//在左侧进行拖拽
right={this.state.Rightbuttons} 在右侧进行拖拽
rowID={rowID}
sectionID={sectionID}
autoClose={true}//按钮点击是否自动关闭
backgroundColor={'#fff'}
onOpen={(sectionID, rowID) => {
this.setState({
sectionID,
rowID,
})
}}
onClose={() => console.log('===close')}
scroll={this.props.scroll}
>
这个scroll 是一个方法吧,