UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

74 lines 2.44 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var useLoadedNavigation_exports = {}; __export(useLoadedNavigation_exports, { useLoadedNavigation: () => useLoadedNavigation, useOptionalNavigation: () => useOptionalNavigation }); module.exports = __toCommonJS(useLoadedNavigation_exports); var import_native = require("@react-navigation/native"); var import_react = require("react"); var import_router = require("../router/router.cjs"); function useLoadedNavigation() { const { navigationRef } = (0, import_router.useOneRouter)(); const navigation = (0, import_native.useNavigation)(); const isMounted = (0, import_react.useRef)(true); const pending = (0, import_react.useRef)([]); (0, import_react.useEffect)(() => { isMounted.current = true; return () => { isMounted.current = false; }; }, []); const flush = (0, import_react.useCallback)(() => { if (isMounted.current) { const pendingCallbacks = pending.current; pending.current = []; pendingCallbacks.forEach(callback => { callback(navigation); }); } }, [navigation]); (0, import_react.useEffect)(() => { if (navigationRef.current) { flush(); } }, [flush, navigationRef]); const push = (0, import_react.useCallback)(fn => { pending.current.push(fn); if (navigationRef.current) { flush(); } }, [flush, navigationRef]); return push; } function useOptionalNavigation() { const [navigation, setNavigation] = (0, import_react.useState)(null); const loadNavigation = useLoadedNavigation(); (0, import_react.useEffect)(() => { loadNavigation(nav => setNavigation(nav)); }, [loadNavigation]); return navigation; }