one
Version:
One is a React framework for web, iOS, and Android apps.
82 lines (79 loc) • 2.49 kB
JavaScript
import { jsx } from "react/jsx-runtime";
import { useControlled } from "./controlled.native.js";
import { Children, isValidElement, useMemo } from "react";
import NativeTab from "./specs/OneNativeTabNativeComponent.native.js";
import NativePager from "./specs/OneNativeSwiftPagerNativeComponent.native.js";
import { viewportStyle } from "./viewportStyle.native.js";
var PAGE_STYLE = {
position: "absolute",
left: 0,
top: 0,
width: "100%",
height: "100%"
};
function Page(_props) {
throw new Error("Swift.Page must be a direct child of Swift.Pager");
}
function Pager(param) {
var { children, selection, onSelectionChange, revision = 0, style, ...props } = param;
var controlled = useControlled(function(event) {
return onSelectionChange(event.selection);
}, revision);
var pages = useMemo(function() {
var ids = /* @__PURE__ */ new Set();
return Children.toArray(children).map(function(child) {
if (!/* @__PURE__ */ isValidElement(child) || child.type !== Page) {
throw new Error("Swift.Pager accepts Swift.Page elements as direct children");
}
var { id, testID, children: page } = child.props;
if (!id || ids.has(id)) {
throw new Error(`Swift.Pager requires unique, nonempty page ids: "${id}"`);
}
ids.add(id);
return {
id,
testID,
children: page
};
});
}, [children]);
var selected = pages.find(function(page) {
return page.id === selection;
});
if (!selected) {
throw new Error(`Swift.Pager selection "${selection}" must identify a mounted Swift.Page`);
}
return /* @__PURE__ */ jsx(NativePager, {
...props,
style: viewportStyle(style),
selection,
acknowledgedEvent: controlled.acknowledgedEvent,
revision,
onNativePagerSelectionChange: function onNativePagerSelectionChange(param2) {
var { nativeEvent } = param2;
return controlled.onNativeChange(nativeEvent);
},
children: pages.map(function(page) {
var visible = page.id === selection;
return /* @__PURE__ */ jsx(NativeTab, {
tabId: page.id,
title: "",
systemImage: "",
badge: "",
tabRole: "",
kind: "page",
slotHeight: 0,
tabModifiers: "{}",
testID: page.testID,
style: PAGE_STYLE,
collapsable: false,
pointerEvents: visible ? "auto" : "none",
accessibilityElementsHidden: !visible,
importantForAccessibility: visible ? "auto" : "no-hide-descendants",
children: page.children
}, page.id);
})
});
}
export { Page, Pager };
//# sourceMappingURL=Pager.native.js.map