@crossed/sheet
Version:
A Cross Platform(Android & iOS) ActionSheet with a robust and flexible api, native performance and zero dependency code for react native. Create anything you want inside ActionSheet.
51 lines (50 loc) • 1.43 kB
JavaScript
import { useEffect, useState } from "react";
import { actionSheetEventManager } from "../eventmanager";
import { useProviderContext } from "../provider";
const useSheetManager = ({
id,
onHide,
onBeforeShow,
onContextUpdate
}) => {
const [visible, setVisible] = useState(false);
const currentContext = useProviderContext();
useEffect(() => {
if (!id)
return void 0;
const subscriptions = [
actionSheetEventManager.subscribe(
`show_${id}`,
(data, context) => {
if (currentContext !== context)
return;
if (visible)
return;
onContextUpdate == null ? void 0 : onContextUpdate();
onBeforeShow == null ? void 0 : onBeforeShow(data);
setVisible(true);
}
),
actionSheetEventManager.subscribe(`hide_${id}`, (data, context) => {
if (currentContext !== context)
return;
onHide == null ? void 0 : onHide(data);
})
];
return () => {
subscriptions.forEach((s) => {
var _a;
return (_a = s == null ? void 0 : s.unsubscribe) == null ? void 0 : _a.call(s);
});
};
}, [id, onHide, onBeforeShow, onContextUpdate, visible, currentContext]);
return {
visible,
setVisible
};
};
var use_sheet_manager_default = useSheetManager;
export {
use_sheet_manager_default as default
};
//# sourceMappingURL=use-sheet-manager.js.map