one
Version:
One is a React framework for web, iOS, and Android apps.
232 lines (229 loc) • 11 kB
JavaScript
;
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 NavigationStack_native_exports = {};
__export(NavigationStack_native_exports, {
NavigationStack: () => NavigationStack,
Toolbar: () => Toolbar,
ToolbarContent: () => ToolbarContent,
ToolbarItem: () => ToolbarItem,
ToolbarItemGroup: () => ToolbarItemGroup,
ToolbarNode: () => ToolbarNode,
ToolbarSpacer: () => ToolbarSpacer
});
module.exports = __toCommonJS(NavigationStack_native_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_react = require("react");
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_containerChildren = require("./containerChildren.native.js");
var import_OneNativeNavigationStackNativeComponent = __toESM(require("./specs/OneNativeNavigationStackNativeComponent.native.js"), 1);
var import_OneNativeNavigationStackContentNativeComponent = __toESM(require("./specs/OneNativeNavigationStackContentNativeComponent.native.js"), 1);
var import_OneNativeToolbarNativeComponent = __toESM(require("./specs/OneNativeToolbarNativeComponent.native.js"), 1);
var import_OneNativeToolbarItemNativeComponent = __toESM(require("./specs/OneNativeToolbarItemNativeComponent.native.js"), 1);
var import_OneNativeToolbarItemGroupNativeComponent = __toESM(require("./specs/OneNativeToolbarItemGroupNativeComponent.native.js"), 1);
var import_OneNativeToolbarSpacerNativeComponent = __toESM(require("./specs/OneNativeToolbarSpacerNativeComponent.native.js"), 1);
var import_viewportStyle = require("./viewportStyle.native.js");
var CONTENT_STYLE = {
position: "absolute",
left: 0,
top: 0
};
var TOOLBAR_CHILDREN = "Swift.ToolbarItem, Swift.ToolbarItemGroup, and Swift.ToolbarSpacer";
function ToolbarMarker(_props) {
throw new Error("Swift.Toolbar must be a direct child of Swift.NavigationStack or Swift.Tabs, or a NavigationSplitView column");
}
function ToolbarContent(_props) {
throw new Error("Swift.Toolbar.Content must be a direct child of Swift.Toolbar");
}
var Toolbar = Object.assign(ToolbarMarker, { Content: ToolbarContent });
function ToolbarItem(_props) {
throw new Error("Swift.ToolbarItem must be a direct child of Swift.Toolbar");
}
function ToolbarItemGroup(_props) {
throw new Error("Swift.ToolbarItemGroup must be a direct child of Swift.Toolbar");
}
function ToolbarSpacer(_props) {
throw new Error("Swift.ToolbarSpacer must be a direct child of Swift.Toolbar");
}
function toolbarPlacement(value, owner, iosVersion) {
var placement = value !== null && value !== void 0 ? value : "automatic";
if (typeof placement !== "string") throw new Error(`${owner} placement must be a string`);
(0, import_swiftui.assertSwiftUIValue)("ToolbarItemPlacement", placement, iosVersion);
return placement;
}
function ToolbarItemNode(param) {
var { element, iosVersion } = param;
var props = element.props;
if (import_react.Children.count(props.children) === 0) throw new Error("Swift.ToolbarItem needs children");
(0, import_containerChildren.assertOneNativeChildren)(props.children, "Swift.ToolbarItem");
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_OneNativeToolbarItemNativeComponent.default, {
...props,
placement: toolbarPlacement(props.placement, "Swift.ToolbarItem", iosVersion),
swiftStyle: (0, import_swiftStyleNative.swiftStyleNative)(props.swiftStyle),
onNativeSDKEvent: function onNativeSDKEvent(param2) {
var { nativeEvent } = param2;
return (0, import_swiftStyleNative.dispatchSDKEvent)(props.swiftStyle, nativeEvent.name, nativeEvent.value);
},
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_containerChildren.InsideContainer, {
value: true,
children: props.children
})
});
}
function ToolbarItemGroupNode(param) {
var { element, iosVersion } = param;
var _props_label, _props_systemImage;
var props = element.props;
if (import_react.Children.count(props.children) === 0) throw new Error("Swift.ToolbarItemGroup needs children");
(0, import_containerChildren.assertOneNativeChildren)(props.children, "Swift.ToolbarItemGroup");
if (props.systemImage !== void 0 && !props.label) throw new Error("Swift.ToolbarItemGroup systemImage requires a label");
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_OneNativeToolbarItemGroupNativeComponent.default, {
...props,
label: (_props_label = props.label) !== null && _props_label !== void 0 ? _props_label : "",
systemImage: (_props_systemImage = props.systemImage) !== null && _props_systemImage !== void 0 ? _props_systemImage : "",
placement: toolbarPlacement(props.placement, "Swift.ToolbarItemGroup", iosVersion),
swiftStyle: (0, import_swiftStyleNative.swiftStyleNative)(props.swiftStyle),
onNativeSDKEvent: function onNativeSDKEvent(param2) {
var { nativeEvent } = param2;
return (0, import_swiftStyleNative.dispatchSDKEvent)(props.swiftStyle, nativeEvent.name, nativeEvent.value);
},
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_containerChildren.InsideContainer, {
value: true,
children: props.children
})
});
}
function ToolbarSpacerNode(param) {
var { element, iosVersion } = param;
var _props_sizing;
var props = element.props;
if (import_react.Children.count(props.children) !== 0) throw new Error("Swift.ToolbarSpacer takes no children");
if (iosVersion < 26) throw new Error("Swift.ToolbarSpacer requires iOS 26 or later");
var sizing = (_props_sizing = props.sizing) !== null && _props_sizing !== void 0 ? _props_sizing : "flexible";
(0, import_swiftui.assertSwiftUIValue)("SpacerSizing", sizing, iosVersion);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_OneNativeToolbarSpacerNativeComponent.default, {
...props,
sizing,
placement: toolbarPlacement(props.placement, "Swift.ToolbarSpacer", iosVersion)
});
}
function ToolbarNode(param) {
var { children, iosVersion } = param;
var contentCount = 0;
var toolbarItems = import_react.Children.toArray(children).flatMap(function(child) {
if (!/* @__PURE__ */ (0, import_react.isValidElement)(child) || child.type !== ToolbarContent) return [child];
contentCount += 1;
if (contentCount > 1) throw new Error("Swift.Toolbar accepts one Swift.Toolbar.Content");
var content = child.props.children;
if (import_react.Children.count(content) === 0) throw new Error("Swift.Toolbar.Content needs children");
return import_react.Children.toArray(content);
});
var items = toolbarItems.map(function(child, index) {
if (!/* @__PURE__ */ (0, import_react.isValidElement)(child)) throw new Error(`Swift.Toolbar children must be elements: ${TOOLBAR_CHILDREN}`);
var element = child;
var key = `${index}`;
if (element.type === ToolbarItem) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToolbarItemNode, {
element: child,
iosVersion
}, key);
if (element.type === ToolbarItemGroup) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToolbarItemGroupNode, {
element: child,
iosVersion
}, key);
if (element.type === ToolbarSpacer) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToolbarSpacerNode, {
element: child,
iosVersion
}, key);
throw new Error(`Swift.Toolbar accepts ${TOOLBAR_CHILDREN} elements as children`);
});
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_OneNativeToolbarNativeComponent.default, { children: items });
}
function NavigationStack(param) {
var { children, swiftStyle, style, ...props } = param;
var iosVersion = Number.parseFloat(String(import_react_native.Platform.Version));
var { toolbars, content } = (0, import_react.useMemo)(function() {
var toolbars2 = [];
var content2 = [];
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
try {
for (var _iterator = import_react.Children.toArray(children)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var child = _step.value;
if (child === null || child === void 0 || typeof child === "boolean") continue;
if (/* @__PURE__ */ (0, import_react.isValidElement)(child)) {
if (child.type === Toolbar) {
toolbars2.push(child);
continue;
}
if (child.type === ToolbarItem || child.type === ToolbarItemGroup || child.type === ToolbarSpacer) throw new Error(`Swift.NavigationStack accepts Swift.Toolbar elements or React Native content as children; ${TOOLBAR_CHILDREN} belong inside Swift.Toolbar`);
}
content2.push(child);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return {
toolbars: toolbars2,
content: content2
};
}, [children]);
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_OneNativeNavigationStackNativeComponent.default, {
...props,
style: (0, import_viewportStyle.viewportStyle)(style),
swiftStyle: (0, import_swiftStyleNative.swiftStyleNative)(swiftStyle),
onNativeSDKEvent: function onNativeSDKEvent(param2) {
var { nativeEvent } = param2;
return (0, import_swiftStyleNative.dispatchSDKEvent)(swiftStyle, nativeEvent.name, nativeEvent.value);
},
children: [toolbars.map(function(toolbar, index) {
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToolbarNode, {
iosVersion,
children: toolbar.props.children
}, index);
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_OneNativeNavigationStackContentNativeComponent.default, {
collapsable: false,
style: CONTENT_STYLE,
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_containerChildren.InsideContainer, {
value: false,
children: content
})
})]
});
}
//# sourceMappingURL=NavigationStack.native.js.map