UNPKG

expo-router

Version:

Expo Router is a file-based router for React Native and web applications.

72 lines 3.22 kB
"use strict"; 'use client'; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.Screen = Screen; exports.isScreen = isScreen; const react_1 = __importStar(require("react")); const useNavigation_1 = require("../useNavigation"); const useLayoutEffect = typeof window !== 'undefined' ? react_1.default.useLayoutEffect : function () { }; /** Component for setting the current screen's options dynamically. */ function Screen({ name, options }) { const navigation = (0, useNavigation_1.useNavigation)(name); useLayoutEffect(() => { if (options && // React Navigation will infinitely loop in some cases if an empty object is passed to setOptions. // https://github.com/expo/router/issues/452 Object.keys(options).length) { navigation.setOptions(options); } }, [navigation, options]); return null; } function isScreen(child, contextKey) { if ((0, react_1.isValidElement)(child) && child && child.type === Screen) { if (typeof child.props === 'object' && child.props && 'name' in child.props && !child.props.name) { throw new Error(`<Screen /> component in \`default export\` at \`app${contextKey}/_layout\` must have a \`name\` prop when used as a child of a Layout Route.`); } if (process.env.NODE_ENV !== 'production') { if (['children', 'component', 'getComponent'].some((key) => child.props && typeof child.props === 'object' && key in child.props)) { throw new Error(`<Screen /> component in \`default export\` at \`app${contextKey}/_layout\` must not have a \`children\`, \`component\`, or \`getComponent\` prop when used as a child of a Layout Route`); } } return true; } return false; } //# sourceMappingURL=Screen.js.map