0

I've an issue regarding an app i'm developing on React Native (w/Expo).

I'm REALLY new to React Native. I don't know if this is an issue of libraries or an issue gathered by my low knowledge.

In my app there's a button to open a modal in which you can set different details. One of this is the ability to search for a Location (in a nested modal).

In the second modal there's a custom InputField component (it's basically a TextInput from RN) inside a custom "HeaderComponent" of my modal.

(The HeaderComponent is simply outside a ScrollView that I added inside a custom ModalComponent)

On Android it works as expected, but when I open the second modal on iOS (my physical device), the keyboard decides to go freaking crazy producing weird jumps/glitches. I'm not sure why this happens but when I move my custom InputField inside the ScrollView along with the "children" components of my custom Modal, the keyboard works well.

Here's a recording of what happens on Android (and the expected result).

Here's a recording of what happens on iOS when I have InputField inside HeaderComponent.

Here's a recording of what happens on iOS when I have InputField outside HeaderComponent (works well).

Here you can file the files. It's now a working example because it would be too wild and complicated but if needed I can share the full github repo.

https://snack.expo.dev/@plungarini/636281

Project components tree for the issue:

> App.js (Ignore this)
  > Modal.js
  > AddLogScreen.js (First Modal)
    > DiveLocation.js
      > Modal.js
      > SearchLocation.js (Second Modal)
        > InputField.js

You will find all the files inside the Snack in the "Files" folder.

PS: I'd prefer to not have the InputField outside HeaderComponent because it shouldn't scroll. A quick workaround could be to have the ScrollView outside the custom ModalComponent but it would be quite annoying because all the other components that uses ModalComponent would need to have a repetition of ScrollView.

EDIT 1

I'm trying everything to localize the issue. What I think is that it may be in the implementation of a parent component. Inside Modal.js:87 I tried to move {HeaderComponent && <HeaderComponent />} on line 94 (inside ScrollView). I did this because initially I tought it was an issue caused by the wrapper (because it was working as expected when in SearchLocation.js I moved the InputField from the Header Component Function to the children of Modal). That doesn't seems the case because I still have the same problem. That's why I think that the problem may be importing HeaderComponent as a param. But I don't personally know any other option.

James Z
  • 12,209
  • 10
  • 24
  • 44
Pietro Lungarini
  • 103
  • 2
  • 12
  • 1
    Keyboard's can be pretty wonky in react native especially iOS. Sorry but the answer to your question is simply trial and error, you might look into using a component like `KeyboardAvoidingView` or making sure that your keyboard isn't placed inside of a scrollview. Trust me every time I design something in react native keyboards and every accompanying feature (proper autofill etc) are one of the biggest pain points to the dev process. – b.stevens.photo Oct 08 '21 at 17:54
  • @t_killah thanks for your advice. As I said I'm pretty new to react-native. I guess I'll move my scrollview out of my Modal component as a temporary solution. Let's see if someone has a better solution :) – Pietro Lungarini Oct 09 '21 at 07:08
  • 1
    Best time to learn is now ;) – b.stevens.photo Oct 12 '21 at 18:45

0 Answers0