@tamagui/sheet 1.135.4 → 1.135.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/dist/cjs/Sheet.native.js +96 -90
  2. package/dist/cjs/Sheet.native.js.map +1 -6
  3. package/dist/cjs/SheetContext.native.js +21 -18
  4. package/dist/cjs/SheetContext.native.js.map +1 -6
  5. package/dist/cjs/SheetController.cjs +1 -1
  6. package/dist/cjs/SheetController.js +1 -1
  7. package/dist/cjs/SheetController.js.map +1 -1
  8. package/dist/cjs/SheetController.native.js +51 -38
  9. package/dist/cjs/SheetController.native.js.map +1 -6
  10. package/dist/cjs/SheetImplementationCustom.cjs +1 -1
  11. package/dist/cjs/SheetImplementationCustom.js +1 -1
  12. package/dist/cjs/SheetImplementationCustom.js.map +1 -1
  13. package/dist/cjs/SheetImplementationCustom.native.js +362 -312
  14. package/dist/cjs/SheetImplementationCustom.native.js.map +1 -6
  15. package/dist/cjs/SheetScrollView.cjs +1 -1
  16. package/dist/cjs/SheetScrollView.js +1 -1
  17. package/dist/cjs/SheetScrollView.js.map +1 -1
  18. package/dist/cjs/SheetScrollView.native.js +137 -107
  19. package/dist/cjs/SheetScrollView.native.js.map +1 -6
  20. package/dist/cjs/constants.native.js +21 -18
  21. package/dist/cjs/constants.native.js.map +1 -6
  22. package/dist/cjs/contexts.cjs +1 -1
  23. package/dist/cjs/contexts.js +1 -1
  24. package/dist/cjs/contexts.native.js +28 -21
  25. package/dist/cjs/contexts.native.js.map +1 -6
  26. package/dist/cjs/createSheet.native.js +148 -101
  27. package/dist/cjs/createSheet.native.js.map +1 -6
  28. package/dist/cjs/helpers.native.js +20 -17
  29. package/dist/cjs/helpers.native.js.map +1 -6
  30. package/dist/cjs/index.native.js +23 -32
  31. package/dist/cjs/index.native.js.map +1 -6
  32. package/dist/cjs/nativeSheet.native.js +65 -53
  33. package/dist/cjs/nativeSheet.native.js.map +1 -6
  34. package/dist/cjs/types.native.js +9 -5
  35. package/dist/cjs/types.native.js.map +1 -6
  36. package/dist/cjs/useSheet.native.js +21 -17
  37. package/dist/cjs/useSheet.native.js.map +1 -6
  38. package/dist/cjs/useSheetController.cjs +1 -1
  39. package/dist/cjs/useSheetController.js +1 -1
  40. package/dist/cjs/useSheetController.native.js +36 -27
  41. package/dist/cjs/useSheetController.native.js.map +1 -6
  42. package/dist/cjs/useSheetOffscreenSize.native.js +41 -23
  43. package/dist/cjs/useSheetOffscreenSize.native.js.map +1 -6
  44. package/dist/cjs/useSheetOpenState.native.js +44 -30
  45. package/dist/cjs/useSheetOpenState.native.js.map +1 -6
  46. package/dist/cjs/useSheetProviderProps.cjs +1 -1
  47. package/dist/cjs/useSheetProviderProps.js +1 -1
  48. package/dist/cjs/useSheetProviderProps.js.map +1 -1
  49. package/dist/cjs/useSheetProviderProps.native.js +119 -108
  50. package/dist/cjs/useSheetProviderProps.native.js.map +1 -6
  51. package/dist/jsx/Sheet.native.js +114 -84
  52. package/dist/jsx/Sheet.native.js.map +1 -6
  53. package/dist/jsx/SheetContext.native.js +35 -10
  54. package/dist/jsx/SheetContext.native.js.map +1 -6
  55. package/dist/jsx/SheetController.native.js +67 -29
  56. package/dist/jsx/SheetController.native.js.map +1 -6
  57. package/dist/jsx/SheetImplementationCustom.native.js +377 -312
  58. package/dist/jsx/SheetImplementationCustom.native.js.map +1 -6
  59. package/dist/jsx/SheetScrollView.native.js +156 -104
  60. package/dist/jsx/SheetScrollView.native.js.map +1 -6
  61. package/dist/jsx/constants.native.js +35 -8
  62. package/dist/jsx/constants.native.js.map +1 -6
  63. package/dist/jsx/contexts.native.js +45 -9
  64. package/dist/jsx/contexts.native.js.map +1 -6
  65. package/dist/jsx/createSheet.native.js +160 -109
  66. package/dist/jsx/createSheet.native.js.map +1 -6
  67. package/dist/jsx/helpers.native.js +31 -7
  68. package/dist/jsx/helpers.native.js.map +1 -6
  69. package/dist/jsx/index.native.js +31 -12
  70. package/dist/jsx/index.native.js.map +1 -6
  71. package/dist/jsx/nativeSheet.native.js +77 -50
  72. package/dist/jsx/nativeSheet.native.js.map +1 -6
  73. package/dist/jsx/types.native.js +19 -1
  74. package/dist/jsx/types.native.js.map +1 -6
  75. package/dist/jsx/useSheet.native.js +32 -8
  76. package/dist/jsx/useSheet.native.js.map +1 -6
  77. package/dist/jsx/useSheetController.native.js +52 -14
  78. package/dist/jsx/useSheetController.native.js.map +1 -6
  79. package/dist/jsx/useSheetOffscreenSize.native.js +52 -13
  80. package/dist/jsx/useSheetOffscreenSize.native.js.map +1 -6
  81. package/dist/jsx/useSheetOpenState.native.js +55 -22
  82. package/dist/jsx/useSheetOpenState.native.js.map +1 -6
  83. package/dist/jsx/useSheetProviderProps.native.js +135 -98
  84. package/dist/jsx/useSheetProviderProps.native.js.map +1 -6
  85. package/package.json +20 -19
  86. package/types/SheetContext.d.ts.map +1 -1
@@ -1,342 +1,407 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { ProvideAdaptContext, useAdaptContext } from "@tamagui/adapt";
3
- import { AnimatePresence } from "@tamagui/animate-presence";
4
- import { useComposedRefs } from "@tamagui/compose-refs";
5
- import { currentPlatform, isClient, isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
6
- import { LayoutMeasurementController, Stack, Theme, useConfiguration, useDidFinishSSR, useEvent, useThemeName } from "@tamagui/core";
7
- import { Portal, USE_NATIVE_PORTAL } from "@tamagui/portal";
8
- import React, { useState } from "react";
9
- import { Dimensions, Keyboard, PanResponder, View } from "react-native";
10
- import { ParentSheetContext, SheetInsideSheetContext } from "./contexts";
11
- import { resisted } from "./helpers";
12
- import { SheetProvider } from "./SheetContext";
13
- import { useSheetOpenState } from "./useSheetOpenState";
14
- import { useSheetProviderProps } from "./useSheetProviderProps";
15
- var hiddenSize = 10000.1, sheetHiddenStyleSheet = null, relativeDimensionTo = isWeb ? "window" : "screen", SheetImplementationCustom = /* @__PURE__ */ React.forwardRef(function(props, forwardedRef) {
16
- var parentSheet = React.useContext(ParentSheetContext), { animation, animationConfig: animationConfigProp, modal = !1, zIndex = parentSheet.zIndex + 1, moveOnKeyboardChange = !1, unmountChildrenWhenHidden = !1, portalProps, containerComponent: ContainerComponent = React.Fragment } = props, state = useSheetOpenState(props), [overlayComponent, setOverlayComponent] = React.useState(null), providerProps = useSheetProviderProps(props, state, {
17
- onOverlayComponent: setOverlayComponent
18
- }), { frameSize, setFrameSize, snapPoints, snapPointsMode, hasFit, position, setPosition, scrollBridge, screenSize, setMaxContentSize, maxSnapPoint } = providerProps, { open, controller, isHidden } = state, sheetRef = React.useRef(void 0), ref = useComposedRefs(forwardedRef, sheetRef, providerProps.contentRef), { animationDriver } = useConfiguration();
19
- if (!animationDriver)
20
- throw new Error("Sheet reqiures an animation driver to be set");
21
- var animationConfig = function() {
22
- if (animationDriver.supportsCSS)
23
- return {};
24
- var [animationProp, animationPropConfig] = animation ? Array.isArray(animation) ? animation : [
25
- animation
26
- ] : [];
27
- return animationConfigProp ?? (animationProp ? {
28
- ...animationDriver.animations[animationProp],
29
- ...animationPropConfig
30
- } : null);
31
- }(), [isShowingInnerSheet, setIsShowingInnerSheet] = React.useState(!1), shouldHideParentSheet = !isWeb && modal && isShowingInnerSheet && // if not using weird portal limitation we dont need to hide parent sheet
32
- USE_NATIVE_PORTAL, sheetInsideSheet = React.useContext(SheetInsideSheetContext), onInnerSheet = React.useCallback(function(hasChild) {
33
- setIsShowingInnerSheet(hasChild);
34
- }, []), positions = React.useMemo(function() {
35
- return snapPoints.map(function(point) {
36
- return getYPositions(snapPointsMode, point, screenSize, frameSize);
1
+ "use strict";
2
+
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf,
8
+ __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: !0
37
13
  });
38
- }, [
39
- screenSize,
40
- frameSize,
41
- snapPoints,
42
- snapPointsMode
43
- ]), { useAnimatedNumber, useAnimatedNumberStyle, useAnimatedNumberReaction } = animationDriver, _animationDriver_View, AnimatedView = (_animationDriver_View = animationDriver.View) !== null && _animationDriver_View !== void 0 ? _animationDriver_View : Stack;
44
- useIsomorphicLayoutEffect(function() {
45
- if (sheetInsideSheet && open)
46
- return sheetInsideSheet(!0), function() {
14
+ },
15
+ __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
17
+ get: () => from[key],
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
+ value: mod,
29
+ enumerable: !0
30
+ }) : target, mod)),
31
+ __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
+ value: !0
33
+ }), mod);
34
+ var SheetImplementationCustom_exports = {};
35
+ __export(SheetImplementationCustom_exports, {
36
+ SheetImplementationCustom: () => SheetImplementationCustom
37
+ });
38
+ module.exports = __toCommonJS(SheetImplementationCustom_exports);
39
+ var import_jsx_runtime = require("react/jsx-runtime"),
40
+ import_adapt = require("@tamagui/adapt"),
41
+ import_animate_presence = require("@tamagui/animate-presence"),
42
+ import_compose_refs = require("@tamagui/compose-refs"),
43
+ import_constants = require("@tamagui/constants"),
44
+ import_core = require("@tamagui/core"),
45
+ import_portal = require("@tamagui/portal"),
46
+ import_react = __toESM(require("react"), 1),
47
+ import_react_native = require("react-native"),
48
+ import_contexts = require("./contexts.native.js"),
49
+ import_helpers = require("./helpers.native.js"),
50
+ import_SheetContext = require("./SheetContext.native.js"),
51
+ import_useSheetOpenState = require("./useSheetOpenState.native.js"),
52
+ import_useSheetProviderProps = require("./useSheetProviderProps.native.js"),
53
+ hiddenSize = 10000.1,
54
+ sheetHiddenStyleSheet = null,
55
+ relativeDimensionTo = import_constants.isWeb ? "window" : "screen",
56
+ SheetImplementationCustom = /* @__PURE__ */import_react.default.forwardRef(function (props, forwardedRef) {
57
+ var parentSheet = import_react.default.useContext(import_contexts.ParentSheetContext),
58
+ {
59
+ animation,
60
+ animationConfig: animationConfigProp,
61
+ modal = !1,
62
+ zIndex = parentSheet.zIndex + 1,
63
+ moveOnKeyboardChange = !1,
64
+ unmountChildrenWhenHidden = !1,
65
+ portalProps,
66
+ containerComponent: ContainerComponent = import_react.default.Fragment
67
+ } = props,
68
+ state = (0, import_useSheetOpenState.useSheetOpenState)(props),
69
+ [overlayComponent, setOverlayComponent] = import_react.default.useState(null),
70
+ providerProps = (0, import_useSheetProviderProps.useSheetProviderProps)(props, state, {
71
+ onOverlayComponent: setOverlayComponent
72
+ }),
73
+ {
74
+ frameSize,
75
+ setFrameSize,
76
+ snapPoints,
77
+ snapPointsMode,
78
+ hasFit,
79
+ position,
80
+ setPosition,
81
+ scrollBridge,
82
+ screenSize,
83
+ setMaxContentSize,
84
+ maxSnapPoint
85
+ } = providerProps,
86
+ {
87
+ open,
88
+ controller,
89
+ isHidden
90
+ } = state,
91
+ sheetRef = import_react.default.useRef(void 0),
92
+ ref = (0, import_compose_refs.useComposedRefs)(forwardedRef, sheetRef, providerProps.contentRef),
93
+ {
94
+ animationDriver
95
+ } = (0, import_core.useConfiguration)();
96
+ if (!animationDriver) throw new Error("Sheet reqiures an animation driver to be set");
97
+ var animationConfig = function () {
98
+ if (animationDriver.supportsCSS) return {};
99
+ var [animationProp, animationPropConfig] = animation ? Array.isArray(animation) ? animation : [animation] : [];
100
+ return animationConfigProp ?? (animationProp ? {
101
+ ...animationDriver.animations[animationProp],
102
+ ...animationPropConfig
103
+ } : null);
104
+ }(),
105
+ [isShowingInnerSheet, setIsShowingInnerSheet] = import_react.default.useState(!1),
106
+ shouldHideParentSheet = !import_constants.isWeb && modal && isShowingInnerSheet &&
107
+ // if not using weird portal limitation we dont need to hide parent sheet
108
+ import_portal.USE_NATIVE_PORTAL,
109
+ sheetInsideSheet = import_react.default.useContext(import_contexts.SheetInsideSheetContext),
110
+ onInnerSheet = import_react.default.useCallback(function (hasChild) {
111
+ setIsShowingInnerSheet(hasChild);
112
+ }, []),
113
+ positions = import_react.default.useMemo(function () {
114
+ return snapPoints.map(function (point) {
115
+ return getYPositions(snapPointsMode, point, screenSize, frameSize);
116
+ });
117
+ }, [screenSize, frameSize, snapPoints, snapPointsMode]),
118
+ {
119
+ useAnimatedNumber,
120
+ useAnimatedNumberStyle,
121
+ useAnimatedNumberReaction
122
+ } = animationDriver,
123
+ _animationDriver_View,
124
+ AnimatedView = (_animationDriver_View = animationDriver.View) !== null && _animationDriver_View !== void 0 ? _animationDriver_View : import_core.Stack;
125
+ (0, import_constants.useIsomorphicLayoutEffect)(function () {
126
+ if (sheetInsideSheet && open) return sheetInsideSheet(!0), function () {
47
127
  sheetInsideSheet(!1);
48
128
  };
49
- }, [
50
- sheetInsideSheet,
51
- open
52
- ]);
53
- var nextParentContext = React.useMemo(function() {
54
- return {
55
- zIndex
56
- };
57
- }, [
58
- zIndex
59
- ]), isMounted = useDidFinishSSR(), startPosition = isMounted && screenSize ? screenSize : hiddenSize, animatedNumber = useAnimatedNumber(startPosition), at = React.useRef(startPosition), hasntMeasured = at.current === hiddenSize, [disableAnimation, setDisableAnimation] = useState(hasntMeasured), hasScrollView = React.useRef(!1);
60
- useAnimatedNumberReaction({
61
- value: animatedNumber,
62
- hostRef: sheetRef
63
- }, React.useCallback(function(value) {
64
- at.current = value, scrollBridge.paneY = value;
65
- }, [
66
- animationDriver
67
- ]));
68
- function stopSpring() {
69
- animatedNumber.stop(), scrollBridge.onFinishAnimate && (scrollBridge.onFinishAnimate(), scrollBridge.onFinishAnimate = void 0);
70
- }
71
- var animateTo = useEvent(function(position2) {
72
- if (frameSize !== 0) {
73
- var toValue = isHidden || position2 === -1 ? screenSize : positions[position2];
74
- at.current !== toValue && (at.current = toValue, stopSpring(), animatedNumber.setValue(toValue, {
75
- type: "spring",
76
- ...animationConfig
77
- }));
78
- }
79
- });
80
- useIsomorphicLayoutEffect(function() {
81
- if (hasntMeasured && screenSize && frameSize) {
82
- at.current = screenSize, animatedNumber.setValue(screenSize, {
83
- type: "timing",
84
- duration: 0
85
- }, function() {
86
- setTimeout(function() {
87
- setDisableAnimation(!1);
88
- }, 10);
89
- });
90
- return;
129
+ }, [sheetInsideSheet, open]);
130
+ var nextParentContext = import_react.default.useMemo(function () {
131
+ return {
132
+ zIndex
133
+ };
134
+ }, [zIndex]),
135
+ isMounted = (0, import_core.useDidFinishSSR)(),
136
+ startPosition = isMounted && screenSize ? screenSize : hiddenSize,
137
+ animatedNumber = useAnimatedNumber(startPosition),
138
+ at = import_react.default.useRef(startPosition),
139
+ hasntMeasured = at.current === hiddenSize,
140
+ [disableAnimation, setDisableAnimation] = (0, import_react.useState)(hasntMeasured),
141
+ hasScrollView = import_react.default.useRef(!1);
142
+ useAnimatedNumberReaction({
143
+ value: animatedNumber,
144
+ hostRef: sheetRef
145
+ }, import_react.default.useCallback(function (value) {
146
+ at.current = value, scrollBridge.paneY = value;
147
+ }, [animationDriver]));
148
+ function stopSpring() {
149
+ animatedNumber.stop(), scrollBridge.onFinishAnimate && (scrollBridge.onFinishAnimate(), scrollBridge.onFinishAnimate = void 0);
91
150
  }
92
- disableAnimation || !frameSize || !screenSize || isHidden || hasntMeasured && !open || (animateTo(position), position === -1 && (scrollBridge.scrollLock = !1, scrollBridge.scrollStartY = -1));
93
- }, [
94
- hasntMeasured,
95
- disableAnimation,
96
- isHidden,
97
- frameSize,
98
- screenSize,
99
- open,
100
- position
101
- ]);
102
- var _props_disableDrag, disableDrag = (_props_disableDrag = props.disableDrag) !== null && _props_disableDrag !== void 0 ? _props_disableDrag : controller == null ? void 0 : controller.disableDrag, themeName = useThemeName(), [isDragging, setIsDragging] = React.useState(!1), panResponder = React.useMemo(function() {
103
- if (disableDrag || !frameSize || isShowingInnerSheet) return;
104
- var minY = positions[0];
105
- scrollBridge.paneMinY = minY;
106
- var startY = at.current;
107
- function setPanning(val) {
108
- setIsDragging(val), isClient && (sheetHiddenStyleSheet || (sheetHiddenStyleSheet = document.createElement("style"), typeof document.head < "u" && document.head.appendChild(sheetHiddenStyleSheet)), val ? sheetHiddenStyleSheet.innerText = ":root * { user-select: none !important; -webkit-user-select: none !important; }" : sheetHiddenStyleSheet.innerText = "");
109
- }
110
- var release = function(param) {
111
- var { vy, dragAt } = param;
112
- if (scrollBridge.setParentDragging(!1), !scrollBridge.scrollLock) {
113
- isExternalDrag = !1, previouslyScrolling = !1, setPanning(!1);
114
- for (var at2 = dragAt + startY, end = at2 + frameSize * vy * 0.2, closestPoint = 0, dist = Number.POSITIVE_INFINITY, i = 0; i < positions.length; i++) {
115
- var position2 = positions[i], curDist = end > position2 ? end - position2 : position2 - end;
116
- curDist < dist && (dist = curDist, closestPoint = i);
117
- }
118
- setPosition(closestPoint), animateTo(closestPoint);
119
- }
120
- }, finish = function(_e, state2) {
121
- release({
122
- vy: state2.vy,
123
- dragAt: state2.dy
124
- });
125
- }, previouslyScrolling = !1, onMoveShouldSet = function(e, param) {
126
- var { dy } = param;
127
- function getShouldSet() {
128
- if (e.target === providerProps.handleRef.current)
129
- return !0;
130
- if (scrollBridge.hasScrollableContent === !0) {
131
- if (scrollBridge.scrollLock)
132
- return !1;
133
- var isScrolled = scrollBridge.y !== 0, isDraggingUp = dy < 0, isNearTop = scrollBridge.paneY - 5 <= scrollBridge.paneMinY;
134
- if (isScrolled)
135
- return previouslyScrolling = !0, !1;
136
- if (isNearTop && hasScrollView.current && isDraggingUp)
137
- return !1;
138
- }
139
- return Math.abs(dy) > 10;
151
+ var animateTo = (0, import_core.useEvent)(function (position2) {
152
+ if (frameSize !== 0) {
153
+ var toValue = isHidden || position2 === -1 ? screenSize : positions[position2];
154
+ at.current !== toValue && (at.current = toValue, stopSpring(), animatedNumber.setValue(toValue, {
155
+ type: "spring",
156
+ ...animationConfig
157
+ }));
140
158
  }
141
- var granted = getShouldSet();
142
- return granted && scrollBridge.setParentDragging(!0), granted;
143
- }, grant = function() {
144
- setPanning(!0), stopSpring(), startY = at.current;
145
- }, isExternalDrag = !1;
146
- return scrollBridge.drag = function(dy) {
147
- isExternalDrag || (isExternalDrag = !0, grant());
148
- var to = dy + startY;
149
- animatedNumber.setValue(resisted(to, minY), {
150
- type: "direct"
151
- });
152
- }, scrollBridge.release = release, PanResponder.create({
153
- onMoveShouldSetPanResponder: onMoveShouldSet,
154
- onPanResponderGrant: grant,
155
- onPanResponderMove: function(_e, param) {
156
- var { dy } = param, toFull = dy + startY, to = resisted(toFull, minY), isAtTop = to <= minY;
157
- isAtTop ? scrollBridge.setParentDragging(!1) : scrollBridge.setParentDragging(!0), animatedNumber.setValue(to, {
158
- type: "direct"
159
- });
160
- },
161
- onPanResponderEnd: finish,
162
- onPanResponderTerminate: finish,
163
- onPanResponderRelease: finish
164
159
  });
165
- }, [
166
- disableDrag,
167
- isShowingInnerSheet,
168
- animateTo,
169
- frameSize,
170
- positions,
171
- setPosition
172
- ]), handleAnimationViewLayout = React.useCallback(function(e) {
173
- var _e_nativeEvent, next = Math.min((_e_nativeEvent = e.nativeEvent) === null || _e_nativeEvent === void 0 ? void 0 : _e_nativeEvent.layout.height, Dimensions.get(relativeDimensionTo).height);
174
- next && setFrameSize(next);
175
- }, []), handleMaxContentViewLayout = React.useCallback(function(e) {
176
- var _e_nativeEvent, next = Math.min((_e_nativeEvent = e.nativeEvent) === null || _e_nativeEvent === void 0 ? void 0 : _e_nativeEvent.layout.height, Dimensions.get(relativeDimensionTo).height);
177
- next && setMaxContentSize(next);
178
- }, []), animatedStyle = useAnimatedNumberStyle(animatedNumber, function(val) {
179
- "worklet";
180
- var translateY = frameSize === 0 ? hiddenSize : val;
181
- return {
182
- transform: [
183
- {
184
- translateY
185
- }
186
- ]
187
- };
188
- }), sizeBeforeKeyboard = React.useRef(null);
189
- React.useEffect(function() {
190
- if (!(isWeb || !moveOnKeyboardChange)) {
191
- var keyboardShowListener = Keyboard.addListener(currentPlatform === "ios" ? "keyboardWillShow" : "keyboardDidShow", function(e) {
192
- sizeBeforeKeyboard.current === null && (sizeBeforeKeyboard.current = isHidden || position === -1 ? screenSize : positions[position], animatedNumber.setValue(Math.max(sizeBeforeKeyboard.current - e.endCoordinates.height, 0), {
160
+ (0, import_constants.useIsomorphicLayoutEffect)(function () {
161
+ if (hasntMeasured && screenSize && frameSize) {
162
+ at.current = screenSize, animatedNumber.setValue(screenSize, {
193
163
  type: "timing",
194
- duration: 250
195
- }));
196
- }), keyboardDidHideListener = Keyboard.addListener("keyboardDidHide", function() {
197
- sizeBeforeKeyboard.current !== null && (animatedNumber.setValue(sizeBeforeKeyboard.current, {
198
- type: "timing",
199
- duration: 250
200
- }), sizeBeforeKeyboard.current = null);
201
- });
202
- return function() {
203
- keyboardDidHideListener.remove(), keyboardShowListener.remove();
204
- };
205
- }
206
- }, [
207
- moveOnKeyboardChange,
208
- positions,
209
- position,
210
- isHidden
211
- ]);
212
- var [opacity, setOpacity] = React.useState(open ? 1 : 0);
213
- open && opacity === 0 && setOpacity(1), React.useEffect(function() {
214
- if (!open) {
215
- var tm = setTimeout(function() {
216
- setOpacity(0);
217
- }, 400);
218
- return function() {
219
- clearTimeout(tm);
220
- };
221
- }
222
- }, [
223
- open
224
- ]);
225
- var forcedContentHeight = hasFit ? void 0 : snapPointsMode === "percent" ? `${maxSnapPoint}${isWeb ? "dvh" : "%"}` : maxSnapPoint, setHasScrollView = React.useCallback(function(val) {
226
- hasScrollView.current = val;
227
- }, []), contents = /* @__PURE__ */ _jsx(LayoutMeasurementController, {
228
- disable: !open,
229
- children: /* @__PURE__ */ _jsx(ParentSheetContext.Provider, {
230
- value: nextParentContext,
231
- children: /* @__PURE__ */ _jsxs(SheetProvider, {
232
- ...providerProps,
233
- setHasScrollView,
234
- children: [
235
- /* @__PURE__ */ _jsx(AnimatePresence, {
236
- custom: {
237
- open
238
- },
239
- children: shouldHideParentSheet || !open ? null : overlayComponent
240
- }),
241
- snapPointsMode !== "percent" && /* @__PURE__ */ _jsx(View, {
242
- style: {
243
- opacity: 0,
244
- position: "absolute",
245
- top: 0,
246
- left: 0,
247
- right: 0,
248
- bottom: 0,
249
- pointerEvents: "none"
250
- },
251
- onLayout: handleMaxContentViewLayout
164
+ duration: 0
165
+ }, function () {
166
+ setTimeout(function () {
167
+ setDisableAnimation(!1);
168
+ }, 10);
169
+ });
170
+ return;
171
+ }
172
+ disableAnimation || !frameSize || !screenSize || isHidden || hasntMeasured && !open || (animateTo(position), position === -1 && (scrollBridge.scrollLock = !1, scrollBridge.scrollStartY = -1));
173
+ }, [hasntMeasured, disableAnimation, isHidden, frameSize, screenSize, open, position]);
174
+ var _props_disableDrag,
175
+ disableDrag = (_props_disableDrag = props.disableDrag) !== null && _props_disableDrag !== void 0 ? _props_disableDrag : controller?.disableDrag,
176
+ themeName = (0, import_core.useThemeName)(),
177
+ [isDragging, setIsDragging] = import_react.default.useState(!1),
178
+ panResponder = import_react.default.useMemo(function () {
179
+ if (disableDrag || !frameSize || isShowingInnerSheet) return;
180
+ var minY = positions[0];
181
+ scrollBridge.paneMinY = minY;
182
+ var startY = at.current;
183
+ function setPanning(val) {
184
+ setIsDragging(val), import_constants.isClient && (sheetHiddenStyleSheet || (sheetHiddenStyleSheet = document.createElement("style"), typeof document.head < "u" && document.head.appendChild(sheetHiddenStyleSheet)), val ? sheetHiddenStyleSheet.innerText = ":root * { user-select: none !important; -webkit-user-select: none !important; }" : sheetHiddenStyleSheet.innerText = "");
185
+ }
186
+ var release = function (param) {
187
+ var {
188
+ vy,
189
+ dragAt
190
+ } = param;
191
+ if (scrollBridge.setParentDragging(!1), !scrollBridge.scrollLock) {
192
+ isExternalDrag = !1, previouslyScrolling = !1, setPanning(!1);
193
+ for (var at2 = dragAt + startY, end = at2 + frameSize * vy * 0.2, closestPoint = 0, dist = Number.POSITIVE_INFINITY, i = 0; i < positions.length; i++) {
194
+ var position2 = positions[i],
195
+ curDist = end > position2 ? end - position2 : position2 - end;
196
+ curDist < dist && (dist = curDist, closestPoint = i);
197
+ }
198
+ setPosition(closestPoint), animateTo(closestPoint);
199
+ }
200
+ },
201
+ finish = function (_e, state2) {
202
+ release({
203
+ vy: state2.vy,
204
+ dragAt: state2.dy
205
+ });
206
+ },
207
+ previouslyScrolling = !1,
208
+ onMoveShouldSet = function (e, param) {
209
+ var {
210
+ dy
211
+ } = param;
212
+ function getShouldSet() {
213
+ if (e.target === providerProps.handleRef.current) return !0;
214
+ if (scrollBridge.hasScrollableContent === !0) {
215
+ if (scrollBridge.scrollLock) return !1;
216
+ var isScrolled = scrollBridge.y !== 0,
217
+ isDraggingUp = dy < 0,
218
+ isNearTop = scrollBridge.paneY - 5 <= scrollBridge.paneMinY;
219
+ if (isScrolled) return previouslyScrolling = !0, !1;
220
+ if (isNearTop && hasScrollView.current && isDraggingUp) return !1;
221
+ }
222
+ return Math.abs(dy) > 10;
223
+ }
224
+ var granted = getShouldSet();
225
+ return granted && scrollBridge.setParentDragging(!0), granted;
226
+ },
227
+ grant = function () {
228
+ setPanning(!0), stopSpring(), startY = at.current;
229
+ },
230
+ isExternalDrag = !1;
231
+ return scrollBridge.drag = function (dy) {
232
+ isExternalDrag || (isExternalDrag = !0, grant());
233
+ var to = dy + startY;
234
+ animatedNumber.setValue((0, import_helpers.resisted)(to, minY), {
235
+ type: "direct"
236
+ });
237
+ }, scrollBridge.release = release, import_react_native.PanResponder.create({
238
+ onMoveShouldSetPanResponder: onMoveShouldSet,
239
+ onPanResponderGrant: grant,
240
+ onPanResponderMove: function (_e, param) {
241
+ var {
242
+ dy
243
+ } = param,
244
+ toFull = dy + startY,
245
+ to = (0, import_helpers.resisted)(toFull, minY),
246
+ isAtTop = to <= minY;
247
+ isAtTop ? scrollBridge.setParentDragging(!1) : scrollBridge.setParentDragging(!0), animatedNumber.setValue(to, {
248
+ type: "direct"
249
+ });
250
+ },
251
+ onPanResponderEnd: finish,
252
+ onPanResponderTerminate: finish,
253
+ onPanResponderRelease: finish
254
+ });
255
+ }, [disableDrag, isShowingInnerSheet, animateTo, frameSize, positions, setPosition]),
256
+ handleAnimationViewLayout = import_react.default.useCallback(function (e) {
257
+ var _e_nativeEvent,
258
+ next = Math.min((_e_nativeEvent = e.nativeEvent) === null || _e_nativeEvent === void 0 ? void 0 : _e_nativeEvent.layout.height, import_react_native.Dimensions.get(relativeDimensionTo).height);
259
+ next && setFrameSize(next);
260
+ }, []),
261
+ handleMaxContentViewLayout = import_react.default.useCallback(function (e) {
262
+ var _e_nativeEvent,
263
+ next = Math.min((_e_nativeEvent = e.nativeEvent) === null || _e_nativeEvent === void 0 ? void 0 : _e_nativeEvent.layout.height, import_react_native.Dimensions.get(relativeDimensionTo).height);
264
+ next && setMaxContentSize(next);
265
+ }, []),
266
+ animatedStyle = useAnimatedNumberStyle(animatedNumber, function (val) {
267
+ "worklet";
268
+
269
+ var translateY = frameSize === 0 ? hiddenSize : val;
270
+ return {
271
+ transform: [{
272
+ translateY
273
+ }]
274
+ };
275
+ }),
276
+ sizeBeforeKeyboard = import_react.default.useRef(null);
277
+ import_react.default.useEffect(function () {
278
+ if (!(import_constants.isWeb || !moveOnKeyboardChange)) {
279
+ var keyboardShowListener = import_react_native.Keyboard.addListener(import_constants.currentPlatform === "ios" ? "keyboardWillShow" : "keyboardDidShow", function (e) {
280
+ sizeBeforeKeyboard.current === null && (sizeBeforeKeyboard.current = isHidden || position === -1 ? screenSize : positions[position], animatedNumber.setValue(Math.max(sizeBeforeKeyboard.current - e.endCoordinates.height, 0), {
281
+ type: "timing",
282
+ duration: 250
283
+ }));
252
284
  }),
253
- /* @__PURE__ */ _jsx(AnimatedView, {
254
- ref,
255
- ...panResponder == null ? void 0 : panResponder.panHandlers,
256
- onLayout: handleAnimationViewLayout,
257
- // @ts-ignore for CSS driver this is necessary to attach the transition
258
- // also motion driver at least though i suspect all drivers?
259
- animation: isDragging || disableAnimation ? null : animation,
260
- // @ts-ignore
261
- disableClassName: !0,
262
- style: [
263
- {
285
+ keyboardDidHideListener = import_react_native.Keyboard.addListener("keyboardDidHide", function () {
286
+ sizeBeforeKeyboard.current !== null && (animatedNumber.setValue(sizeBeforeKeyboard.current, {
287
+ type: "timing",
288
+ duration: 250
289
+ }), sizeBeforeKeyboard.current = null);
290
+ });
291
+ return function () {
292
+ keyboardDidHideListener.remove(), keyboardShowListener.remove();
293
+ };
294
+ }
295
+ }, [moveOnKeyboardChange, positions, position, isHidden]);
296
+ var [opacity, setOpacity] = import_react.default.useState(open ? 1 : 0);
297
+ open && opacity === 0 && setOpacity(1), import_react.default.useEffect(function () {
298
+ if (!open) {
299
+ var tm = setTimeout(function () {
300
+ setOpacity(0);
301
+ }, 400);
302
+ return function () {
303
+ clearTimeout(tm);
304
+ };
305
+ }
306
+ }, [open]);
307
+ var forcedContentHeight = hasFit ? void 0 : snapPointsMode === "percent" ? `${maxSnapPoint}${import_constants.isWeb ? "dvh" : "%"}` : maxSnapPoint,
308
+ setHasScrollView = import_react.default.useCallback(function (val) {
309
+ hasScrollView.current = val;
310
+ }, []),
311
+ contents = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.LayoutMeasurementController, {
312
+ disable: !open,
313
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_contexts.ParentSheetContext.Provider, {
314
+ value: nextParentContext,
315
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_SheetContext.SheetProvider, {
316
+ ...providerProps,
317
+ setHasScrollView,
318
+ children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_animate_presence.AnimatePresence, {
319
+ custom: {
320
+ open
321
+ },
322
+ children: shouldHideParentSheet || !open ? null : overlayComponent
323
+ }), snapPointsMode !== "percent" && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react_native.View, {
324
+ style: {
325
+ opacity: 0,
326
+ position: "absolute",
327
+ top: 0,
328
+ left: 0,
329
+ right: 0,
330
+ bottom: 0,
331
+ pointerEvents: "none"
332
+ },
333
+ onLayout: handleMaxContentViewLayout
334
+ }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(AnimatedView, {
335
+ ref,
336
+ ...panResponder?.panHandlers,
337
+ onLayout: handleAnimationViewLayout,
338
+ // @ts-ignore for CSS driver this is necessary to attach the transition
339
+ // also motion driver at least though i suspect all drivers?
340
+ animation: isDragging || disableAnimation ? null : animation,
341
+ // @ts-ignore
342
+ disableClassName: !0,
343
+ style: [{
264
344
  position: "absolute",
265
345
  zIndex,
266
346
  width: "100%",
267
347
  height: forcedContentHeight,
268
348
  minHeight: forcedContentHeight,
269
349
  opacity: shouldHideParentSheet ? 0 : opacity,
270
- ...(shouldHideParentSheet || !open) && {
350
+ ...((shouldHideParentSheet || !open) && {
271
351
  pointerEvents: "none"
272
- }
273
- },
274
- animatedStyle
275
- ],
276
- children: (
277
- /* <AdaptProvider>{props.children}</AdaptProvider> */
278
- props.children
279
- )
352
+ })
353
+ }, animatedStyle],
354
+ children: (/* <AdaptProvider>{props.children}</AdaptProvider> */
355
+ props.children)
356
+ })]
280
357
  })
281
- ]
282
- })
283
- })
284
- });
285
- if (!USE_NATIVE_PORTAL) {
286
- var adaptContext = useAdaptContext();
287
- contents = /* @__PURE__ */ _jsx(ProvideAdaptContext, {
288
- ...adaptContext,
289
- children: (
290
- /* @ts-ignore */
291
- contents
292
- )
293
- });
294
- }
295
- var shouldMountChildren = unmountChildrenWhenHidden ? !!opacity : !0;
296
- if (modal) {
297
- var modalContents = /* @__PURE__ */ _jsx(Portal, {
298
- stackZIndex: zIndex,
299
- ...portalProps,
300
- children: shouldMountChildren && /* @__PURE__ */ _jsx(ContainerComponent, {
301
- children: /* @__PURE__ */ _jsx(Theme, {
302
- contain: !0,
303
- forceClassName: !0,
304
- name: themeName,
305
- children: contents
306
358
  })
307
- })
308
- });
309
- return isWeb ? modalContents : /* @__PURE__ */ _jsx(SheetInsideSheetContext.Provider, {
310
- value: onInnerSheet,
311
- children: modalContents
312
- });
313
- }
314
- return contents;
315
- });
359
+ });
360
+ if (!import_portal.USE_NATIVE_PORTAL) {
361
+ var adaptContext = (0, import_adapt.useAdaptContext)();
362
+ contents = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_adapt.ProvideAdaptContext, {
363
+ ...adaptContext,
364
+ children: (/* @ts-ignore */
365
+ contents)
366
+ });
367
+ }
368
+ var shouldMountChildren = unmountChildrenWhenHidden ? !!opacity : !0;
369
+ if (modal) {
370
+ var modalContents = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_portal.Portal, {
371
+ stackZIndex: zIndex,
372
+ ...portalProps,
373
+ children: shouldMountChildren && /* @__PURE__ */(0, import_jsx_runtime.jsx)(ContainerComponent, {
374
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.Theme, {
375
+ contain: !0,
376
+ forceClassName: !0,
377
+ name: themeName,
378
+ children: contents
379
+ })
380
+ })
381
+ });
382
+ return import_constants.isWeb ? modalContents : /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_contexts.SheetInsideSheetContext.Provider, {
383
+ value: onInnerSheet,
384
+ children: modalContents
385
+ });
386
+ }
387
+ return contents;
388
+ });
316
389
  function getYPositions(mode, point, screenSize, frameSize) {
317
390
  if (!screenSize || !frameSize) return 0;
318
391
  if (mode === "mixed") {
319
- if (typeof point == "number")
320
- return screenSize - Math.min(screenSize, Math.max(0, point));
321
- if (point === "fit")
322
- return screenSize - Math.min(screenSize, frameSize);
392
+ if (typeof point == "number") return screenSize - Math.min(screenSize, Math.max(0, point));
393
+ if (point === "fit") return screenSize - Math.min(screenSize, frameSize);
323
394
  if (point.endsWith("%")) {
324
395
  var pct = Math.min(100, Math.max(0, Number(point.slice(0, -1)))) / 100;
325
- if (Number.isNaN(pct))
326
- return console.warn("Invalid snapPoint percentage string"), 0;
396
+ if (Number.isNaN(pct)) return console.warn("Invalid snapPoint percentage string"), 0;
327
397
  var next = Math.round(screenSize - pct * screenSize);
328
398
  return next;
329
399
  }
330
400
  return console.warn("Invalid snapPoint unknown value"), 0;
331
401
  }
332
- if (mode === "fit")
333
- return point === 0 ? screenSize : screenSize - Math.min(screenSize, frameSize);
334
- if (mode === "constant" && typeof point == "number")
335
- return screenSize - Math.min(screenSize, Math.max(0, point));
402
+ if (mode === "fit") return point === 0 ? screenSize : screenSize - Math.min(screenSize, frameSize);
403
+ if (mode === "constant" && typeof point == "number") return screenSize - Math.min(screenSize, Math.max(0, point));
336
404
  var pct1 = Math.min(100, Math.max(0, Number(point))) / 100;
337
405
  return Number.isNaN(pct1) ? (console.warn("Invalid snapPoint percentage"), 0) : Math.round(screenSize - pct1 * screenSize);
338
406
  }
339
- export {
340
- SheetImplementationCustom
341
- };
342
- //# sourceMappingURL=SheetImplementationCustom.js.map
407
+ //# sourceMappingURL=SheetImplementationCustom.native.js.map