react-native-bottom-sheet icon indicating copy to clipboard operation
react-native-bottom-sheet copied to clipboard

[Bug]: Bottom Sheet doesn't open correctly when auto focus is enabled

Open code-504 opened this issue 8 months ago • 6 comments

Version

v5

Reanimated Version

v3

Gesture Handler Version

v2

Platforms

Android

What happened?

I have a bottom sheet with an input field that has auto-focus enabled. When I open my drawer, it causes the bottom sheet to open and then immediately close. However, the second time I open it, the bottom sheet appears, but it doesn't seem to respond correctly.

Reproduction steps

  • Open the snak example
  • Run the app on Android
  • Click: "Open sheet button"
  • (It opens and closes)
  • Click: "Open sheet button" again
  • (it shows the bottom sheet but now is not working properly)

https://github.com/user-attachments/assets/7d234032-794c-45e2-8fdc-3541342ccc6e

Reproduction sample

https://snack.expo.dev/@code-504/bottom-sheet---issue-reproduction-template?platform=android

Relevant log output


code-504 avatar Apr 21 '25 05:04 code-504

I have a workaround: I auto-focus the input after a few milliseconds, and it works but it doesn’t look very smooth.

useEffect(() => {
    setTimeout(() => {
        if (inputRef.current != null) {
            inputRef.current.focus();
        }
    }, 340);
}, []);

code-504 avatar Apr 21 '25 05:04 code-504

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar May 21 '25 09:05 github-actions[bot]

Still an issue. Bumping to prevent it going stale.

levibuzolic avatar May 21 '25 12:05 levibuzolic

tested your sample code on latest release and the issue not occurring, could you please retest again

gorhom avatar Jun 03 '25 19:06 gorhom

tested your sample code on latest release and the issue not occurring, could you please retest again

Here’s a new Snack: https://snack.expo.dev/@code-504/bottom-sheet---issue-reproduction-template?platform=android

The problem still persists. In this new version, it no longer glitches like in the video I shared when I first reported the bug. However, the auto-focus now only works the first time the bottom sheet is opened. When I press the "Open" button, the text input is not auto-focused.

Tested in a real Android device.

https://github.com/user-attachments/assets/58650571-900c-439b-9be3-82d9d58a6c4a

code-504 avatar Jun 03 '25 19:06 code-504

I'm facing a similar issue. In my case, I'm trying to autofocus a TextInput when the snapIndex changes to 1, but the autofocus doesn't work. Additionally, after manually focusing on the input, if I try to swipe down to change the snapIndex back to 0, the BottomSheetModal closes—even though I've set the props to prevent it from closing on pan down.

mantu-bit avatar Jun 17 '25 06:06 mantu-bit

Im getting the same error on IOS. Using a BottomSheet Text Input component with auto focus. Removing the autofocus fixes the issue. I also get this system log:

[RemoteTextInput] -[RTIInputSystemClient remoteTextInputSessionWithID:performInputOperation:]  perform input operation requires a valid sessionID. inputModality = Keyboard, inputOperation = <null selector>, customInfoType = UIEmojiSearchOperations

Im on version 5.2.4.

https://github.com/user-attachments/assets/51f5faa0-4970-4bbe-abc6-b84ab1bd845a

Francismb avatar Sep 03 '25 01:09 Francismb

Downgrading to 5.1.8 fixes the issue.

Francismb avatar Sep 03 '25 01:09 Francismb

The problem still persists. In this new version, it no longer glitches like in the video I shared when I first reported the bug. However, the auto-focus now only works the first time the bottom sheet is opened. When I press the "Open" button, the text input is not auto-focused.

@code-504 correct, the auto focus prop will only open the component mount, but in BottomSheet the components do not unmount when the sheet is closed. You could use BottomSheetModal component instead for that

gorhom avatar Sep 04 '25 18:09 gorhom