-
-
Notifications
You must be signed in to change notification settings - Fork 785
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
Backdrop flashes on mount #208
Comments
you could use https://gorhom.github.io/react-native-bottom-sheet/modal import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { View, Text, StyleSheet, Button } from 'react-native';
import BottomSheet, {
BottomSheetModal,
BottomSheetBackdrop,
BottomSheetModalProvider,
} from '@gorhom/bottom-sheet';
const snapPoints = ['40%'];
const App = () => {
// ref
const bottomSheetModalRef = useRef<BottomSheetModal>(null);
const [showModal, setShowModal] = useState(false);
// callbacks
const handlePresentModalPress = useCallback(() => {
bottomSheetModalRef.current?.present();
}, []);
const handleSheetChanges = useCallback((index: number) => {
console.log('handleSheetChanges', index);
}, []);
useEffect(() => {
if(showModal) {
bottomSheetModalRef.current?.present()
}else{
bottomSheetModalRef.current?.dismiss();
}
}, [showModal])
// renders
return (
<BottomSheetModalProvider>
<View style={styles.container}>
{showModal ? (
<Button onPress={handlePresentModalPress} title="Present Modal" />
) : null}
<Button
onPress={() => setShowModal(m => !m)}
title={showModal ? 'Unmount modal' : 'Mount modal'}
/>
</View>
<BottomSheetModal
ref={bottomSheetModalRef}
snapPoints={snapPoints}
onChange={handleSheetChanges}
backdropComponent={BottomSheetBackdrop}
>
<View style={styles.contentContainer}>
<Text>Awesome 🎉</Text>
</View>
</BottomSheetModal>
</BottomSheetModalProvider>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 24,
justifyContent: 'center',
backgroundColor: 'white',
},
contentContainer: {
flex: 1,
alignItems: 'center',
},
});
export default App; |
I am experiencing this bug too. Cannot use v3 and this seems a v2 bug too so... is this going to be fixed @gorhom ? Thought v2 is in maintenance mode for bugs like this one? Basically |
@ferrannp Dose it happened with 'BottomSheetModal' too ? |
It seems that no but with Edit: Mmm actually that seems another problem. If you have more than 2 SnapPoints and you snap to the first, there is no opacity changes in background from first to second... Gonna keep playing with it. @gorhom if using the |
@ferrannp try to modify
|
you can ! |
@gorhom the modal is just much slower to appear (because mount/unmounting) than the BottomSheet. This seems to work: setTimeout(() => {
setBackdropComponent(BottomSheetBackdrop);
// TODO bug in BottomSheet that when it mounts, backdrop flashes
}, 250); Pretty sure there is a way to fix this in v2 (like it is fix in v3). Another thing that seems to work (maybe better): const [backdropOpacity, setBackDropOpacity] = useState(0);
const renderBackdrop = useCallback(
props => <BottomSheetBackdrop {...props} opacity={backdropOpacity} />, [backdropOpacity]
); Then: setBackDropOpacity(0.5);
bottomSheetRef.current?.expand(); |
hi @ferrannp , you do not need to update react-native-bottom-sheet/src/components/bottomSheetBackdrop/BottomSheetBackdrop.tsx Lines 60 to 68 in cbfe80a
i think it get slower because of setting the |
I agree with @ferrannp I have the same issue on v2. It's a little bit better using BottomSheetModal but when you call I think this issue should be reopen. |
@theohdv this is my workaround if you are interested: const [backdropOpacity, setBackDropOpacity] = useState(0);
const renderBackdrop = useCallback(
props => <BottomSheetBackdrop {...props} opacity={backdropOpacity} />,
[backdropOpacity]
);
<BottomSheet
backdropComponent={renderBackdrop}
... Then before calling expand: if (backdropOpacity === 0) {
setBackDropOpacity(0.5);
}
bottomSheetRef.current?.expand(); In this way you do not see the flash when mounting it. |
Thanks for the tips, but in my case I cannot use this workaround because But I tried to call |
@theohdv could you share a reproducible sample code of your use case and i will look into it |
Ok it is working well when Reproducible sample: It is 2 different issues, so I can open a new issues for this one if you want. But I think this issue should be reopen as it's a real bug (and using BottomsheetModal component is a workaround not a fix). Screen.Recording.2021-01-27.at.11.35.03.mov |
thanks @theohdv for providing the reproducible snack ! i will look into it later today |
@gorhom not sure if related but I tried v3 and when you use this example from docs: https://gorhom.github.io/react-native-bottom-sheet/usage even even if not using backdrop, if the BS is initially mounted (first screen) it also flashes. You can just reload JS and you see it flashes. |
hi @ferrannp , @theohdv & @Michael-M-Judd i have submitted a pr to fix this issue on |
i will investigate it shortly |
@gorhom I tried your PR for v2 and it seems to work just fine 👍 🥳 . |
@gorhom when did you plan to release those fixes ? |
@gorhom any idea how to prevent this flash on mount for |
Still existing today, I have the BottomSheet mounted in a page as initially closed but when I navigate to the screen, the backdrop flashes. |
Same here! using Backdrop flashing occurs on First mounting of modal. But other mountings doesn't have this issue. probably relevant to |
I just fixed the issue. It was all about Backdrop flashes if I provide:
But doesn't have any flashing if I provide:
I just shifted all values and Note: backdrop animation doesn't have any differenece between two configs, the only difference is that in first config, backdrop flashes on first mount only. |
Hi, @gorhom! Any updates for this issue? Thanks |
@nickprihodko could you create a new issue and provide a new reproducible sample code following the template issue, thanks |
I also have this issue using BottomSheetModal and with only single snapPoint backdrop doesn't show so i took suggestion of @theMasix and used onChange method to close modal when it dragged down to first index
|
to anyone experiencing this on android, make sure you are using useCallback for the 'renderBackdrop' prop likes the docs say. |
# Why Closes [ENG-11073](https://linear.app/expo/issue/ENG-11073) # How There is a bug in the Gorhom bottom sheet that causes the backdrop component to flash. It was reported a while ago, but it doesn’t seem to be resolved. Here are related issues: gorhom/react-native-bottom-sheet#208 and gorhom/react-native-bottom-sheet#908. I've adjusted the animation to mask the disappearing backdrop component. # Test Plan - Expo Go with empty app ✅
# Why Closes [ENG-11073](https://linear.app/expo/issue/ENG-11073) # How There is a bug in the Gorhom bottom sheet that causes the backdrop component to flash. It was reported a while ago, but it doesn’t seem to be resolved. Here are related issues: gorhom/react-native-bottom-sheet#208 and gorhom/react-native-bottom-sheet#908. I've adjusted the animation to mask the disappearing backdrop component. # Test Plan - Expo Go with empty app ✅
Bug
Adding a backdrop on v2 seems to causes the initial backdrop to flash on mount even though the modal is closed. You can see here, where once I tap "mount" it flashes the backdrop quickly. If I remove the backdrop, it doesn't show up. I've tried doing a custom, more basic backdrop and it doesn't seem to work either (same thing). Note: it's fairly quick here, but in a larger app it seems to take even longer to disappear
I did notice that this issue #118 seems to be related, but I'm on the latest version and still having issues. I tried adding some debugging logs but couldn't get more from it. I have a feeling it's related to the
animatedIndex
value being passed in? That value controls opacity of the backdrop and if it's not 0 on mount it'll flash (what seems to be at full opacity).Environment info
Steps To Reproduce
Go to android (IOS doesn't have the problem on the snack simulator, but if you do it on real simulator or real device you'll see it, press mount, you'll see the screen flicker:
https://snack.expo.io/7UoD9PU0Z
Describe what you expected to happen:
On mount, if the modal is closed I.e. index === -1, we should not show the backdrop flash. The animation code is correct, but the mounting logic seems a little odd
Reproducible sample code
https://snack.expo.io/7UoD9PU0Z
The text was updated successfully, but these errors were encountered: