Skip to content

Commit

Permalink
refactor: ✨ update bottomsheet by BackButton
Browse files Browse the repository at this point in the history
  • Loading branch information
zheleznov163 committed Jul 8, 2022
1 parent b787feb commit bb6219b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
20 changes: 18 additions & 2 deletions components/moleculs/BottomSheetModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { forwardRef, useCallback, useState } from "react";
import { StyleSheet, View } from "react-native";
import React, { forwardRef, useCallback, useEffect, useState } from "react";
import { BackHandler, StyleSheet, View } from "react-native";
import { observer } from "mobx-react-lite";
import {
BottomSheetModalMethods,
Expand All @@ -23,6 +23,8 @@ export const BottomSheetModal = observer(
const theme = useTheme();
const [isOpen, handleAnimate] = useBackdrop(props.onAnimate);

useBottomSheetBackButton(isOpen);

return (
<>
{isOpen && <Backdrop />}
Expand Down Expand Up @@ -59,6 +61,8 @@ export const BottomSheet = observer(

const [isOpen, handleAnimate] = useBackdrop(props.onAnimate);

useBottomSheetBackButton(isOpen);

return (
<>
{isOpen && <Backdrop />}
Expand Down Expand Up @@ -103,6 +107,18 @@ function useBackdrop(onAnimate: BottomSheetProps["onAnimate"]) {
return [isOpen, handleAnimate] as const;
}

function useBottomSheetBackButton(isOpen: boolean | undefined) {
useEffect(() => {
if (isOpen) {
const handler = BackHandler.addEventListener(
"hardwareBackPress",
() => true
);
return () => handler.remove();
}
}, [isOpen]);
}

const styles = StyleSheet.create({
background: {
borderTopRightRadius: 30,
Expand Down
17 changes: 0 additions & 17 deletions screens/Profile/hooks/useBottomSheetBackButton.ts

This file was deleted.

0 comments on commit bb6219b

Please sign in to comment.