一、Touchable系列组件
Touchable系列组件可以包裹一层根View,响应点击变化和点击事件
1.1 例如TouchableWithoutFeedback,只可以处理点击或长按响应,不能修改点击的颜色透明度变化,使用代码例子如下:
<TouchableWithoutFeedback
onPress={
()=>{
this.setState({
count: this.state.count+1
})
}
}
onLongPress={
()=>{
Alert.alert('提示','确认删除吗?',[
{text:'取消',onPress:()=>{},style:'cancel'},
{text:'确定',onPress:()=>{}},
])
}
}>
<View style={styles.button}>
<Text style={styles.buttonText}>
我是TouchableWithoutFeedback,单击我
</Text>
</View>
</TouchableWithoutFeedback>
<Text style={styles.text}>您单击了:{this.state.count}次</Text>
</View>
1.1.1、 按钮在请求网络时不允许再次点击,disable
使用例子:
onPress={
()=>{
this.setState({
count: this.state.count+1,
text:'正在登录...',
waiting:true
})
setTimeout(()=>{
this.setState({text:'网络不流畅',waiting:false})
},2000);
}
}
1.2、 TouchableHighlight :设置按下的不透明度,可以通过属性underLayColor设置TouchableHighLight被按下时的不透明度
underlayColor: 设置TouchbleHighLight按下去的颜色,默认黑色
activeOpacity: 不透明度
使用例子:
<TouchableHighlight
activeOpacity={0.7}
underlayColor='green'
onPress={
()=>{
this.setState({
count: this.state.count+1,
text:'正在登录...',
waiting:true
})
setTimeout(()=>{
this.setState({text:'网络不流畅',waiting:false})
},2000);
}
}
react-native入门——touchable系列按钮使用
最新推荐文章于 2024-05-16 01:32:09 发布