question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[v4] | Rerendering screen prevents modal to be redisplayed

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
gorhomcommented, Oct 18, 2021

this should be fixed with v4.1.3

2reactions
gorhomcommented, Oct 17, 2021

working on fixing this

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to prevent modal from re-rendering when I update the ...
Modal is displayed when showModal property in the state changes to true. I update the fieldOne property (also inside the state) when input ......
Read more >
React re-renders guide: everything, all at once - Developer way
Comprehensive guide on React re-renders. The guide explains what are re-renders, what is necessary and unnecessary re-render, ...
Read more >
5 Ways to Avoid React Component Re-Renderings
In this article, I have discussed 5 different methods to prevent unnecessary re-rendering in React components. Most of these solutions capitalize caching, and ......
Read more >
How to stop re-rendering lists in React? - Alex Sidorenko
Components always re-render​​ First, let's simplify our example by removing all props from the Item . We will still update the parent state...
Read more >
Re-rendering Components in ReactJS - GeeksforGeeks
Step 4: Open VS Code go to the explorer in VS Code (press crtl+shift+E). ... How to prevent unwanted re-rendering of components?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found