英文:
Two clicks instead one when use scrollView in react-native
问题
使用<ScrollView>在React Native中,当键盘打开时,需要点击两次才能执行按钮的操作。第一次点击只是关闭键盘,第二次点击才执行按钮的操作。这两次点击发生在屏幕上的同一点(在按钮上)。我还使用了<KeyboardAvoidingView>。
在<KeyboardAvoidingView>中,根据平台的不同,behavior属性可能设置为'padding'或'height',并且使用了styles.Container样式。
使用ScrollView的情况:
不使用ScrollView的情况(期望行为):
我进行了一些测试:
- 
移除
<ScrollView>后,只需要一次点击,但不会显示按钮在屏幕上,因为有许多组件。 - 
使用
<KeyboardAvoidingView>不改变<ScrollView>的行为。 - 
我尝试使用
<KeyboardAwareScrollView>,但无法安装它。 
所使用的React和React Native版本如下:
"react": "18.2.0",
"react-native": "0.71.2",
英文:
When I use a <ScrollView> in react-native and the keyboard is open, I need use two clicks instead one to execute a button.
The first click only close the keyboard and the second click execute the action from button. The clicks are executed in the same point of the screen(over the button). I use <KeyboardAvoidView> too because.
        <KeyboardAvoidingView
            behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
            style={styles.Container}
        >
            <ScrollView>
                <Components/>
                <Components/>
                <Components/>
                <Components/>
                <Components/>
                <Button/>
            </ScrollView>
        </KeyboardAvoidingView>
With ScrollView
Without ScrollView (Desire behavior)
enter image description here
I make some tests:
- 
When remove
<ScrollView>: I use one click but not display the button on screen because I have many componentes; - 
Uses
<keyboardAvoidingView>not alter the behavior from<ScrollView> - 
I try uses <KeyboardAwareScrollView> but I couldn't install it.
"react": "18.2.0", "react-native": "0.71.2", 
答案1
得分: 1
我相信你在寻找keyboardShouldPersistTaps属性。
英文:
I believe you're looking for the keyboardShouldPersistTaps prop.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论