取决于一点对你采取的办法,但我要说最好的办法是用动画(这是本机作出反应的一部分)。
你可以做这样的事情:
render(){
var animVal = new Animated.Value(0);
Animated.timing(animVal, {toValue: 1, duration: 300}).start();
var animatedViewStyles =
{
marginLeft: animVal.interpolate({
inputRange: [0, 1],
outputRange: this.state.switchOn ? [100, 0] : [0, 100],
}),
// add some other styles here
color: 'green'
};
}
return (
<Animated.View style={animatedViewStyles}>
<TouchableHighlight onPress(() => this.setState({switchOn: !this.state.switchOn}))><Text>This is my switch</Text></TouchableHighlight>
</Animated.View>
);
查看更多信息的文档https://facebook.github.io/react-native/docs/animated.html。
我会看看那些,但我仍然希望我只是缺少标准的系统和组件。谢谢。 – hippietrail