React Native 之TouchableOpacity组件

constructor(props){
    super(props);
    this.state = {
      title:'不透明触摸'
    }
    this.activiEvent = this.activiEvent.bind(this);
  }
  render() {
    return (

      
        {/*
        onPress={this.renderPress()}
        onPress={()=>this.activiEvent('点击')}
        onPressIn={()=>this.activiEvent('按下')}
        onPressOut={()=>this.activiEvent('抬起')}
        onLongPress={()=>this.activiEvent('长按')}
        */}
        
          }
          onPress={()=>this.activiEvent('点击')}
          onPressIn={()=>this.activiEvent('按下')}
          onPressOut={()=>this.activiEvent('抬起')}
          onLongPress={()=>this.activiEvent('长按')}
          >
            
              我是文本但可以点击常用事件
            
          
        

        
          {this.state.title}{/*标签内取值要用花括号*/}
        

      

    );
  }

  renderPress(){
    {/*还没点击就弹窗了 花括号注释不能写到函数外 标签内注释用花括号 标签外可以用// */}

    Alert.alert('iOS')
  }

  activiEvent(event){
    this.setState({
      title:event
    })
  }

 

转载于:https://www.cnblogs.com/liuw-flexi/p/11512521.html

你可能感兴趣的:(React Native 之TouchableOpacity组件)