Skip to content

Commit

Permalink
feat: 🪝 + useBottomSheetModals
Browse files Browse the repository at this point in the history
  • Loading branch information
zheleznov163 committed Jul 8, 2022
1 parent f9f5c36 commit 0984bf1
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 1 deletion.
2 changes: 1 addition & 1 deletion screens/Profile/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default as useBottomSheetBackButton } from "./useBottomSheetBackButton";
export { default as useBottomSheetModals } from "./useBottomSheetModals";
152 changes: 152 additions & 0 deletions screens/Profile/hooks/useBottomSheetModals.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import { useCallback } from "react";
import { Platform, StyleSheet } from "react-native";
import { useSharedValue } from "react-native-reanimated";
import { useDimensions } from "@react-native-community/hooks";
import { reaction } from "mobx";
import { Phrase, Steps } from "classes";
import { useGlobalBottomsheet } from "hooks";
import { COLOR } from "utils";
import {
AddWatchAccount,
ChangeAvatar,
ChangeCurrency,
ChangeLanguage,
ChangeWallet,
AddAccount,
} from "../components/organisms";

export default function useBottomSheetModals() {
const gbs = useGlobalBottomsheet();

const { screen } = useDimensions();
const animatedPosition = useSharedValue(screen.height);

const close = useCallback(() => gbs.close(), []);

const changeAvatar = useCallback(() => {
gbs.setProps({
enablePanDownToClose: true,
snapPoints: [350],
animatedPosition,
backgroundStyle: styles.background,
android_keyboardInputMode: undefined,
children: <ChangeAvatar close={close} />,
});
gbs.snapToIndex(0);
}, []);

const addWatchAccount = useCallback(() => {
gbs.setProps({
enablePanDownToClose: true,
snapPoints: [350],
animatedPosition,
backgroundStyle: styles.background,
android_keyboardInputMode: "adjustResize",
children: () => <AddWatchAccount close={close} />,
});
gbs.snapToIndex(0);
}, []);

const changeWallet = useCallback(() => {
gbs.setProps({
enablePanDownToClose: true,
snapPoints: ["95%"],
animatedPosition,
backgroundStyle: styles.background,
android_keyboardInputMode: "adjustResize",
children: () => <ChangeWallet close={close} />,
});
gbs.snapToIndex(0);
}, []);

const changeLanguage = useCallback(() => {
gbs.setProps({
enablePanDownToClose: true,
snapPoints: ["95%"],
animatedPosition,
backgroundStyle: styles.background,
android_keyboardInputMode: "adjustResize",
children: () => <ChangeLanguage close={close} />,
});
gbs.snapToIndex(0);
}, []);

const channgeCurrency = useCallback(() => {
gbs.setProps({
enablePanDownToClose: true,
snapPoints: ["95%"],
animatedPosition,
backgroundStyle: styles.background,
android_keyboardInputMode: "adjustResize",
children: () => <ChangeCurrency close={close} />,
});
gbs.snapToIndex(0);
}, []);

const addAccount = useCallback(() => {
const steps = new Steps(["Choose", "Create", "Name", "Import"]);
const phrase = new Phrase();

const disposer = reaction(
() => steps.title,
(title) => {
switch (title) {
case "Create":
gbs.updProps({ snapPoints: ["95%"] });
phrase.create();
break;
case "Import":
gbs.updProps({ snapPoints: ["95%"] });
phrase.clear();
break;
case "Name":
gbs.updProps({ snapPoints: ["95%"] });
break;
default:
gbs.updProps({ snapPoints: [350] });
break;
}
}
);

gbs.setProps({
enablePanDownToClose: true,
snapPoints: [350],
animatedPosition,
backgroundStyle: styles.background,
android_keyboardInputMode: "adjustResize",
keyboardBehavior:
Platform.OS === "android" ? "interactive" : "fillParent",

onClose: () => {
disposer();
},

children: () => (
<AddAccount steps={steps} phrase={phrase} close={close} />
),
});

gbs.snapToIndex(0);
}, []);

return [
animatedPosition,
{
changeAvatar,
addAccount,
addWatchAccount,
changeWallet,
changeLanguage,
channgeCurrency,
},
close,
] as const;
}

const styles = StyleSheet.create({
background: {
backgroundColor: COLOR.Dark3,
paddingTop: 30,
},
});

0 comments on commit 0984bf1

Please sign in to comment.