Files
super-app/App/common/hooks/useBottomSheet.tsx

55 lines
1.8 KiB
TypeScript
Raw Normal View History

import { useState } from "react";
import { View } from "react-native";
import BaseBottomSheetComponent from "../../../components/bottomsheet/BaseBottomSheetComponent";
import { GenericActionPayload } from "../actions/GenericAction";
import { BOTTOMSHEET_ANIMATION_DURATION } from "../constants";
import { ModalView } from "../interface/modals/ModalView";
import { clearBottomSheet, setBottomSheetView } from "../utilities/AlfredUtils";
export const useBottomSheet = (
handleActions: (actionPayload?: GenericActionPayload) => void,
) => {
const [bottomsheet, setBottomSheet] = useState<JSX.Element[]>([]);
const onAnimationEndHandler = (id: number | null) => {
if (!id) return;
setBottomSheetView(id);
};
const addBottomSheet = (modalView: ModalView) => {
setBottomSheet(prevState => [
...prevState,
<View>
<BaseBottomSheetComponent
onBottomSheetAnimationEnd={onAnimationEndHandler}
showModal={true}
onClose={() => removeBottomSheet()}
modalView={modalView}
handleActions={handleActions}
/>
</View>,
]);
};
const removeBottomSheet = () => {
clearBottomSheet();
setBottomSheet(prevState => {
const newState = [...prevState];
newState.pop();
return newState;
});
};
const replaceBottomSheet = (modalView: ModalView) => {
setTimeout(() => {
removeBottomSheet();
NTP-8070 | Rohitaksh | RN integration iOS (#14407) Signed-off-by: kishan kumar <kishan.kumar@navi.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Chirayu <chirayu.mor@navi.com> Co-authored-by: Prakhar Saxena <prakhar.saxena@navi.com> Co-authored-by: Shivam Goyal <shivam.goyal@navi.com> Co-authored-by: vedant aggarwal <vedant.aggarwal@navi.com> Co-authored-by: A Shrihari Raju <shrihari.raju@navi.com> Co-authored-by: Prajjaval Verma <prajjaval.verma@navi.com> Co-authored-by: Raaj Gopal <raaj.gopal@navi.com> Co-authored-by: Aman S <aman.s@navi.com> Co-authored-by: Aman <amankasyapp@gmail.com> Co-authored-by: Sanjay P <sanjay.p@navi.com> Co-authored-by: Varun Jain <varun.jain@navi.com> Co-authored-by: Shiv Natani <shiv.natani@navi.com> Co-authored-by: Hardik Chaudhary <hardik.chaudhary@navi.com> Co-authored-by: Kishan Kumar <kishan.kumar@navi.com> Co-authored-by: Balrambhai Sharma <sharma.balrambhai@navi.com> Co-authored-by: Ujjwal Kumar <ujjwal.kumar@navi.com> Co-authored-by: Aditya Narayan Malik <aditya.narayan@navi.com> Co-authored-by: Ayushman Sharma <ayushman.sharma@navi.com> Co-authored-by: Anmol Agrawal <anmol.agrawal@navi.com> Co-authored-by: Soumya Ranjan Patra <soumya.ranjan@navi.com> Co-authored-by: Sohan Reddy Atukula <sohan.reddy@navi.com> Co-authored-by: Sayed Owais Ali <sayed.owais@navi.com> Co-authored-by: Ankit Yadav <ankit.yadav@navi.com> Co-authored-by: Shaurya Rehan <shaurya.rehan@navi.com> Co-authored-by: saksham-mahajan_navi <saksham.mahajan@navi.com> Co-authored-by: shankar yadav <shankar.yadav@navi.com> Co-authored-by: Mehul Garg <mehul.garg@navi.com> Co-authored-by: Somarapu Vamshi <somarapu.vamshi@navi.com> Co-authored-by: Kshitij Pramod Ghongadi <kshitij.pramod@navi.com> Co-authored-by: Sandeep Kumar <sandeep.ku@navi.com> Co-authored-by: Aparna Vadlamani <aparna.vadlamani@navi.com> Co-authored-by: Siddiboina Susai <siddiboina.susai@navi.com> Co-authored-by: Kamalesh Garnayak <kamalesh.garnayak@navi.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Divyesh Shinde <divyesh.shinde@navi.com> Co-authored-by: Mohit Rajput <mohit.rajput@navi.com> Co-authored-by: Akshita Singh <akshita.singh@navi.com> Co-authored-by: shreyansu raj <shreyansu.raj@navi.com> Co-authored-by: Venkat Praneeth Reddy <venkat.praneeth@navi.com>
2025-01-13 19:00:56 +05:30
}, BOTTOMSHEET_DISMISS_ANIMATION_DURATION); // This delay ensures the first bottom sheet closes before the next one appears.
setTimeout(() => {
addBottomSheet(modalView);
}, BOTTOMSHEET_ANIMATION_DURATION);
// BOTTOMSHEET_ANIMATION_DURATION is for allowing the current bottomsheet to close animatically before opening the new one.
};
return { bottomsheet, addBottomSheet, removeBottomSheet, replaceBottomSheet };
};