react-native onFocus事件每次都不会触发

时间:2016-12-17 21:05:37

标签: react-native

我使用onFocus来触发向上滚动ScrollView的功能,以便用户在键盘上键入时可以看到TextInput。

输入框的标记如下所示:

<ScrollView ref="scrollView" contentContainerStyle={styles.content}>
 <Input ref='name' onBlur={this.inputBlur.bind(this)} onFocus={this.inputFocused.bind(this, 'name')}   value={this.state.name} onChange={this.onChange.bind(this, 'name')}/>
</ScrollView>

我使用此功能在brl上再次滚动和向下滚动

inputFocused (refName) {
  setTimeout(() => {
    let scrollResponder = this.refs.scrollView.getScrollResponder();
    scrollResponder.scrollResponderScrollNativeHandleToKeyboard(
      findNodeHandle(this.refs[refName]),
      110, //additionalOffset
      true
    );
  }, 50);
}

inputBlur () {
  this.refs.scrollView.scrollTo({x:0,animate:true})
}

但每次键盘出现或TextInput聚焦时都不会触发。

我的输入组件如下所示:

  <TextInput
          placeholderTextColor="#9E9E9E"
          underlineColorAndroid="#BDBDBD"
          placeholder={this.props.placeholder}
          keyboardType={this.props.keyboard}
          style={styles.actionText}
          onChangeText={this.props.onChange}
          value={this.props.value}
          secureTextEntry={this.props.password}
          onSubmitEditing={this.props.onSubmitEditing}
          onFocus={this.props.onFocus}
          onBlur={this.props.onBlur}
        />

如何在每次关注文本字段时运行inputFocued函数?

0 个答案:

没有答案