UNPKG

one

Version:

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

80 lines (78 loc) 3.25 kB
"use strict"; 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 useFocusEffect_exports = {}; __export(useFocusEffect_exports, { useFocusEffect: () => useFocusEffect }); module.exports = __toCommonJS(useFocusEffect_exports); var import_react = require("react"); var import_useLoadedNavigation = require("./link/useLoadedNavigation.native.js"); function useFocusEffect(effect, deps) { var navigation = (0, import_useLoadedNavigation.useOptionalNavigation)(); (0, import_react.useEffect)(function () { if (!navigation) { return; } var isFocused = false; var cleanup; var callback = function () { var destroy = effect(); if (destroy === void 0 || typeof destroy === "function") { return destroy; } if (process.env.NODE_ENV !== "production") { var message = "An effect function must not return anything besides a function, which is used for clean-up."; if (destroy === null) { message += " You returned 'null'. If your effect does not require clean-up, return 'undefined' (or nothing)."; } else if (typeof destroy.then === "function") { message += "\n\nIt looks like you wrote 'useFocusEffect(async () => ...)' or returned a Promise. Instead, write the async function inside your effect and call it immediately:\n\nuseFocusEffect(\n React.useCallback(() => {\n async function fetchData() {\n // You can await here\n const response = await MyAPI.getData(someId);\n // ...\n }\n\n fetchData();\n }, [someId])\n);\n\nSee usage guide: https://reactnavigation.org/docs/use-focus-effect"; } else { message += ` You returned '${JSON.stringify(destroy)}'.`; } console.error(message); } }; if (navigation.isFocused()) { cleanup = callback(); isFocused = true; } var unsubscribeFocus = navigation.addListener("focus", function () { if (isFocused) return; cleanup === null || cleanup === void 0 ? void 0 : cleanup(); cleanup = callback(); isFocused = true; }); var unsubscribeBlur = navigation.addListener("blur", function () { cleanup === null || cleanup === void 0 ? void 0 : cleanup(); cleanup = void 0; isFocused = false; }); return function () { cleanup === null || cleanup === void 0 ? void 0 : cleanup(); unsubscribeFocus(); unsubscribeBlur(); }; }, [navigation, ...deps]); } //# sourceMappingURL=useFocusEffect.native.js.map