RN-第三方控件示例react-native

RN-常用第三方组件之react-native-swipeout

2017-04-21  本文已影响1882人  精神病患者link常

左右滑动出现按钮,类似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

demo:https://github.com/chjwrr/ThirdPartyToolTest

DDBDBB7C-A4EA-4D92-9D72-A3FCB039FF2E.png
上一篇下一篇

猜你喜欢

热点阅读