回调没有在另一个回调中执行

时间:2018-01-25 21:16:43

标签: react-native

我有一个回调,我传递给这个名为raiseKeyboard的组件。我希望它在键盘显示时执行。

在此代码中,回调不会在**** 1 ****位置执行,但会在**** 2 ****位置成功执行。

class AlbumCreateView extends Component {
      constructor(props){
        super(props)
        this._keyboardDidHide = this._keyboardDidHide.bind(this)
        this._keyboardDidShow = this._keyboardDidShow.bind(this)
      }

  componentWillMount () {
    this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this._keyboardDidShow);
    this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this._keyboardDidHide);
  }

  componentWillUnmount () {
    this.keyboardDidShowListener.remove();
    this.keyboardDidHideListener.remove();
  }

  _keyboardDidShow () {
    this.props.raiseKeyboard //****1****
  }

  _keyboardDidHide () {
    //alert('Keyboard Hidden');
  }
  render(){
    return(
      <View style={styles.flatList}>
        <View style={styles.albumButton}>
          <Text onPress={this.props.raiseKeyboard}> //****2****
            raise modal
          </Text>
        </View>
        <TextInput onSubmitEditing={Keyboard.dismiss}
          placeholder='testing'
          keyboardType='default'
        />

      </View>
    )
  }
}

1 个答案:

答案 0 :(得分:1)

你不需要实际执行这个功能吗?

_keyboardDidShow () {
    this.props.raiseKeyboard() //****1****
  }

注意:最后缺少()