Skip to content
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] | Rerendering screen prevents modal to be redisplayed #697

Closed
nastarfan opened this issue Oct 14, 2021 · 12 comments
Closed

[v4] | Rerendering screen prevents modal to be redisplayed #697

nastarfan opened this issue Oct 14, 2021 · 12 comments
Assignees
Labels
bug Something isn't working v4 Written in Reanimated v2

Comments

@nastarfan
Copy link

nastarfan commented Oct 14, 2021

Bug

BottomSheetModal cannot be shown after performing state update on the screen. It is working fine if there is no state update, thus no rendering, but once the screen is rerendered the modal cannot be shown after dismissed/closed.

When there is no state update, the sheet modal is working fine:

without state update

But once we add state update, the sheet modal cannot be displayed:

with state update

Environment info

Library Version
@gorhom/bottom-sheet 4.1.2
react-native 0.65.1
react-native-reanimated 2.2.2
react-native-gesture-handler 1.10.3

Steps To Reproduce

  1. Use BottomSheetModal
  2. Add onChange callback
  3. Update state within the callback
  4. BottomSheetModal can no longer appear

Describe what you expected to happen:

  1. Even if we perform state update on the screen, we can still show the modal

Reproducible sample code

I have created a snack for the code to demonstrate the bug, but somehow it won't run in expo, I am not very familiar with it. If line 39 and 42 (update state code) are commented out, everything works fine.
https://snack.expo.dev/@nastarfan/bottom-sheet-v4-reproducible-issue-template

...
const handlePresentPress = useCallback(() => {
    bottomSheetRef.current?.present();
  }, []);

const handleSheetChanges = useCallback((index: number) => {
    if (index === -1) {
      console.log('closing');
      setBottomSheetState('closed');
    } else {
      console.log('opening');
      setBottomSheetState('opened');
    }
  }, []);

...

 <BottomSheetModal
        ref={bottomSheetRef}
        snapPoints={snapPoints}
        onChange={handleSheetChanges}>
        <View style={styles.sheetContainer}>
          <Text>Hello</Text>
          <Text>
            Ullamco veniam minim sint aliquip fugiat sunt occaecat consectetur
            qui commodo.
          </Text>
        </View>
      </BottomSheetModal>
...

This issue only presents for BottomSheetModal. BottomSheet works fine

@nastarfan nastarfan added the bug Something isn't working label Oct 14, 2021
@gorhom gorhom self-assigned this Oct 14, 2021
@gorhom gorhom added the v4 Written in Reanimated v2 label Oct 14, 2021
@sirajtahrawashmen
Copy link

sirajtahrawashmen commented Oct 15, 2021

+1

@gorhom
Copy link
Owner

gorhom commented Oct 17, 2021

working on fixing this

@gorhom
Copy link
Owner

gorhom commented Oct 18, 2021

this should be fixed with v4.1.3

@gorhom gorhom closed this as completed Oct 18, 2021
@nastarfan
Copy link
Author

Thanks a lot @gorhom , you rock man

bulkinav pushed a commit to bulkinav/react-native-bottom-sheet that referenced this issue Nov 4, 2021
bulkinav pushed a commit to bulkinav/react-native-bottom-sheet that referenced this issue Dec 6, 2021
@He1nr1chK
Copy link

Still happens in v4.1.5

@dlombardi
Copy link

This is still occuring

@portiz-daitan
Copy link

This is still occurring in v4.1.5

@portiz-daitan
Copy link

I was able to fix this issue with the following code:

const selectOption = (option: PickerOption) => {
    selectedOptionRef.current = option;
    close();
  };

const handleChange = useCallback(
    (index: number) => {
      if (index === -1 && selectedOptionRef.current) {
        onChange(selectedOptionRef.current);

        selectedOptionRef.current = undefined;
      }
    },
    [onChange]
  );

Basically, I stored in a ref the value that needs to be updated and, then, delayed the onChange callback until index becomes -1 (which means modal was closed)

@Kjagd
Copy link

Kjagd commented May 24, 2022

I have something that sounds like the same problem. I've found that it's seems to be the opacity which is set to 0 from the fix here: #690 (comment) (I can still press on element and fire listeners for that)

@arjendevos
Copy link

Seems like we're still having this problem on

    "@gorhom/bottom-sheet": "^4.4.0",

@arjendevos
Copy link

But only on iOS

@arjendevos
Copy link

The strange thing is, if we add a console.log to handleSheetChanges it opens but without animation 🤯

  const handleSheetChanges = React.useCallback((index: number) => {
    console.log("....");
  }, []);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v4 Written in Reanimated v2
Projects
None yet
Development

No branches or pull requests

8 participants