one
Version:
One is a React framework for web, iOS, and Android apps.
195 lines (192 loc) • 8.29 kB
JavaScript
import { jsx, jsxs } from "react/jsx-runtime";
import { Children, isValidElement, useMemo } from "react";
import { Platform } from "react-native";
import { assertSwiftUIValue } from "./generated/swiftui.native.js";
import { dispatchSDKEvent, swiftStyleNative } from "./generated/swiftStyleNative.native.js";
import { InsideContainer, assertOneNativeChildren } from "./containerChildren.native.js";
import NativeNavigationStack from "./specs/OneNativeNavigationStackNativeComponent.native.js";
import NativeContent from "./specs/OneNativeNavigationStackContentNativeComponent.native.js";
import NativeToolbar from "./specs/OneNativeToolbarNativeComponent.native.js";
import NativeToolbarItem from "./specs/OneNativeToolbarItemNativeComponent.native.js";
import NativeToolbarItemGroup from "./specs/OneNativeToolbarItemGroupNativeComponent.native.js";
import NativeToolbarSpacer from "./specs/OneNativeToolbarSpacerNativeComponent.native.js";
import { viewportStyle } from "./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`);
assertSwiftUIValue("ToolbarItemPlacement", placement, iosVersion);
return placement;
}
function ToolbarItemNode(param) {
var { element, iosVersion } = param;
var props = element.props;
if (Children.count(props.children) === 0) throw new Error("Swift.ToolbarItem needs children");
assertOneNativeChildren(props.children, "Swift.ToolbarItem");
return /* @__PURE__ */ jsx(NativeToolbarItem, {
...props,
placement: toolbarPlacement(props.placement, "Swift.ToolbarItem", iosVersion),
swiftStyle: swiftStyleNative(props.swiftStyle),
onNativeSDKEvent: function onNativeSDKEvent(param2) {
var { nativeEvent } = param2;
return dispatchSDKEvent(props.swiftStyle, nativeEvent.name, nativeEvent.value);
},
children: /* @__PURE__ */ jsx(InsideContainer, {
value: true,
children: props.children
})
});
}
function ToolbarItemGroupNode(param) {
var { element, iosVersion } = param;
var _props_label, _props_systemImage;
var props = element.props;
if (Children.count(props.children) === 0) throw new Error("Swift.ToolbarItemGroup needs children");
assertOneNativeChildren(props.children, "Swift.ToolbarItemGroup");
if (props.systemImage !== void 0 && !props.label) throw new Error("Swift.ToolbarItemGroup systemImage requires a label");
return /* @__PURE__ */ jsx(NativeToolbarItemGroup, {
...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: swiftStyleNative(props.swiftStyle),
onNativeSDKEvent: function onNativeSDKEvent(param2) {
var { nativeEvent } = param2;
return dispatchSDKEvent(props.swiftStyle, nativeEvent.name, nativeEvent.value);
},
children: /* @__PURE__ */ jsx(InsideContainer, {
value: true,
children: props.children
})
});
}
function ToolbarSpacerNode(param) {
var { element, iosVersion } = param;
var _props_sizing;
var props = element.props;
if (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";
assertSwiftUIValue("SpacerSizing", sizing, iosVersion);
return /* @__PURE__ */ jsx(NativeToolbarSpacer, {
...props,
sizing,
placement: toolbarPlacement(props.placement, "Swift.ToolbarSpacer", iosVersion)
});
}
function ToolbarNode(param) {
var { children, iosVersion } = param;
var contentCount = 0;
var toolbarItems = Children.toArray(children).flatMap(function(child) {
if (!/* @__PURE__ */ 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 (Children.count(content) === 0) throw new Error("Swift.Toolbar.Content needs children");
return Children.toArray(content);
});
var items = toolbarItems.map(function(child, index) {
if (!/* @__PURE__ */ 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__ */ jsx(ToolbarItemNode, {
element: child,
iosVersion
}, key);
if (element.type === ToolbarItemGroup) return /* @__PURE__ */ jsx(ToolbarItemGroupNode, {
element: child,
iosVersion
}, key);
if (element.type === ToolbarSpacer) return /* @__PURE__ */ jsx(ToolbarSpacerNode, {
element: child,
iosVersion
}, key);
throw new Error(`Swift.Toolbar accepts ${TOOLBAR_CHILDREN} elements as children`);
});
return /* @__PURE__ */ jsx(NativeToolbar, { children: items });
}
function NavigationStack(param) {
var { children, swiftStyle, style, ...props } = param;
var iosVersion = Number.parseFloat(String(Platform.Version));
var { toolbars, content } = useMemo(function() {
var toolbars2 = [];
var content2 = [];
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
try {
for (var _iterator = 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__ */ 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__ */ jsxs(NativeNavigationStack, {
...props,
style: viewportStyle(style),
swiftStyle: swiftStyleNative(swiftStyle),
onNativeSDKEvent: function onNativeSDKEvent(param2) {
var { nativeEvent } = param2;
return dispatchSDKEvent(swiftStyle, nativeEvent.name, nativeEvent.value);
},
children: [toolbars.map(function(toolbar, index) {
return /* @__PURE__ */ jsx(ToolbarNode, {
iosVersion,
children: toolbar.props.children
}, index);
}), /* @__PURE__ */ jsx(NativeContent, {
collapsable: false,
style: CONTENT_STYLE,
children: /* @__PURE__ */ jsx(InsideContainer, {
value: false,
children: content
})
})]
});
}
export { NavigationStack, Toolbar, ToolbarContent, ToolbarItem, ToolbarItemGroup, ToolbarNode, ToolbarSpacer };
//# sourceMappingURL=NavigationStack.native.js.map