在键盘感知滚动视图中的 textInput 后​​按下 React-Native 按钮

IT技术 javascript android ios reactjs react-native
2021-05-08 08:36:22

我有一个问题,我有一个的TextInput按钮KeyboardAwareScrollView我希望用户输入一些文本,然后按下使用TouchableOpacity制作按钮这会将用户刚刚输入的文本向前发送。

问题是在输入文本后,第一次尝试TextInput只会失去焦点。只有在下次记者尝试是butto n实际压。我怎样才能让按钮在第一次按下时做出react?

我正在使用这个包https://github.com/APSL/react-native-keyboard-aware-scroll-view

我的代码如下:

import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'

export default class App extends Component<{}> {
  render() {
    return (
      <KeyboardAwareScrollView>
        <TextInput
          style={{ width: 100, height: 50, backgroundColor: 'blue' }}
        />
        <TouchableOpacity 
          style={{ backgroundColor: 'red', width: 50, height: 50 }}
        />
      </KeyboardAwareScrollView>
    );
  }
}
1个回答

在 ScrollView 上使用keyboardShouldPersistTaps='always'下面是如何做到这一点。

<ScrollView
            keyboardShouldPersistTaps='always' >
</ScrollView>

发生这种情况是因为ScrollView具有先关闭键盘的属性,然后才允许对其子视图进行操作。现在我们正在使用上述属性更改该行为。