-
-
Notifications
You must be signed in to change notification settings - Fork 784
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
[v4] | Keyboard causing bottom-sheet to close down completely when using enableDynamicSizing (Android only) #1602
Comments
Having the same issue 😢 |
We have the same issue |
same issue, it will close when height of bottom sheet is to low |
I have this same issue! It seems to only be an issue on android. When monitoring the I've also found that if you do not use dynamic sizing, and specify a rather tall snappoint, it does not occur, but that sort of defeats the purpose of automatic sizing, and having the keyboard push the modal up just far enough to fit in the keyboard. |
Use BottomSheetTextInput instead of TextInput from react native to fix this. |
hey @mangeshkchauhan. As I mentioned above, using the BottomSheetTextInput doesn't fix the problem :/ |
Correct, it doesn't fix the issue. |
Running into this same issue atm. Anyone have a solution for it? |
I've also just seen this issue. For me, setting |
Same issue here. The problem for is not even about the enableDynamicSizing. As long as the height of the modal is too low, it closes itself upon opening the keyboard. This includes the snapoints. BottomSheetTextInput doesn't fix it neither. |
i have same issue |
I could fix this by adding Otherwise, you need to put the minHeight of the content more than the keyboard height Edit: you will have a small problem when you set enableDismissOnClose to false, the keyboard won't be dismissed when you close the bottom sheet you can fix it by adding this callback to onChange: import debounce from 'lodash/debounce';
const debouncedOnChange = debounce((index) => {
if (index === -1) {
Keyboard.dismiss();
}
}, 10); |
@mhsfh this does work, however if you're using the backdropComponent prop then that component will remain. I tried to just work around this by implementing my own backdrop component but I can't get the modal to show again if im using Guess I'll have to use the larger snap point. |
@dealvz const handleOpen = React.useCallback((): void => {
Keyboard.dismiss();
bottomSheetRef?.current?.present();
bottomSheetRef?.current?.expand();
if (Platform.OS === 'ios') KeyboardManager.setEnable(false);
}, []);
const handleClose = React.useCallback((): void => {
bottomSheetRef?.current?.close();
if (Platform.OS === 'ios') KeyboardManager.setEnable(true);
}, []); and by the way, you will have a small problem when you set enableDismissOnClose to false, the keyboard won't be dismissed when you close the bottom sheet you can fix it by adding this callback to onChange: import debounce from 'lodash/debounce';
const debouncedOnChange = debounce((index) => {
if (index === -1) {
Keyboard.dismiss();
}
}, 10); |
I have same issue with and without enableDynamicSizing. Bottom sheet get dismissed when keyboard is opened in Android. Any workarounds ? @gorhom any workaround would be helpful. |
let me have a look |
could someone provide a repo using Expo Snack: https://snack.expo.io/@gorhom/bottom-sheet-v4-reproducible-issue-template |
@victorkvarghese |
tested it , and it did not dismiss. while you are here, could you test this issue against v5 |
@gorhom <BottomSheetModal
keyboardBehavior="interactive"
keyboardBlurBehavior="restore"
android_keyboardInputMode="adjustResize"
... |
I have |
Here to report the same/similar issue, except I'm seeing it in both Android AND iOS, and can confirm that it seems to only happen when dynamic sizing is enabled. I will note that the UI does not auto-dismiss unless I have some custom
This seems to happen directly as a result of incorrect indices when the keyboard first appears, but only if it's brought up AFTER the bottom sheet has finished rendering/expanding/animating. So either it's brought up manually by tapping into a non-autofocused text input, or in the case of an autofocused input, after the keyboard is dismissed (i.e. in Android) and then brought back by tapping the input field again. As others have mentioned, this seems to be a result of the
@gorhom I tried to create a repro but was unable to even get the template snack to work: it seems to fail on a workletInit function missing, and some Googling suggested using a polyfill, which resulted in the app crashing. This was as far as I was able to diagnose, but I was not able to get that working: https://snack.expo.dev/@jwalt/bottom-sheet-v4-reproducible-issue-template |
I am using 4.5.1. and enableDynamicSizing={true} is required, otherwise the sheet will break in small devices. Will try upgrading to latest versions I had to wrap the view in BottomSheetView to make it visible with enableDynamicSizing={true}. `
` EDIT: upgrading to latest v5 aplha version, keyboard is not dismissing in android. |
Having same issue :( |
Having same issue with enableDynamicSizing on android. Did try upgrading to 5.0.0-alpha but was still seeing this issue. |
For people trying to replace the The relevant parts
useDebounce.ts
|
@ssomarii Glad you got it working! I forgot to include the backdrop component in my previous comment, not sure if that's what was missing |
Can confirm this bug. Happens when the content height is short. Adding some video for reference: Normal behaviour where the sheet content height is big enough big.mp4Buggy behaviour where the sheet content height is small small.mp4Fix as stated by @apetta and @ssomarii const bottomSheetModalRef = useRef();
const [keyboardOpen, setKeyboardOpen] = useState(false);
const [enableDismissOnClose, setEnableDismissOnClose] = useState(true);
const renderBackdrop = useCallback(
(props: any) => (
<CustomBackdrop
{...props}
onPress={() => {
if (!enableDismissOnClose && keyboardOpen) {
setEnableDismissOnClose(true);
}
bottomSheetModalRef.current?.close();
}}
/>
),
[enableDismissOnClose, handleClose, keyboardOpen],
);
useEffect(() => {
if (Platform.OS !== 'android') return;
const keyboardDidShowListener = Keyboard.addListener(
'keyboardDidShow',
() => setKeyboardOpen(true),
);
const keyboardDidHideListener = Keyboard.addListener(
'keyboardDidHide',
() => setKeyboardOpen(false),
);
return () => {
keyboardDidShowListener.remove();
keyboardDidHideListener.remove();
};
}, []);
useEffect(() => {
setEnableDismissOnClose(!keyboardOpen);
}, [keyboardOpen]);
return (
<BottomSheetModal
ref={bottomSheetModalRef}
enableDynamicSizing
enableDismissOnClose={enableDismissOnClose}
backdropComponent={renderBackdrop}
>
{/* your content */}
</BottomSheetModal>
) |
Is this issue being resolved in any alpha tag or pr ? |
Facing this issue on Android |
same issue happening in my android also. |
Related with #1356 |
@gorhom Here's a minium reproducible snack: https://snack.expo.dev/@jeremyplura/bottom-sheet-v4-reproducible-issue-template |
In this snack, even setting explicit snap points doesn't fix the issue: const snapPoints = useMemo(() => [200], []);
<BottomSheetModal
ref={bottomSheetRef}
snapPoints={snapPoints}
> |
Facing Same. Any Solution? |
Ah I just came here, because I thought I am doing something wrong. Happens to me too. Will try out some solutions too. |
Same issue here. |
Still get this bug |
I try with version 5.0.0-alpha.9 and this bug does not occur |
I've been using version 5.0.0-alpha.9 with the enableDynamicSizing parameter wrapped in a BottomSheetView, and it works flawlessly. However, in Android, the animation when the modal is raised upon opening the keyboard isn't smooth. |
I fixed the problem by installing react-native-keyboard-controller and adding keyboardBehavior and keyboardBlurBehavior. <BottomSheetModal
enableDynamicSizing={true}
keyboardBehavior="interactive"
keyboardBlurBehavior="restore"
>
<BottomSheetTextInput />
<BottomSheetModal> |
This is happening in case of |
I can confirm it's not happening anymore for me in the 5.0.0-alpha.10 version. |
Can confirm 5.0.0-alpha.10 fixes this issue. |
@Mirthis , I agree with your point. I am facing the same issue when the view height is less than the keyboard height. |
same issue |
I was able to solve the issue turning on autofocus on the BottomSheetTextInput; |
I upgraded to |
unfortunately, |
Yes, when we set the minimum height of the bottom sheet to be greater than the keyboard height, the keyboard behaves well. |
I'm seeing this on |
Oh... I just spent a while going through the codepaths to see if I can find a solution and tracked it down to what I think is this return value being
I then noticed a few lines above with an early return if the animation is due to the keyboard: react-native-bottom-sheet/src/components/bottomSheet/BottomSheet.tsx Lines 513 to 519 in d8d34fa
I noticed that it requires I wonder if those who did get it working on |
I have just upgraded to <BottomSheetModal snapPoints={newConnectionSnapPoints}
topInset={insets.top}
ref={newConnectionRef}
enableOverDrag={false}
enableHandlePanningGesture={false}
enableContentPanningGesture={true}
enableDynamicSizing={true}
keyboardBlurBehavior={'restore'}
keyboardBehavior={'interactive'}
enablePanDownToClose={true}
handleComponent={() => <View />}
backdropComponent={(props : BottomSheetBackdropProps) => (
<BlurredBackground sheetProps={props} />
)}
onDismiss={resetAddConnection}
index={0}
footerComponent={SheetFooter}
android_keyboardInputMode="adjustResize"
>
<BottomSheetView style={[layout.bottomSheetWrapper, buttons.fixedBottomContainer, { minHeight: 410 }]}> |
I am experiencing this as well, on iOS using 5.0.5. here's my code: import { useThreadsSheet } from '@/components/threads-sheet/threads-sheet-provider'
import { useStores } from '@/models'
import BottomSheet, {
BottomSheetBackdrop,
BottomSheetBackdropProps,
BottomSheetFooter,
BottomSheetFooterProps,
BottomSheetScrollView,
BottomSheetTextInput,
BottomSheetView,
} from '@gorhom/bottom-sheet'
import { Separator } from '@repo/ui/components/ui/separator'
import { Text } from '@repo/ui/components/ui/text'
import { observer } from 'mobx-react-lite'
import { useCallback, useMemo } from 'react'
import { useSafeAreaInsets } from 'react-native-safe-area-context'
export const ThreadsSheet = observer(() => {
const { bottomSheetRef } = useThreadsSheet()
const { threadsStore } = useStores()
const { bottom } = useSafeAreaInsets()
// callbacks
const handleSheetChanges = useCallback((index: number) => {
console.log('handleSheetChanges', index)
}, [])
const renderBackdrop = useCallback(
(props: BottomSheetBackdropProps) => (
<BottomSheetBackdrop
{...props}
disappearsOnIndex={-1}
appearsOnIndex={0}
/>
),
[],
)
const renderFooter = useCallback(
(props: BottomSheetFooterProps) => (
<BottomSheetFooter {...props} bottomInset={bottom}>
<BottomSheetTextInput
style={{
marginTop: 8,
marginBottom: 10,
borderRadius: 10,
fontSize: 16,
lineHeight: 20,
padding: 8,
backgroundColor: 'rgba(151, 151, 151, 0.25)',
color: '#fff',
}}
/>
</BottomSheetFooter>
),
[],
)
const snapPoints = useMemo(() => ['50%', '70%'], [])
return (
<BottomSheet
index={-1}
snapPoints={snapPoints}
ref={bottomSheetRef}
onChange={handleSheetChanges}
backdropComponent={renderBackdrop}
footerComponent={renderFooter}
enablePanDownToClose={true}
backgroundStyle={{
backgroundColor: '#151616',
}}
>
<BottomSheetView
className='bg-secondary'
style={{
flex: 1,
}}
>
<BottomSheetView className='flex-col items-center justify-between mb-2'>
<Text className='text-lg font-semibold mb-3'>Comments</Text>
<Separator className='w-full bg-border-gray' />
</BottomSheetView>
<BottomSheetScrollView>
<Text>{threadsStore.selectedThreadId}</Text>
<Text>{threadsStore.selectedThreadId}</Text>
<Text>{threadsStore.selectedThreadId}</Text>
<Text>{threadsStore.selectedThreadId}</Text>
</BottomSheetScrollView>
</BottomSheetView>
</BottomSheet>
)
}) whenever the keyboard appears, the bottom sheet simply closes entirely. It's unclear what the right path forward is here but wanted to report that this is not at all fixed in the latest version. |
I had the same issue (using the latest version). This fixed it for me too! |
Bug
I've recently refactored old logic behind the bottom sheet modal since I used
useBottomSheetDynamicSnapPoints
and changed it toenableDynamicSizing.
Everything is working fine but when using with Input Field the bottom-sheet is closing only on Android larger devices.Changing the
keyboardBehavior: 'interactive'
to:keyboardBehavior={Platform.OS === 'ios' ? 'interactive' : 'fillParent'}
made unwanted closing to go away but now the modal doesn't look really good since it will take up whole screen. Ideally I want to have modal just above the keyboard, something that I had before with older logic.The linked issue but without using
enableDynamicSizing
is here it's same now for me since'interactive'
doesn't work.Environment info
Steps To Reproduce
BottomSheetTextInput
and regular inputDescribe what you expected to happen:
IOS devices
When I added logging before closing down I get this in console:
LOG [BottomSheetContainer::handleContainerLayout] height:779.8095092773438
LOG [BottomSheetModal::handleDismiss] currentIndexRef:0 minimized:false
LOG [BottomSheetModal::handleDismiss] currentIndexRef:0 minimized:false
LOG [BottomSheetModal::handleDismiss] currentIndexRef:-1 minimized:false
LOG [BottomSheetModal::handleDismiss] currentIndexRef:-1 minimized:false
LOG [BottomSheetModal::handleDismiss] currentIndexRef:1 minimized:false
Not sure if info can be used for debugging. 🤔
Reproducible sample code
Any help would be amazing. 🙏
The text was updated successfully, but these errors were encountered: