Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextInput with editable set to false does not emit OnPressIn and OnPressOut #33649

Open
michalmaka opened this issue Apr 15, 2022 · 11 comments
Open
Labels
Component: TextInput Related to the TextInput component. Needs: Triage 🔍

Comments

@michalmaka
Copy link
Contributor

Description

Having TextInput component with editable prop set to false has different effect on iOS and Android.
On iOS OnPressIn and OnPressOut are emitted correctly, but on Android they're not triggered.

Version

0.68.1

Output of npx react-native info

It's clearly visible on snack, no need for my workspace configuration

Steps to reproduce

  1. Create TextInput component
  2. Set editable prop to false
  3. Use OnPressIn callback
  4. See no execution of OnPressIn on Android

Snack, code example, screenshot, or link to a repository

https://snack.expo.dev/@michal.maka/textinput-editable-android

@react-native-bot react-native-bot added the Component: TextInput Related to the TextInput component. label Apr 15, 2022
@KanwarBhajneek
Copy link

Setting it to falsy value will work on both Android and iOS. In above snack link editable={null} works on both Android and iOS

@imhazige
Copy link

imhazige commented Oct 6, 2022

Encountered same problem

@tkud04
Copy link

tkud04 commented Jan 20, 2023

Setting it to falsy value will work on both Android and iOS. In above snack link editable={null} works on both Android and iOS

This worked for me on both Android and iOS

@dnwjn
Copy link

dnwjn commented Feb 20, 2023

Setting it to falsy value will work on both Android and iOS. In above snack link editable={null} works on both Android and iOS

This works for me too!

@ray-holland-es
Copy link

ray-holland-es commented May 11, 2023

Have the same problem. Setting it to null for Android makes the input editable and ignores any autofocus of subsequent form field rendering

@hssdiv
Copy link

hssdiv commented Jul 4, 2023

apart from using editable={null}

I also added onFocus={() => Keyboard.dismiss(), as android was pulling up keyboard and still focusing that input

update: apparently there is a better way using:
showSoftInputOnFocus={false}

@SamerJurdi
Copy link

I found a solution to trigger a function on pressing the TextInput with editable set to false for both iOS and android.

  • Wrap the TextInput component with a Pressable component.
  • Put your function in the onPress prop of the Pressable component. (This triggers the function on android)
  • Then add the same function to the onPressIn prop of the TextInput component. (This triggers the function on iOS)

@dplazagarrido
Copy link

I found a solution to trigger a function on pressing the TextInput with editable set to false for both iOS and android.

  • Wrap the TextInput component with a Pressable component.
  • Put your function in the onPress prop of the Pressable component. (This triggers the function on android)
  • Then add the same function to the onPressIn prop of the TextInput component. (This triggers the function on iOS)

This works like a charm! Thx u saved my day

@laurisdedumets
Copy link

Setting editable={null} seems to emit the signal on Android because it doesn't actually prevent the field from being editable, so there is no point of even adding it as a property.

I'm not familiar with the source code of React Native, but I think this is the line that confirms this:

Until this issue is fixed, the workaround of wrapping your input with some sort of Pressable is the only valid option to achieve this functionality.

@adesh1167
Copy link

I found a solution to trigger a function on pressing the TextInput with editable set to false for both iOS and android.

  • Wrap the TextInput component with a Pressable component.
  • Put your function in the onPress prop of the Pressable component. (This triggers the function on android)
  • Then add the same function to the onPressIn prop of the TextInput component. (This triggers the function on iOS)

this saved the day

@M-Arslan04
Copy link

I found a solution to trigger a function on pressing the TextInput with editable set to false for both iOS and android.

  • Wrap the TextInput component with a Pressable component.
  • Put your function in the onPress prop of the Pressable component. (This triggers the function on android)
  • Then add the same function to the onPressIn prop of the TextInput component. (This triggers the function on iOS)

This one works like a charm, Thanks 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: TextInput Related to the TextInput component. Needs: Triage 🔍
Projects
None yet
Development

No branches or pull requests