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

Fix android issues with dynamic snap points and open keyboard + `onAnimate` values

Open paulrostorp opened this issue 3 years ago • 13 comments

Motivation

I was facing an issue on android when using dynamic snap points and the adjustPan setting when content height changed while the keyboard was open. I think the following video best showcases the problem:

https://user-images.githubusercontent.com/1866649/199200414-1d78a25c-538d-4021-9f27-4c4c9003d52b.mp4

as you can see, the height of the content changes when the validation text appears or disappears, thereby adding or removing about twenty pixels.

I've narrowed down the issue: because of the keyboard height, the appropriate snapPoint index is not found and triggers the intermediary collapse of the sheet.

I've tested this on android and ios:

  • with and without dynamic snap points setting
  • with single and multiple snap points
  • with modal/regular bottom sheet
  • with bottomsheet scrollview

I have not found this to cause any regressions, but there may be a better solution to this problem.

Edit: Upon further investigation, I also found some issues with onAnimate being provided with the wrong values (both ios and android), I've fixed that in https://github.com/gorhom/react-native-bottom-sheet/pull/1163/commits/0c7e1532eaac8cd56488ca4c9221c1afdd2714fc, but I'm starting to think my fixes are not tackling the root issue, @gorhom please advise 🙂

paulrostorp avatar Nov 01 '22 09:11 paulrostorp

for any interested, here is a patch:

@gorhom+bottom-sheet+4.4.5.patch

diff --git a/node_modules/@gorhom/bottom-sheet/src/components/bottomSheet/BottomSheet.tsx b/node_modules/@gorhom/bottom-sheet/src/components/bottomSheet/BottomSheet.tsx
index b166440..ce74512 100644
--- a/node_modules/@gorhom/bottom-sheet/src/components/bottomSheet/BottomSheet.tsx
+++ b/node_modules/@gorhom/bottom-sheet/src/components/bottomSheet/BottomSheet.tsx
@@ -693,9 +693,9 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
         /**
          * store next position
          */
-        animatedNextPosition.value = position;
+        animatedNextPosition.value = position + animatedKeyboardHeight.value;
         animatedNextPositionIndex.value =
-          animatedSnapPoints.value.indexOf(position);
+          animatedSnapPoints.value.indexOf(position + animatedKeyboardHeight.value);

paulrostorp avatar Nov 01 '22 09:11 paulrostorp

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

github-actions[bot] avatar Dec 02 '22 09:12 github-actions[bot]

not stale cc @gorhom

paulrostorp avatar Dec 06 '22 12:12 paulrostorp

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

github-actions[bot] avatar Jan 07 '23 09:01 github-actions[bot]

not stale cc @gorhom

paulrostorp avatar Jan 10 '23 09:01 paulrostorp

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

github-actions[bot] avatar Feb 10 '23 09:02 github-actions[bot]

not stale cc @gorhom

paulrostorp avatar Feb 11 '23 10:02 paulrostorp

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

github-actions[bot] avatar Mar 14 '23 09:03 github-actions[bot]

Not stale

paulrostorp avatar Mar 18 '23 06:03 paulrostorp

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

github-actions[bot] avatar Apr 17 '23 09:04 github-actions[bot]

Hi @paulrostorp, thanks for investigating and submitting this pr, could you please provide a reproducible sample code to test out the issue and validate the proposed solution ? thanks

gorhom avatar Apr 30 '23 13:04 gorhom

Probably it's related with this #1821

XantreDev avatar May 01 '24 12:05 XantreDev

I think it may not be Android only as I'm having this on my app for both platform. It happened when the content size of the sheet changed. In my case, I have a helper text that changed its content depending on the input validation. I think what happened here is its trying to recalculate the sheet size since I've enabled dynamic sizing. The current workaround is to set a fixed height to the content.

https://github.com/gorhom/react-native-bottom-sheet/assets/1400323/e0a19293-d243-462c-876b-5bbfd45de5a9

idrakimuhamad avatar May 17 '24 14:05 idrakimuhamad