one
Version:
One is a React framework for web, iOS, and Android apps.
67 lines (64 loc) • 2.96 kB
JavaScript
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
import React, { createContext, isValidElement, useContext } from "react";
import { Platform, View } from "react-native";
import { IsWithinNativeNavigator } from "../../layouts/NativeNavigatorContext.native.js";
var IsWithinSplitViewContext = /* @__PURE__ */ createContext(false);
function SplitViewColumnComponent(props) {
if (Platform.OS !== "ios") return /* @__PURE__ */ jsx(View, { children: props.children });
return /* @__PURE__ */ jsx(Fragment, { children: props.children });
}
function SplitViewInspectorComponent(props) {
if (Platform.OS !== "ios") return /* @__PURE__ */ jsx(View, { children: props.children });
return /* @__PURE__ */ jsx(Fragment, { children: props.children });
}
function SplitViewNavigator(param) {
var { children, slot: Slot, ...rest } = param;
var isWithinNativeNavigator = useContext(IsWithinNativeNavigator);
if (useContext(IsWithinSplitViewContext)) {
throw new Error("There can only be one SplitView in the navigation hierarchy.");
}
if (Platform.OS === "ios" && isWithinNativeNavigator) {
throw new Error("SplitView cannot be used inside another navigator, except for Slot.");
}
if (Platform.OS !== "ios") {
console.warn("SplitView is only supported on iOS.");
return Slot ? /* @__PURE__ */ jsx(Slot, {}) : null;
}
var { Split } = require("react-native-screens/experimental");
var allChildrenArray = React.Children.toArray(children);
var columnChildren = allChildrenArray.filter(function(child) {
return /* @__PURE__ */ isValidElement(child) && child.type === SplitViewColumnComponent;
});
var inspectorChildren = allChildrenArray.filter(function(child) {
return /* @__PURE__ */ 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__ */ jsx(Slot, {}) : null;
}
return /* @__PURE__ */ jsx(IsWithinSplitViewContext.Provider, {
value: true,
children: /* @__PURE__ */ jsxs(Split.Host, {
preferredDisplayMode: "oneBesideSecondary",
...rest,
children: [
columnChildren.map(function(child, index) {
return /* @__PURE__ */ jsx(Split.Column, { children: child.props.children }, `column-${index}`);
}),
/* @__PURE__ */ jsx(Split.Column, { children: Slot ? /* @__PURE__ */ jsx(Slot, {}) : null }),
inspectorChildren.map(function(child, index) {
return /* @__PURE__ */ jsx(Split.Inspector, { children: child.props.children }, `inspector-${index}`);
})
]
}, columnChildren.length + inspectorChildren.length)
});
}
var SplitView = Object.assign(SplitViewNavigator, {
Column: SplitViewColumnComponent,
Inspector: SplitViewInspectorComponent
});
export { SplitView };
//# sourceMappingURL=split-view.native.js.map