UNPKG

one

Version:

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

402 lines (399 loc) • 17.8 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 Tabs_native_exports = {}; __export(Tabs_native_exports, { Tab: () => Tab, TabSection: () => TabSection, TabViewBottomAccessory: () => TabViewBottomAccessory, TabViewSlot: () => TabViewSlot, Tabs: () => Tabs }); module.exports = __toCommonJS(Tabs_native_exports); var import_jsx_runtime = require("react/jsx-runtime"); var import_controlled = require("./controlled.native.js"); var import_react_native = require("react-native"); var import_swiftui = require("./generated/swiftui.native.js"); var import_swiftStyleNative = require("./generated/swiftStyleNative.native.js"); var import_viewSlots = require("./generated/viewSlots.native.js"); var import_react = require("react"); var import_OneNativeTabNativeComponent = __toESM(require("./specs/OneNativeTabNativeComponent.native.js"), 1); var import_OneNativeTabsNativeComponent = __toESM(require("./specs/OneNativeTabsNativeComponent.native.js"), 1); var import_NavigationStack = require("./NavigationStack.native.js"); var PAGE_STYLE = { position: "absolute", left: 0, top: 0, width: "100%", height: "100%" }; function TabViewBottomAccessory(_props) { throw new Error("Swift.TabViewBottomAccessory must be a direct child of Swift.Tabs"); } function TabViewSlot(_props) { throw new Error("Swift.TabViewSlot must be a direct child of Swift.Tabs"); } function TabSection(_props) { throw new Error("Swift.TabSection must be a direct child of Swift.Tabs"); } function Tab(_props) { throw new Error("Swift.Tab must be a direct child of Swift.Tabs or Swift.TabSection"); } function tabContentModifiers(owner, props, iosVersion) { var _props_sectionActions; if (props.disabled !== void 0 && iosVersion < 18.4) throw new Error(`${owner} disabled requires iOS 18.4 or later`); if (props.help !== void 0 && iosVersion < 27) throw new Error(`${owner} help requires iOS 27 or later`); var placements = function placements2(value) { var _ref; var list = (_ref = value === null || value === void 0 ? void 0 : value.for) !== null && _ref !== void 0 ? _ref : []; var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; try { for (var _iterator = list[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var placement = _step.value; (0, import_swiftui.assertSwiftUIValue)("AdaptableTabBarPlacement", placement, iosVersion); } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return != null) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } if (new Set(list).size !== list.length) throw new Error(`${owner} lists a placement twice`); return list; }; if (props.customizationBehavior) (0, import_swiftui.assertSwiftUIValue)("TabCustomizationBehavior", props.customizationBehavior.behavior, iosVersion); if (props.defaultVisibility) (0, import_swiftui.assertSwiftUIValue)("Visibility", props.defaultVisibility.visibility, iosVersion); if (props.springLoadingBehavior) (0, import_swiftui.assertSwiftUIValue)("SpringLoadingBehavior", props.springLoadingBehavior, iosVersion); if (props.tabPlacement) (0, import_swiftui.assertSwiftUIValue)("TabPlacement", props.tabPlacement, iosVersion); if (props.defaultSectionExpansion) (0, import_swiftui.assertSwiftUIValue)("TabSectionExpansion", props.defaultSectionExpansion, iosVersion); return JSON.stringify({ image: props.image, labelStyle: props.labelStyle, section: props.section, disabled: props.disabled, hidden: props.hidden, customizationID: props.customizationID, customizationBehavior: props.customizationBehavior && { value: props.customizationBehavior.behavior, placements: placements(props.customizationBehavior) }, defaultVisibility: props.defaultVisibility && { value: props.defaultVisibility.visibility, placements: placements(props.defaultVisibility) }, springLoadingBehavior: props.springLoadingBehavior, tabPlacement: props.tabPlacement, defaultSectionExpansion: props.defaultSectionExpansion, sectionActions: (_props_sectionActions = props.sectionActions) === null || _props_sectionActions === void 0 ? void 0 : _props_sectionActions.map(function(param) { var { id, title, systemImage } = param; return { id, title, systemImage: systemImage !== null && systemImage !== void 0 ? systemImage : "" }; }), accessibilityLabel: props.accessibilityLabel, accessibilityHint: props.accessibilityHint, accessibilityValue: props.accessibilityValue, accessibilityIdentifier: props.accessibilityIdentifier, help: props.help }); } function Tabs(param) { var { children, selection, onSelectionChange, onReselect, revision = 0, tabViewStyle = "automatic", tabBarVisibility = "automatic", customization = "", onCustomizationChange, swiftStyle, style, ...props } = param; var _ref, _accessory_inline, _ref1, _accessory_expanded, _ref2; var iosVersion = Number.parseFloat(String(import_react_native.Platform.Version)); (0, import_swiftui.assertSwiftUIValue)("TabViewStyle", tabViewStyle, iosVersion); (0, import_swiftui.assertSwiftUIValue)("Visibility", tabBarVisibility, iosVersion); var controlled = (0, import_controlled.useControlled)(function(event) { return onSelectionChange(event.selection); }, revision); var { entries, accessory, actions, toolbar } = (0, import_react.useMemo)(function() { var ids = /* @__PURE__ */ new Set(); var entries2 = []; var accessory2; var toolbar2; var actions2 = /* @__PURE__ */ new Map(); var claim = function claim2(owner, id) { if (!id || ids.has(id)) throw new Error(`${owner} requires unique, nonempty ids: "${id}"`); ids.add(id); }; var tab = function tab2(props2, section) { var { id, title, systemImage, image, badge, role, testID, onPress, swiftStyle: swiftStyle2, children: page } = props2; claim("Swift.Tab", id); if (Boolean(onPress) === (page !== void 0)) { throw new Error(`Swift.Tab "${id}" needs exactly one of onPress and children: a tab either runs an action or shows a page`); } if (systemImage && image) throw new Error(`Swift.Tab "${id}" takes systemImage or image, not both`); if (role) (0, import_swiftui.assertSwiftUIValue)("TabRole", role, iosVersion); entries2.push({ id, kind: onPress ? "action" : "page", title, systemImage: systemImage !== null && systemImage !== void 0 ? systemImage : "", badge: badge === void 0 ? "" : String(badge), role: role !== null && role !== void 0 ? role : "", slotHeight: 0, tabModifiers: tabContentModifiers(`Swift.Tab "${id}"`, { ...props2, section }, iosVersion), swiftStyle: swiftStyle2, testID, onPress, children: page }); if (onPress) actions2.set(id, onPress); }; var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; try { var _loop = function() { var child = _step.value; if (!/* @__PURE__ */ (0, import_react.isValidElement)(child)) throw new Error("Swift.Tabs children must be elements"); if (child.type === Tab) { tab(child.props, void 0); } else if (child.type === TabSection) { var _section_sectionActions; var section = child.props; claim("Swift.TabSection", section.id); var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0; try { for (var _iterator2 = ((_section_sectionActions = section.sectionActions) !== null && _section_sectionActions !== void 0 ? _section_sectionActions : [])[Symbol.iterator](), _step1; !(_iteratorNormalCompletion2 = (_step1 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { var action = _step1.value; claim(`Swift.TabSection "${section.id}" sectionActions`, action.id); actions2.set(action.id, action.onPress); } } catch (err) { _didIteratorError2 = true; _iteratorError2 = err; } finally { try { if (!_iteratorNormalCompletion2 && _iterator2.return != null) { _iterator2.return(); } } finally { if (_didIteratorError2) { throw _iteratorError2; } } } entries2.push({ id: section.id, kind: "section", title: section.title, systemImage: "", badge: "", role: "", slotHeight: 0, tabModifiers: tabContentModifiers(`Swift.TabSection "${section.id}"`, section, iosVersion), children: void 0 }); var tabs = import_react.Children.toArray(section.children); if (!tabs.length) throw new Error(`Swift.TabSection "${section.id}" needs Swift.Tab children`); var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0; try { for (var _iterator1 = tabs[Symbol.iterator](), _step2; !(_iteratorNormalCompletion1 = (_step2 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) { var sectionChild = _step2.value; if (!/* @__PURE__ */ (0, import_react.isValidElement)(sectionChild) || sectionChild.type !== Tab) throw new Error(`Swift.TabSection "${section.id}" accepts Swift.Tab elements as children`); tab(sectionChild.props, section.id); } } catch (err) { _didIteratorError1 = true; _iteratorError1 = err; } finally { try { if (!_iteratorNormalCompletion1 && _iterator1.return != null) { _iterator1.return(); } } finally { if (_didIteratorError1) { throw _iteratorError1; } } } } else if (child.type === TabViewBottomAccessory) { if (accessory2) throw new Error("Swift.Tabs accepts one TabViewBottomAccessory"); accessory2 = child.props; } else if (child.type === import_NavigationStack.Toolbar) { if (toolbar2) throw new Error("Swift.Tabs accepts one Swift.Toolbar"); toolbar2 = child.props.children; } else if (child.type === TabViewSlot) { var slot = child.props; if (!Object.hasOwn(import_viewSlots.tabViewSlotAvailability, slot.name)) throw new Error(`Swift.TabViewSlot has no SDK modifier ${slot.name}`); if (iosVersion < import_viewSlots.tabViewSlotAvailability[slot.name]) throw new Error(`Swift.TabViewSlot ${slot.name} requires iOS ${import_viewSlots.tabViewSlotAvailability[slot.name]} or later`); if (!Number.isFinite(slot.height) || slot.height <= 0) throw new Error("Swift.TabViewSlot height must be a positive number"); if (slot.children === void 0) throw new Error("Swift.TabViewSlot needs children"); if (entries2.some(function(entry) { return entry.kind === "slot" && entry.id === slot.name; })) throw new Error(`Swift.Tabs accepts one ${slot.name} slot`); entries2.push({ id: slot.name, kind: "slot", title: "", systemImage: "", badge: "", role: "", slotHeight: slot.height, tabModifiers: "{}", children: slot.children }); } else { throw new Error("Swift.Tabs accepts Swift.Tab, Swift.TabSection, Swift.TabViewSlot, Swift.TabViewBottomAccessory, and Swift.Toolbar elements as direct children"); } }; for (var _iterator = import_react.Children.toArray(children)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) _loop(); } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return != null) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } return { entries: entries2, accessory: accessory2, actions: actions2, toolbar: toolbar2 }; }, [children, iosVersion]); var tabsBeyondIOS17 = entries.some(function(entry) { return entry.kind === "section" || entry.kind !== "slot" && entry.tabModifiers !== "{}"; }); if (iosVersion < 18 && (tabsBeyondIOS17 || tabViewStyle !== "automatic" || onCustomizationChange)) throw new Error("Swift.Tabs sections, tab modifiers, styles, and customization require iOS 18 or later"); if (accessory) { if (entries.some(function(entry) { return entry.kind === "slot" && entry.id === "tabViewBottomAccessory"; })) throw new Error("Swift.Tabs accepts one tabViewBottomAccessory slot"); if (iosVersion < 26) throw new Error("Swift.TabViewBottomAccessory requires iOS 26 or later"); if (accessory.isEnabled !== void 0 && iosVersion < 26.1) throw new Error("Swift.TabViewBottomAccessory isEnabled requires iOS 26.1 or later"); if (accessory.children === void 0 && accessory.inline === void 0 && accessory.expanded === void 0) throw new Error("Swift.TabViewBottomAccessory needs children, inline, or expanded content"); } var selected = entries.find(function(entry) { return entry.id === selection; }); if (!selected || selected.kind !== "page" && selected.kind !== "action") { throw new Error(`Swift.Tabs selection "${selection}" must identify a mounted Swift.Tab`); } if (selected.kind === "action") { throw new Error(`Swift.Tabs selection "${selection}" is an action tab, which never becomes the selection`); } var accessoryEntries = accessory ? [{ kind: "accessoryInline", content: (_ref = (_accessory_inline = accessory.inline) !== null && _accessory_inline !== void 0 ? _accessory_inline : accessory.children) !== null && _ref !== void 0 ? _ref : accessory.expanded }, { kind: "accessoryExpanded", content: (_ref1 = (_accessory_expanded = accessory.expanded) !== null && _accessory_expanded !== void 0 ? _accessory_expanded : accessory.children) !== null && _ref1 !== void 0 ? _ref1 : accessory.inline }].map(function(param2) { var { kind, content } = param2; return { id: kind, kind, title: "", systemImage: "", badge: "", role: "", slotHeight: 0, tabModifiers: "{}", children: content }; }) : []; return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_OneNativeTabsNativeComponent.default, { ...props, style: [{ flex: 1 }, style], swiftStyle: (0, import_swiftStyleNative.swiftStyleNative)(swiftStyle), onNativeSDKEvent: function onNativeSDKEvent(param2) { var { nativeEvent } = param2; return (0, import_swiftStyleNative.dispatchSDKEvent)(swiftStyle, nativeEvent.name, nativeEvent.value); }, selection, acknowledgedEvent: controlled.acknowledgedEvent, revision, tabViewStyle, tabBarVisibility, customization, customizable: Boolean(onCustomizationChange), bottomAccessoryEnabled: (_ref2 = accessory === null || accessory === void 0 ? void 0 : accessory.isEnabled) !== null && _ref2 !== void 0 ? _ref2 : true, onNativeTabsSelectionChange: function onNativeTabsSelectionChange(param2) { var { nativeEvent } = param2; return controlled.onNativeChange(nativeEvent); }, onNativeTabsAction: function onNativeTabsAction(param2) { var { nativeEvent } = param2; var action = actions.get(nativeEvent.tabId); if (action) action(); else onReselect === null || onReselect === void 0 ? void 0 : onReselect(nativeEvent.tabId); }, onNativeTabsCustomizationChange: function onNativeTabsCustomizationChange(param2) { var { nativeEvent } = param2; return onCustomizationChange === null || onCustomizationChange === void 0 ? void 0 : onCustomizationChange(nativeEvent.customization); }, children: [[...entries, ...accessoryEntries].map(function(entry) { var hidden = (entry.kind === "page" || entry.kind === "action") && entry.id !== selection; return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_OneNativeTabNativeComponent.default, { tabId: entry.id, kind: entry.kind, title: entry.title, systemImage: entry.systemImage, badge: entry.badge, tabRole: entry.role, slotHeight: entry.slotHeight, tabModifiers: entry.tabModifiers, swiftStyle: (0, import_swiftStyleNative.swiftStyleNative)(entry.swiftStyle), onNativeSDKEvent: function onNativeSDKEvent(param2) { var { nativeEvent } = param2; return (0, import_swiftStyleNative.dispatchSDKEvent)(entry.swiftStyle, nativeEvent.name, nativeEvent.value); }, testID: entry.testID, style: PAGE_STYLE, collapsable: false, pointerEvents: hidden ? "none" : "auto", accessibilityElementsHidden: hidden, importantForAccessibility: hidden ? "no-hide-descendants" : "auto", children: entry.children }, `${entry.kind}:${entry.id}`); }), toolbar ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_NavigationStack.ToolbarNode, { iosVersion, children: toolbar }) : null] }); } //# sourceMappingURL=Tabs.native.js.map