-
-
Notifications
You must be signed in to change notification settings - Fork 779
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
dynamic snap points cause flickering of backdrop #436
Comments
thanks @schiller-manuel for submitting this bug , i will look into this |
The below component will prevent the flicker on mount. It is by no means foolproof but works for a single snap point use case.
Ensure you also use the below animation config on the bottom sheet itself to align the timing.
|
FYI: still happening on v4 |
And is not only V3 related, that happens in V2 too. One of the possible workarounds is to extend BackdropComponent with a new prop that conditionally turns off interpolation of opacity, and pass this prop when increasing the content height. It is super-hacky but works |
I just created a PR that fixes this for V2: #562, but I believe that it is going to be easy to migrate it to Reanimated 2 if anyone is interested in doing that |
this should be fixed on |
Seems to still be broken for 4.4.5. |
@gorhom any update on this ? And are there going to be a new versions ? |
Slightly improved version of the @benjamin-sweney component. It didn't work from the start but when i changed
AntiFlickerBottomSheetBackdrop.tsx
|
the BottomSheetBackdropl was Flickering when the content height change and unfortunately nothing from the above solutions worked for me so I created my AntiFlickerBottomSheetBackdrop, may it help someone facing the same problem I faced import {
BottomSheetBackdrop,
BottomSheetBackdropProps,
} from '@gorhom/bottom-sheet';
import React, { ComponentProps } from 'react';
import { useAnimatedReaction, useSharedValue } from 'react-native-reanimated';
export const AntiFlickerBottomSheetBackdrop = (
props: BottomSheetBackdropProps & ComponentProps<typeof BottomSheetBackdrop>,
) => {
const adjustedAnimatedIndex = useSharedValue(0);
// when it opening it start from -1 to 0
// when it closing it start from 0 to -1
// 0: is open -1: is close
// when the error happen it jump directly from 0 to -1
// when the problem end it jump back from -1 to 0
useAnimatedReaction(
() => props.animatedIndex.value,
(prepared, pre) => {
if (pre === null) {
// initial state
adjustedAnimatedIndex.value = prepared;
return;
}
const jumpForward = prepared - pre === 1;
const jumpBackward = pre - prepared === 1;
if (pre !== prepared && !jumpBackward && !jumpForward) {
adjustedAnimatedIndex.value = prepared;
}
},
);
return (
<BottomSheetBackdrop {...props} animatedIndex={adjustedAnimatedIndex} />
);
};
// usage
const renderBackdrop: React.FC<BottomSheetBackdropProps> = useCallback(
(p) => (
<AntiFlickerBottomSheetBackdrop
{...p}
pressBehavior={pressBehavior}
disappearsOnIndex={-1}
appearsOnIndex={0}
/>
),
[pressBehavior],
);
<BottomSheetModal
keyboardBehavior="interactive"
keyboardBlurBehavior="restore"
android_keyboardInputMode="adjustResize"
enableDynamicSizing
enablePanDownToClose
animateOnMount
backdropComponent={renderBackdrop}
/> |
@mhsfh having tried your fix, there appears to be an initial flicker of the backdrop for me occasionally on presenting. I haven't been able to figure out a fix for that. |
@gorhom have you had a chance to look at this again? |
+1 - I'm hitting this too. |
I don't understand why they don't make things that are simple and that everyone needs instead of making things so complicated that even a lot of people can't use all of the things that they have created. |
https://github.com/gorhom/react-native-bottom-sheet/issues/436#issuecomment-1894476861 Great solution, but for avoiding issue with TextInput + autofocus you need listen () => props.animatedPosition.value,. And it should be great! |
Guys! Doesn't care about using snap points or dynamic size here! Description: Solution only for avoiding problems with backdrop flickering onAndroid or on IOS systems. This working for cases with backdrop permanently present on screen. Also you can update this solution for cases with changeable backdrop which depends on modal position or another flags
|
I was able to fix this issue on v(4.6.4) by creating a patch:
|
@RUPESH1439 Thanks! It works, I hope it doesn't break something :) |
The issue is still relevant for v5. I'm using custom backdrop component and for quick workaround I used next solution:
|
flashing-backdrop.mp4
Bug
I added a backdrop to the "Dynamic Snap Point" example and experienced flickering of the backdrop when:
Please see the attached screen recording.
The flickering is caused by the
opacity
of the backdrop which is derived fromanimatedIndex
:react-native-bottom-sheet/src/components/bottomSheetBackdrop/BottomSheetBackdrop.tsx
Lines 77 to 81 in b5a6c65
When the bottom sheet is mounted,
contentHeight
is set to0
and thus theanimatedIndex
is calculated as1
.This initializes the backdrop with its target opacity.
When
contentHeight
is updated inhandleOnLayout
and thus the snap points change,animatedIndex
drops to a value below1
and then reaches1
. This causes a change in the backdrop's opacity which looks like it's flickering.When
contentHeight
is increased, the same behavior is shown:When
contentHeight
is decreased,animatedIndex
stays at1
and no flickering occurs:Environment info
Steps To Reproduce
backdropComponent={BottomSheetBackdrop}
Describe what you expected to happen:
no flickering of backdrop
Ideally,
animatedIndex
would not change when the snap points are modified as done here.Maybe when the number of snap points stay the same,
animatedIndex
should stay constant?Reproducible sample code
I modified the example app by adding the backdrop to the dynamic snap point example, please have a look: schiller-manuel@86b628e
The text was updated successfully, but these errors were encountered: