使用React Native中的scrollView时,需要点击两次而不是一次。

huangapple go评论48阅读模式
英文:

Two clicks instead one when use scrollView in react-native

问题

使用<ScrollView>在React Native中,当键盘打开时,需要点击两次才能执行按钮的操作。第一次点击只是关闭键盘,第二次点击才执行按钮的操作。这两次点击发生在屏幕上的同一点(在按钮上)。我还使用了<KeyboardAvoidingView>

<KeyboardAvoidingView>中,根据平台的不同,behavior属性可能设置为'padding''height',并且使用了styles.Container样式。

使用ScrollView的情况:

点击这里查看图像描述

不使用ScrollView的情况(期望行为):

点击这里查看图像描述

我进行了一些测试:

  1. 移除<ScrollView>后,只需要一次点击,但不会显示按钮在屏幕上,因为有许多组件。

  2. 使用<KeyboardAvoidingView>不改变<ScrollView>的行为。

  3. 我尝试使用<KeyboardAwareScrollView>,但无法安装它。

所使用的React和React Native版本如下:

"react": "18.2.0",
"react-native": "0.71.2",
英文:

When I use a &lt;ScrollView&gt; 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 &lt;KeyboardAvoidView&gt; too because.

        &lt;KeyboardAvoidingView
            behavior={Platform.OS === &#39;ios&#39; ? &#39;padding&#39; : &#39;height&#39;}
            style={styles.Container}
        &gt;
            &lt;ScrollView&gt;
                &lt;Components/&gt;
                &lt;Components/&gt;
                &lt;Components/&gt;
                &lt;Components/&gt;
                &lt;Components/&gt;
                &lt;Button/&gt;
            &lt;/ScrollView&gt;
        &lt;/KeyboardAvoidingView&gt;

With ScrollView

enter image description here

Without ScrollView (Desire behavior)
enter image description here

I make some tests:

  1. When remove &lt;ScrollView&gt; : I use one click but not display the button on screen because I have many componentes;

  2. Uses &lt;keyboardAvoidingView&gt; not alter the behavior from &lt;ScrollView&gt;

  3. I try uses &lt;KeyboardAwareScrollView&gt; but I couldn't install it.

    &quot;react&quot;: &quot;18.2.0&quot;,
    &quot;react-native&quot;: &quot;0.71.2&quot;,
    

答案1

得分: 1

我相信你在寻找keyboardShouldPersistTaps属性。

英文:

I believe you're looking for the keyboardShouldPersistTaps prop.

huangapple
  • 本文由 发表于 2023年2月18日 02:24:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75488022.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定