鍍金池/ 問答/HTML5  HTML/ ReactNative的TouchableHightlight組件的onHide

ReactNative的TouchableHightlight組件的onHideUnderlay觸發(fā)不了

我的代碼是這樣的:

import React, { Component } from 'react';
import { AppRegistry, StyleSheet, View, TouchableHighlight, Text } from 'react-native';

export default class LearnRN extends Component {
  
  constructor(props){
      super(props);

      this.state = {
          text:'',
      }

      this.press = this.press.bind(this);

  }
  
  press(){
        this.setState({text:'hello'});
  }

  render(){
      return (
        <View style={styles.container}>
           <TouchableHighlight onHideUnderlay={this.press}>
                 <View style={styles.button}/>
           </TouchableHighlight>
           <Text>{this.state.text}</Text>
        </View>
      );
  }
}

補充:onShowUnderlay也無法觸發(fā),但是onPress沒有問題,這是為什么?

回答
編輯回答
幼梔

你截圖的代碼應該沒問題,你看看你View組件里面調用是不是出問題了

2018年2月28日 13:36
編輯回答
陌離殤

應該用箭頭函數(shù)
<TouchableHighlight onHideUnderlay={this.press}>
寫為 <TouchableHighlight onHideUnderlay={() => this.press()}

2018年1月15日 06:23