UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

96 lines (93 loc) • 4.76 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; 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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod)); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var split_view_native_exports = {}; __export(split_view_native_exports, { SplitView: () => SplitView }); module.exports = __toCommonJS(split_view_native_exports); var import_jsx_runtime = require("react/jsx-runtime"); var import_react = __toESM(require("react"), 1); var import_react_native = require("react-native"); var import_NativeNavigatorContext = require("../../layouts/NativeNavigatorContext.native.js"); var IsWithinSplitViewContext = /* @__PURE__ */ (0, import_react.createContext)(false); function SplitViewColumnComponent(props) { if (import_react_native.Platform.OS !== "ios") return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, { children: props.children }); return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: props.children }); } function SplitViewInspectorComponent(props) { if (import_react_native.Platform.OS !== "ios") return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, { children: props.children }); return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: props.children }); } function SplitViewNavigator(param) { var { children, slot: Slot, ...rest } = param; var isWithinNativeNavigator = (0, import_react.useContext)(import_NativeNavigatorContext.IsWithinNativeNavigator); if ((0, import_react.useContext)(IsWithinSplitViewContext)) { throw new Error("There can only be one SplitView in the navigation hierarchy."); } if (import_react_native.Platform.OS === "ios" && isWithinNativeNavigator) { throw new Error("SplitView cannot be used inside another navigator, except for Slot."); } if (import_react_native.Platform.OS !== "ios") { console.warn("SplitView is only supported on iOS."); return Slot ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Slot, {}) : null; } var { Split } = require("react-native-screens/experimental"); var allChildrenArray = import_react.default.Children.toArray(children); var columnChildren = allChildrenArray.filter(function(child) { return /* @__PURE__ */ (0, import_react.isValidElement)(child) && child.type === SplitViewColumnComponent; }); var inspectorChildren = allChildrenArray.filter(function(child) { return /* @__PURE__ */ (0, import_react.isValidElement)(child) && child.type === SplitViewInspectorComponent; }); if (columnChildren.length > 2) { throw new Error("There can only be two SplitView.Column in the SplitView."); } if (columnChildren.length + inspectorChildren.length === 0) { console.warn("No SplitView.Column found in SplitView."); return Slot ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Slot, {}) : null; } return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IsWithinSplitViewContext.Provider, { value: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Split.Host, { preferredDisplayMode: "oneBesideSecondary", ...rest, children: [ columnChildren.map(function(child, index) { return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Split.Column, { children: child.props.children }, `column-${index}`); }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Split.Column, { children: Slot ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Slot, {}) : null }), inspectorChildren.map(function(child, index) { return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Split.Inspector, { children: child.props.children }, `inspector-${index}`); }) ] }, columnChildren.length + inspectorChildren.length) }); } var SplitView = Object.assign(SplitViewNavigator, { Column: SplitViewColumnComponent, Inspector: SplitViewInspectorComponent }); //# sourceMappingURL=split-view.native.js.map