Skip to content

Commit

Permalink
fix: cleanup modal backhandler listener on unmount (#3049)
Browse files Browse the repository at this point in the history
Co-authored-by: David Gruseck <[email protected]>
  • Loading branch information
dgruseck and David Gruseck authored Jan 26, 2022
1 parent 8d1cfa1 commit 1fd0e2a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,16 @@ export default function Modal({
}).start();
};

const hideModal = () => {
const removeListeners = () => {
if (subscription.current?.remove) {
subscription.current?.remove();
} else {
BackHandler.removeEventListener('hardwareBackPress', handleBack);
}
};

const hideModal = () => {
removeListeners();
const { scale } = animation;

Animated.timing(opacity, {
Expand Down Expand Up @@ -192,6 +195,10 @@ export default function Modal({
prevVisible.current = visible;
});

React.useEffect(() => {
return removeListeners;
}, []);

if (!rendered) return null;

return (
Expand Down

0 comments on commit 1fd0e2a

Please sign in to comment.