TouchableOpacity:不透明觸摸
該組件封裝了響應(yīng)觸摸事件;當(dāng)點(diǎn)擊按下的時(shí)候括丁,該組件的透明度會(huì)降低。
- 常用屬性:
- activeOpacity (number):當(dāng)用戶觸摸的時(shí)候,組件的透明度;
- 常用方法:
- onPress:點(diǎn)擊谣沸;
- onPressIn:按下;
- onPressOut:抬起笋颤;
- onLongPress:長按;
//ES5寫法
var main = React.createClass({
getInitialState(){
return{
title:'不透明觸摸'
}
},
render() {
return (
<View style={styles.container}>
<TouchableOpacity
activeOpacity={0.5}
onPress={()=>this.activeEvent('點(diǎn)擊')}
onPressIn={()=>this.activeEvent('按下')}
onPressOut={()=>this.activeEvent('抬起')}
onLongPress={()=>this.activeEvent('長按')}
>
<View style={styles.innerViewStyle}>
<Text style={{color:'white'}}>點(diǎn)擊事件</Text>
</View>
</TouchableOpacity>
<View>
<Text>{this.state.title}</Text>
</View>
</View>
);
},
activeEvent(event){
this.setState({
title:event
})
},