0.2.2 • Published 9 years ago
rn-switch v0.2.2
#rn-switch 开关组件
效果

例子
import React, {Component} from 'react';
import {
AppRegistry,
View
} from 'react-native';
import {Switch} from 'rn-switch';
class App extends Component{
constructor(props) {
super(props);
this.state={value:1};
}
switchChange(val){
this.setState({value:val})
}
render(){
return (
<View style={{marginTop:20}}>
<Text>{this.state.value}</Text>
<Switch toggleValue={this.state.value}
onChange={this.switchChange.bind(this)}
></Switch>
<Switch toggleValue="0"
width={100}
onBackgroundColor="red"
onChange={this.switchChange.bind(this)}
></Switch>
<Switch toggleValue="1"
width={100}
toggleLable={true}
onChange={this.switchChange.bind(this)}
></Switch>
<Switch toggleValue="1"
onLable="开"
offLable="关"
height={30}
onLableColor="red"
toggleLable={true}
onChange={this.switchChange.bind(this)}
></Switch>
<Switch toggleValue="1"
disabled={true}
toggleLable={true}
onChange={this.switchChange.bind(this)}
></Switch>
</View>
)
}
}
AppRegistry.registerComponent('App', () => App);属性
width:number开关组件宽度height:number开关组件高度duration:number动画速率,默认为200disabled:bool默认falsedisabledStyle:object禁用后的样式onBackgroundColor:string开启状态下的背景颜色offBackgroundColor:string关闭状态下的背景颜色onValue:any开启状态下回调返回的值,默认返回1offValue:any关闭状态下回调返回的值,默认返回0onLable:string默认不开启onLableColor:string开启提示的文字颜色offLable:string默认不开启offLableColor:string关闭提示的文字颜色toggleLable:bool默认为false,即不显示文字提示toggleValue:booltrue为开启状态,false为关闭状态,默认为falseonChange:function(val)修改后触发的回调函数,返回切换后的值