mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-01-15 15:48:05 +00:00
Signed-off-by: Lance Chant <13349722+lancechant@users.noreply.github.com> Co-authored-by: sarendsen <coding-mosses0z@icloud.com> Co-authored-by: Lance Chant <13349722+lancechant@users.noreply.github.com> Co-authored-by: Gauvain <68083474+Gauvino@users.noreply.github.com>
74 lines
1.9 KiB
TypeScript
74 lines
1.9 KiB
TypeScript
import {
|
|
BottomSheetBackdrop,
|
|
type BottomSheetBackdropProps,
|
|
BottomSheetModal,
|
|
} from "@gorhom/bottom-sheet";
|
|
import { useCallback } from "react";
|
|
import { useGlobalModal } from "@/providers/GlobalModalProvider";
|
|
|
|
/**
|
|
* GlobalModal Component
|
|
*
|
|
* This component renders a global bottom sheet modal that can be controlled
|
|
* from anywhere in the app using the useGlobalModal hook.
|
|
*
|
|
* Place this component at the root level of your app (in _layout.tsx)
|
|
* after BottomSheetModalProvider.
|
|
*/
|
|
export const GlobalModal = () => {
|
|
const { hideModal, modalState, modalRef } = useGlobalModal();
|
|
|
|
const handleSheetChanges = useCallback(
|
|
(index: number) => {
|
|
if (index === -1) {
|
|
hideModal();
|
|
}
|
|
},
|
|
[hideModal],
|
|
);
|
|
|
|
const renderBackdrop = useCallback(
|
|
(props: BottomSheetBackdropProps) => (
|
|
<BottomSheetBackdrop
|
|
{...props}
|
|
disappearsOnIndex={-1}
|
|
appearsOnIndex={0}
|
|
/>
|
|
),
|
|
[],
|
|
);
|
|
|
|
const defaultOptions = {
|
|
enableDynamicSizing: true,
|
|
enablePanDownToClose: true,
|
|
backgroundStyle: {
|
|
backgroundColor: "#171717",
|
|
},
|
|
handleIndicatorStyle: {
|
|
backgroundColor: "white",
|
|
},
|
|
};
|
|
|
|
// Merge default options with provided options
|
|
const modalOptions = { ...defaultOptions, ...modalState.options };
|
|
|
|
return (
|
|
<BottomSheetModal
|
|
ref={modalRef}
|
|
{...(modalOptions.snapPoints
|
|
? { snapPoints: modalOptions.snapPoints }
|
|
: { enableDynamicSizing: modalOptions.enableDynamicSizing })}
|
|
onChange={handleSheetChanges}
|
|
backdropComponent={renderBackdrop}
|
|
handleIndicatorStyle={modalOptions.handleIndicatorStyle}
|
|
backgroundStyle={modalOptions.backgroundStyle}
|
|
enablePanDownToClose={modalOptions.enablePanDownToClose}
|
|
enableDismissOnClose
|
|
stackBehavior='push'
|
|
style={{ zIndex: 1000 }}
|
|
>
|
|
{modalState.content}
|
|
</BottomSheetModal>
|
|
);
|
|
};
|