admin管理员组文章数量:1310431
I'm currently building a React native mobile app on Android, and I realized that when an input is focused (for the user to type something on his keyboard), the click event doesn't apply on other elements.
For instance, when the user is typing something in an input, then if the user want to click on "Submit button", then the click event only unfocus the input but doesn't trigger the click event on the button.
Is there a way to make both event happen when an input is focused ? (Unfocus and click on element both triggered, like in a webpage)
I found only this topic that seems to be have a similar problem but not working for me or I'm using it wrong ? Any touch events not trigger when the TextInput is on focus
My code looks like something like that :
import React, {useState} from 'react'
import { ScrollView, TextInput, TouchableOpacity} from 'react-native'
export default function App(){
return (
<ScrollView
keyboardShouldPersistTaps="always"
>
<TextInput
placeholder="Here is the input to be focused"
/>
<TouchableOpacity
style={{
backgroundColor : "#03a9f4"
}}
onPress={()=>{
console.log("Click triggered !")
}}
>
Submit form
</TouchableOpacity>
</ScrollView>
)
}
I'm currently building a React native mobile app on Android, and I realized that when an input is focused (for the user to type something on his keyboard), the click event doesn't apply on other elements.
For instance, when the user is typing something in an input, then if the user want to click on "Submit button", then the click event only unfocus the input but doesn't trigger the click event on the button.
Is there a way to make both event happen when an input is focused ? (Unfocus and click on element both triggered, like in a webpage)
I found only this topic that seems to be have a similar problem but not working for me or I'm using it wrong ? Any touch events not trigger when the TextInput is on focus
My code looks like something like that :
import React, {useState} from 'react'
import { ScrollView, TextInput, TouchableOpacity} from 'react-native'
export default function App(){
return (
<ScrollView
keyboardShouldPersistTaps="always"
>
<TextInput
placeholder="Here is the input to be focused"
/>
<TouchableOpacity
style={{
backgroundColor : "#03a9f4"
}}
onPress={()=>{
console.log("Click triggered !")
}}
>
Submit form
</TouchableOpacity>
</ScrollView>
)
}
Share
Improve this question
asked Dec 14, 2021 at 10:29
Julien PepeJulien Pepe
1791 silver badge11 bronze badges
3
- 3 Try keyboardShouldPersistTaps – Sukesh Commented Dec 14, 2021 at 10:36
-
4
Did you get it working? For me
<ScrollView keyboardShouldPersistTaps='handled' >
bined withKeyboard.dismiss();
from stackoverflow./a/50510934/3484824 seems to work (at least on my Note8 Android) – Can Rau Commented Apr 29, 2022 at 4:49 -
Ah sorry guys, I thought I responded you
本文标签: javascriptReact nativeClick not trigger on button when an input is focusedStack Overflow
版权声明:本文标题:javascript - React native - Click not trigger on button when an input is focused - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741833132a2400054.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论