[Bug]: Bottom Sheet doesn't open correctly when auto focus is enabled
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
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);
}, []);
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.
Still an issue. Bumping to prevent it going stale.
tested your sample code on latest release and the issue not occurring, could you please retest again
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
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.
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
Downgrading to 5.1.8 fixes the issue.
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