[v4] | Rerendering screen prevents modal to be redisplayed
See original GitHub issueBug
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:
But once we add state update, the sheet modal cannot be displayed:
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
- Use
BottomSheetModal
- Add onChange callback
- Update state within the callback
- BottomSheetModal can no longer appear
Describe what you expected to happen:
- 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:
- Created 2 years ago
- Reactions:2
- Comments:12 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
this should be fixed with
v4.1.3
working on fixing this