UNPKG

one

Version:

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

256 lines (253 loc) • 11.6 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 Sheet_native_exports = {}; __export(Sheet_native_exports, { FullScreenCover: () => FullScreenCover, Sheet: () => Sheet, SheetAppearanceContext: () => SheetAppearanceContext }); module.exports = __toCommonJS(Sheet_native_exports); var import_jsx_runtime = require("react/jsx-runtime"); var import_react = require("react"); var import_react_native = require("react-native"); var import_controlled = require("./controlled.native.js"); var import_OneNativeSheetNativeComponent = __toESM(require("./specs/OneNativeSheetNativeComponent.native.js"), 1); var import_OneNativeSheetContentNativeComponent = __toESM(require("./specs/OneNativeSheetContentNativeComponent.native.js"), 1); var import_swiftui = require("./generated/swiftui.native.js"); var DEFAULT_DETENTS = ["large"]; var SheetAppearanceContext = /* @__PURE__ */ (0, import_react.createContext)(void 0); function nativeDetent(detent) { if (detent === "medium" || detent === "large") return { type: detent, value: 0 }; if (typeof detent !== "object" || detent === null || Object.keys(detent).length !== 1) throw new Error("Invalid presentation detent"); if ("fraction" in detent && Number.isFinite(detent.fraction) && detent.fraction > 0 && detent.fraction <= 1) return { type: "fraction", value: detent.fraction }; if ("height" in detent && Number.isFinite(detent.height) && detent.height > 0) return { type: "height", value: detent.height }; throw new Error("Presentation detent must be medium, large, a fraction in (0, 1], or a positive height"); } function publicDetent(param) { var { type, value } = param; if (type === "medium" || type === "large") return type; if (type === "fraction") return { fraction: value }; if (type === "height") return { height: value }; throw new Error(`Unknown native presentation detent: ${type}`); } function sameDetent(a, b) { return a.type === b.type && a.value === b.value; } function usePresentationId(isPresented) { var [cycle, setCycle] = (0, import_react.useState)({ isPresented, id: isPresented ? 1 : 0 }); if (cycle.isPresented === isPresented) return cycle.id; var next = { isPresented, id: cycle.id + (isPresented ? 1 : 0) }; setCycle(next); return next.id; } function Sheet(param) { var { isPresented, onIsPresentedChange, onDismiss, onDidDismiss, revision = 0, presentationDetents, fitToContents = false, selectedDetent, onSelectedDetentChange, detentRevision = 0, presentationDragIndicator = "automatic", interactiveDismissDisabled = false, presentationBackground, presentationBackgroundInteraction = "automatic", presentationContentInteraction = "automatic", presentationSizing = "automatic", children, style, ...props } = param; var _ref, _ref1; var colorScheme = (0, import_react.useContext)(SheetAppearanceContext); if (typeof isPresented !== "boolean") throw new Error("Swift.Sheet isPresented must be a boolean"); var presentationId = usePresentationId(isPresented); var requestedDetents = presentationDetents !== null && presentationDetents !== void 0 ? presentationDetents : DEFAULT_DETENTS; if (!Array.isArray(requestedDetents) || !requestedDetents.length) throw new Error("Swift.Sheet requires at least one presentation detent"); var detents = requestedDetents.map(nativeDetent); if (new Set(detents.map(function(param2) { var { type, value } = param2; return `${type}:${value}`; })).size !== detents.length) throw new Error("Swift.Sheet presentation detents must be unique"); if (selectedDetent === void 0 !== (onSelectedDetentChange === void 0)) throw new Error("Swift.Sheet selectedDetent and onSelectedDetentChange must be provided together"); if (fitToContents && selectedDetent !== void 0) throw new Error("Swift.Sheet fitToContents cannot be combined with selectedDetent"); var nativeSelection = selectedDetent ? nativeDetent(selectedDetent) : null; if (nativeSelection && !detents.some(function(detent) { return sameDetent(detent, nativeSelection); })) throw new Error("Swift.Sheet selectedDetent must be in presentationDetents"); var backgroundInteraction = (function() { if (typeof presentationBackgroundInteraction === "string") { if (![ "automatic", "enabled", "disabled" ].includes(presentationBackgroundInteraction)) throw new Error("Invalid Swift.Sheet presentationBackgroundInteraction"); return { mode: presentationBackgroundInteraction, detent: { type: "large", value: 0 } }; } if (typeof presentationBackgroundInteraction !== "object" || presentationBackgroundInteraction === null || !("enabledUpThrough" in presentationBackgroundInteraction)) throw new Error("Invalid Swift.Sheet presentationBackgroundInteraction"); var detent = nativeDetent(presentationBackgroundInteraction.enabledUpThrough); if (fitToContents) throw new Error("Swift.Sheet fitToContents cannot use an enabledUpThrough background interaction"); if (!detents.some(function(candidate) { return sameDetent(candidate, detent); })) throw new Error("Swift.Sheet presentationBackgroundInteraction detent must be in presentationDetents"); return { mode: "enabledUpThrough", detent }; })(); if (![ "automatic", "fitted", "form", "page" ].includes(presentationSizing)) throw new Error("Invalid Swift.Sheet presentationSizing"); (0, import_swiftui.assertSwiftUIValue)("Visibility", presentationDragIndicator, Number.parseFloat(String(import_react_native.Platform.Version))); (0, import_swiftui.assertSwiftUIValue)("PresentationContentInteraction", presentationContentInteraction, Number.parseFloat(String(import_react_native.Platform.Version))); var controlled = (0, import_controlled.useControlled)(function(event) { return onIsPresentedChange(event.isPresented); }, revision); var controlledDetent = (0, import_controlled.useControlled)(function(event) { return onSelectedDetentChange === null || onSelectedDetentChange === void 0 ? void 0 : onSelectedDetentChange(publicDetent(event)); }, detentRevision); return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_OneNativeSheetNativeComponent.default, { ...props, style: [{ position: "absolute", width: 0, height: 0 }, style], isPresented, revision, presentationId, acknowledgedEvent: controlled.acknowledgedEvent, detents, fitToContents, selectedDetentType: (_ref = nativeSelection === null || nativeSelection === void 0 ? void 0 : nativeSelection.type) !== null && _ref !== void 0 ? _ref : "", selectedDetentValue: (_ref1 = nativeSelection === null || nativeSelection === void 0 ? void 0 : nativeSelection.value) !== null && _ref1 !== void 0 ? _ref1 : 0, acknowledgedDetentEvent: controlledDetent.acknowledgedEvent, detentRevision, interactiveDismissDisabled, presentationDragIndicator, presentationBackground, presentationBackgroundInteraction: backgroundInteraction.mode, presentationBackgroundInteractionDetentType: backgroundInteraction.detent.type, presentationBackgroundInteractionDetentValue: backgroundInteraction.detent.value, presentationContentInteraction, presentationSizing, presentation: "sheet", colorScheme: colorScheme !== null && colorScheme !== void 0 ? colorScheme : "", onNativeSheetIsPresentedChange: function onNativeSheetIsPresentedChange(param2) { var { nativeEvent } = param2; return controlled.onNativeChange(nativeEvent); }, onNativeSheetDismiss: function onNativeSheetDismiss(param2) { var { nativeEvent } = param2; if (nativeEvent.revision === revision) onDismiss === null || onDismiss === void 0 ? void 0 : onDismiss(); }, onNativeSheetDidDismiss: function onNativeSheetDidDismiss(param2) { var { nativeEvent } = param2; if (!isPresented && nativeEvent.revision === revision && nativeEvent.presentationId === presentationId) onDidDismiss === null || onDidDismiss === void 0 ? void 0 : onDidDismiss(); }, onNativeSheetDetentChange: function onNativeSheetDetentChange(param2) { var { nativeEvent } = param2; return controlledDetent.onNativeChange(nativeEvent); }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_OneNativeSheetContentNativeComponent.default, { collapsable: false, style: { position: "absolute", left: 0, top: 0 }, children }) }); } var COVER_DETENTS = []; function FullScreenCover(param) { var { isPresented, onIsPresentedChange, onDismiss, onDidDismiss, revision = 0, children, style, ...props } = param; if (typeof isPresented !== "boolean") throw new Error("Swift.FullScreenCover isPresented must be a boolean"); var presentationId = usePresentationId(isPresented); var controlled = (0, import_controlled.useControlled)(function(event) { return onIsPresentedChange(event.isPresented); }, revision); return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_OneNativeSheetNativeComponent.default, { ...props, style: [{ position: "absolute", width: 0, height: 0 }, style], isPresented, revision, presentationId, acknowledgedEvent: controlled.acknowledgedEvent, detents: COVER_DETENTS, fitToContents: false, selectedDetentType: "", selectedDetentValue: 0, acknowledgedDetentEvent: 0, detentRevision: 0, presentationBackgroundInteraction: "automatic", presentationBackgroundInteractionDetentType: "large", presentationBackgroundInteractionDetentValue: 0, presentationContentInteraction: "automatic", presentationSizing: "automatic", interactiveDismissDisabled: false, presentationDragIndicator: "automatic", presentation: "fullScreenCover", colorScheme: "", onNativeSheetIsPresentedChange: function onNativeSheetIsPresentedChange(param2) { var { nativeEvent } = param2; return controlled.onNativeChange(nativeEvent); }, onNativeSheetDismiss: function onNativeSheetDismiss(param2) { var { nativeEvent } = param2; if (nativeEvent.revision === revision) onDismiss === null || onDismiss === void 0 ? void 0 : onDismiss(); }, onNativeSheetDidDismiss: function onNativeSheetDidDismiss(param2) { var { nativeEvent } = param2; if (!isPresented && nativeEvent.revision === revision && nativeEvent.presentationId === presentationId) onDidDismiss === null || onDidDismiss === void 0 ? void 0 : onDidDismiss(); }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_OneNativeSheetContentNativeComponent.default, { collapsable: false, style: { position: "absolute", left: 0, top: 0 }, children }) }); } //# sourceMappingURL=Sheet.native.js.map