@tamagui/sheet 1.14.0 → 1.14.2

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 (53) hide show
  1. package/dist/cjs/Sheet.js +659 -1
  2. package/dist/cjs/Sheet.js.map +2 -2
  3. package/dist/cjs/SheetContext.js +40 -1
  4. package/dist/cjs/SheetContext.js.map +2 -2
  5. package/dist/cjs/SheetScrollView.js +104 -1
  6. package/dist/cjs/SheetScrollView.js.map +2 -2
  7. package/dist/cjs/constants.js +34 -1
  8. package/dist/cjs/constants.js.map +2 -2
  9. package/dist/cjs/index.js +18 -1
  10. package/dist/cjs/index.js.map +2 -2
  11. package/dist/cjs/types.js +16 -1
  12. package/dist/cjs/types.js.map +2 -2
  13. package/dist/esm/Sheet.js +643 -1
  14. package/dist/esm/Sheet.js.map +2 -2
  15. package/dist/esm/Sheet.mjs +643 -1
  16. package/dist/esm/Sheet.mjs.map +2 -2
  17. package/dist/esm/SheetContext.js +13 -1
  18. package/dist/esm/SheetContext.js.map +2 -2
  19. package/dist/esm/SheetContext.mjs +13 -1
  20. package/dist/esm/SheetContext.mjs.map +2 -2
  21. package/dist/esm/SheetScrollView.js +80 -1
  22. package/dist/esm/SheetScrollView.js.map +2 -2
  23. package/dist/esm/SheetScrollView.mjs +80 -1
  24. package/dist/esm/SheetScrollView.mjs.map +2 -2
  25. package/dist/esm/constants.js +8 -1
  26. package/dist/esm/constants.js.map +2 -2
  27. package/dist/esm/constants.mjs +8 -1
  28. package/dist/esm/constants.mjs.map +2 -2
  29. package/dist/esm/index.js +1 -1
  30. package/dist/esm/index.js.map +1 -1
  31. package/dist/esm/index.mjs +1 -1
  32. package/dist/esm/index.mjs.map +1 -1
  33. package/dist/jsx/Sheet.js +621 -1
  34. package/dist/jsx/Sheet.js.map +2 -2
  35. package/dist/jsx/Sheet.mjs +621 -1
  36. package/dist/jsx/Sheet.mjs.map +2 -2
  37. package/dist/jsx/SheetContext.js +13 -1
  38. package/dist/jsx/SheetContext.js.map +2 -2
  39. package/dist/jsx/SheetContext.mjs +13 -1
  40. package/dist/jsx/SheetContext.mjs.map +2 -2
  41. package/dist/jsx/SheetScrollView.js +75 -1
  42. package/dist/jsx/SheetScrollView.js.map +2 -2
  43. package/dist/jsx/SheetScrollView.mjs +75 -1
  44. package/dist/jsx/SheetScrollView.mjs.map +2 -2
  45. package/dist/jsx/constants.js +8 -1
  46. package/dist/jsx/constants.js.map +2 -2
  47. package/dist/jsx/constants.mjs +8 -1
  48. package/dist/jsx/constants.mjs.map +2 -2
  49. package/dist/jsx/index.js +1 -1
  50. package/dist/jsx/index.js.map +1 -1
  51. package/dist/jsx/index.mjs +1 -1
  52. package/dist/jsx/index.mjs.map +1 -1
  53. package/package.json +13 -13
package/dist/cjs/Sheet.js CHANGED
@@ -1,2 +1,660 @@
1
- "use strict";var pt=Object.create;var z=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var ht=Object.getOwnPropertyNames;var ft=Object.getPrototypeOf,St=Object.prototype.hasOwnProperty;var Pt=(o,r)=>{for(var e in r)z(o,e,{get:r[e],enumerable:!0})},ve=(o,r,e,l)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of ht(r))!St.call(o,a)&&a!==e&&z(o,a,{get:()=>r[a],enumerable:!(l=mt(r,a))||l.enumerable});return o};var bt=(o,r,e)=>(e=o!=null?pt(ft(o)):{},ve(r||!o||!o.__esModule?z(e,"default",{value:o,enumerable:!0}):e,o)),gt=o=>ve(z({},"__esModule",{value:!0}),o);var Et={};Pt(Et,{ControlledSheet:()=>Ct,Sheet:()=>He,SheetController:()=>Rt,SheetFrame:()=>Ie,SheetFrameFrame:()=>oe,SheetHandle:()=>De,SheetHandleFrame:()=>te,SheetOverlay:()=>Te,SheetOverlayFrame:()=>ne,createSheetScope:()=>Me.createSheetScope});module.exports=gt(Et);var u=require("react/jsx-runtime"),Q=require("@tamagui/adapt"),j=require("@tamagui/compose-refs"),s=require("@tamagui/core"),Ve=require("@tamagui/portal"),Oe=require("@tamagui/remove-scroll"),E=require("@tamagui/stacks"),ke=require("@tamagui/use-constant"),ee=require("@tamagui/use-controllable-state"),Ne=require("@tamagui/use-keyboard-visible"),n=bt(require("react")),H=require("react-native"),R=require("./constants"),x=require("./SheetContext"),Ae=require("./SheetScrollView"),Me=require("./SheetContext");const te=(0,s.styled)(E.XStack,{name:R.SHEET_HANDLE_NAME,height:10,borderRadius:100,backgroundColor:"$background",zIndex:10,marginHorizontal:"35%",marginBottom:"$2",opacity:.5,hoverStyle:{opacity:.7},variants:{open:{true:{pointerEvents:"auto"},false:{opacity:0,pointerEvents:"none"}}}}),De=te.extractable(({__scopeSheet:o,...r})=>{const e=(0,x.useSheetContext)(R.SHEET_HANDLE_NAME,o);return(0,u.jsx)(te,{onPress:()=>{const l=e.snapPoints.length+(e.dismissOnSnapToBottom?-1:0),a=(e.position+1)%l;e.setPosition(a)},open:e.open,...r})}),ye="SheetOverlay",ne=(0,s.styled)(E.ThemeableStack,{name:ye,fullscreen:!0,backgrounded:!0,opacity:.5,zIndex:0,variants:{closed:{true:{opacity:0,pointerEvents:"none"},false:{pointerEvents:"auto"}}}}),Te=ne.extractable(({__scopeSheet:o,...r})=>{const e=(0,x.useSheetContext)(ye,o);return(0,u.jsx)(ne,{closed:!e.open||e.hidden,...r,onPress:(0,s.mergeEvent)(r.onPress,e.dismissOnOverlayPress?()=>{e.setOpen(!1)}:void 0)})}),I=s.isClient?document.createElement("style"):null;I&&document.head.appendChild(I);const oe=(0,s.styled)(E.YStack,{name:R.SHEET_NAME,flex:1,backgroundColor:"$background",borderTopLeftRadius:"$true",borderTopRightRadius:"$true",width:"100%",maxHeight:"100%",overflow:"hidden",pointerEvents:"auto"}),Ie=oe.extractable((0,n.forwardRef)(({__scopeSheet:o,...r},e)=>{const l=(0,x.useSheetContext)(R.SHEET_NAME,o),a=(0,j.useComposedRefs)(e,l.contentRef);return(0,u.jsx)(oe,{ref:a,...r})})),G=1e4,vt={Handle:De,Frame:Ie,Overlay:Te,ScrollView:Ae.SheetScrollView},Ce=(0,n.createContext)({zIndex:40}),xe=()=>{const o=(0,n.useContext)(we),r=o==null?void 0:o.hidden,e=r&&(o==null?void 0:o.open);return{controller:o,isHidden:r,isShowingNonSheet:e}},He=(0,s.withStaticProperties)((0,n.forwardRef)(function(r,e){const l=(0,s.useDidFinishSSR)(),{isShowingNonSheet:a}=xe();return a||!l?null:(0,u.jsx)(yt,{ref:e,...r})}),vt),yt=(0,s.themeable)((0,n.forwardRef)(function(r,e){const l=(0,n.useContext)(Ce),{isHidden:a,controller:d}=xe(),{__scopeSheet:$,snapPoints:M=[80],open:Fe,defaultOpen:wt,children:_e,position:Ye,onPositionChange:Be,onOpenChange:K,defaultPosition:Le,dismissOnOverlayPress:ze=!0,animationConfig:Ge,dismissOnSnapToBottom:v=!1,forceRemoveScrollEnabled:$e=null,disableDrag:Ke,modal:F=!1,zIndex:_=l.zIndex+1,moveOnKeyboardChange:Xe=!1,portalProps:Ue}=r;process.env.NODE_ENV==="development"&&M.some(t=>t<0||t>100)&&console.warn("\u26A0\uFE0F Invalid snapPoint given, snapPoints must be between 0 and 100, equal to percent height of frame");const re=(0,n.useRef)(null),We=(0,j.useComposedRefs)(e,re),w=(0,s.useAnimationDriver)();if(!w)throw new Error("Must set animations in tamagui.config.ts");const se=Ke??(d==null?void 0:d.disableDrag),Ze=(0,Ne.useKeyboardVisible)(),qe=(0,s.useThemeName)(),ae=n.default.useRef(null),m=(0,ke.useConstant)(()=>({enabled:!1,y:0,paneY:0,paneMinY:0,scrollStartY:-1,drag:()=>{},release:()=>{},scrollLock:!1})),Je=t=>{var i;(i=d==null?void 0:d.onOpenChange)==null||i.call(d,t),K==null||K(t)},[c,X]=(0,ee.useControllableState)({prop:(d==null?void 0:d.open)??Fe,defaultProp:!0,onChange:Je,strategy:"most-recent-wins",transition:!0}),[h,Qe]=(0,n.useState)(0),y=(0,n.useMemo)(()=>v?[...M,0]:M,[JSON.stringify(M),v]),[je,U]=(0,ee.useControllableState)({prop:Ye,defaultProp:Le||(c?0:-1),onChange:Be,strategy:"most-recent-wins",transition:!0}),V=c===!1?-1:je;c&&v&&V===y.length-1&&U(0);const O=(0,n.useCallback)(t=>{v&&t===y.length-1?X(!1):U(t)},[v,y.length,U,X]),{useAnimatedNumber:et,useAnimatedNumberReaction:tt,useAnimatedNumberStyle:nt}=w,p=et(G),C=(0,n.useRef)(0);tt({value:p,hostRef:re},t=>{w.isReactNative&&(C.current=t,m.paneY=t)});function ie(){p.stop(),m.onFinishAnimate&&(m.onFinishAnimate(),m.onFinishAnimate=void 0)}const le=c&&V<0;(0,n.useEffect)(()=>{le&&O(0)},[O,le]);const k=(0,n.useMemo)(()=>y.map(t=>xt(t,h)),[h,y]),[ce,ue]=(0,n.useState)(c?1:0);c&&ce===0&&ue(1),(0,n.useEffect)(()=>{if(!c){const t=setTimeout(()=>{ue(0)},400);return()=>{clearTimeout(t)}}},[c]);const Y=(0,s.useEvent)(t=>{const i=p.getValue();if(a&&c||!i||h===0)return;const P=a||t===-1?h===0?G:h:k[t];if(C.current===P)return;if(ie(),a){p.setValue(P,{type:"timing",duration:0}),C.current=P;return}const A=C.current===G;p.setValue(P,{...Ge,type:"spring",overshootClamping:A})});(0,s.useIsomorphicLayoutEffect)(()=>{Y(V)},[a,h,V,Y]);const[W,ot]=(0,n.useState)(!1),de=!s.isWeb&&F&&W,B=(0,n.useContext)(Re),rt=(0,n.useCallback)(t=>{ot(t)},[]),Z=(0,n.useMemo)(()=>{if(se||!h||W)return;const t=k[0];m.paneMinY=t;let i=C.current;function f(b){I&&(b?I.innerText=":root * { user-select: none !important; -webkit-user-select: none !important; }":I.innerText="")}const P=({vy:b,dragAt:S})=>{q=!1,Se=!1,f(!1);const g=S+i+h*b*.2;let T=0,be=1/0;for(let L=0;L<k.length;L++){const J=k[L],ge=g>J?g-J:J-g;ge<be&&(be=ge,T=L)}O(T),Y(T)},A=(b,S)=>{P({vy:S.vy,dragAt:S.dy})};let Se=!1;const dt=(b,{dy:S})=>{const D=m.y!==0,g=S<0,T=m.paneY-5<=m.paneMinY;return D?(Se=!0,!1):T&&!D&&g?!1:Math.abs(S)>5},Pe=()=>{f(!0),ie(),i=C.current};let q=!1;return m.drag=b=>{q||(q=!0,Pe());const S=b+i;p.setValue(Ee(S,t),{type:"direct"})},m.release=P,H.PanResponder.create({onMoveShouldSetPanResponder:dt,onPanResponderGrant:Pe,onPanResponderMove:(b,{dy:S})=>{const D=S+i,g=Ee(D,t);p.setValue(g,{type:"direct"})},onPanResponderEnd:A,onPanResponderTerminate:A,onPanResponderRelease:A})},[se,W,Y,h,k,O]);let pe=null,me=null,he=null;n.default.Children.forEach(_e,t=>{var i,f;if((0,n.isValidElement)(t))switch((f=(i=t.type)==null?void 0:i.staticConfig)==null?void 0:f.componentName){case"SheetHandle":pe=t;break;case"Sheet":he=t;break;case"SheetOverlay":me=t;break;default:console.warn("Warning: passed invalid child to Sheet",t)}});const st=nt(p,t=>({transform:[{translateY:h===0?G:t}]})),N=(0,n.useRef)(null);(0,n.useEffect)(()=>{if(s.isWeb||!Xe)return;const t=H.Keyboard.addListener("keyboardDidShow",f=>{N.current===null&&(N.current=p.getValue(),p.setValue(Math.max(p.getValue()-f.endCoordinates.height,0)))}),i=H.Keyboard.addListener("keyboardDidHide",()=>{N.current!==null&&(p.setValue(N.current),N.current=null)});return()=>{i.remove(),t.remove()}},[]);const at=w.NumberView??w.View;(0,s.useIsomorphicLayoutEffect)(()=>{if(B&&c)return B(!0),()=>{B(!1)}},[B,c]);const it=(0,n.useMemo)(()=>({zIndex:_}),[_]),lt=(0,n.useCallback)(t=>{var f;let i=(f=t.nativeEvent)==null?void 0:f.layout.height;s.isWeb&&s.isTouchable&&!c&&(i+=100),i&&Qe(()=>i)},[Ze]),ct=$e??(c&&F),fe=(0,u.jsx)(Ce.Provider,{value:it,children:(0,u.jsxs)(x.SheetProvider,{modal:F,contentRef:ae,frameSize:h,dismissOnOverlayPress:ze,dismissOnSnapToBottom:v,open:c,hidden:!!a,scope:$,position:V,snapPoints:y,setPosition:O,setOpen:X,scrollBridge:m,children:[de?null:me,(0,u.jsxs)(at,{ref:We,...Z==null?void 0:Z.panHandlers,onLayout:lt,pointerEvents:c&&!de?"auto":"none",animation:r.animation,style:[{position:"absolute",zIndex:_,width:"100%",height:"100%",opacity:ce},st],children:[pe,(0,u.jsx)(Oe.RemoveScroll,{forwardProps:!0,enabled:ct,allowPinchZoom:!0,shards:[ae],removeScrollBar:!1,children:he})]})]})}),ut=(0,n.useContext)(Q.AdaptParentContext);if(F){const t=(0,u.jsx)(Ve.Portal,{zIndex:_,...Ue,children:(0,u.jsx)(s.Theme,{forceClassName:!0,name:qe,children:(0,u.jsx)(Q.AdaptParentContext.Provider,{value:ut,children:fe})})});return s.isWeb?t:(0,u.jsx)(Re.Provider,{value:rt,children:t})}return fe}),{componentName:"Sheet"}),Re=(0,n.createContext)(null),Ct=He;function xt(o,r){if(!r)return 0;if(o===void 0)return console.warn("No snapPoint"),0;const e=o/100;return Math.round(r-e*r)}function Ee(o,r,e=25){if(o<r){const l=r-o,a=Math.min(e,l)/e,$=-(1.1-Math.pow(.1,a))*e;return r+$}return o}const we=(0,n.createContext)(null),Rt=({children:o,onOpenChange:r,...e})=>{const l=(0,s.useEvent)(r),a=(0,n.useMemo)(()=>({open:e.open,hidden:e.hidden,disableDrag:e.disableDrag,onOpenChange:l}),[l,e.open,e.hidden,e.disableDrag]);return(0,u.jsx)(we.Provider,{value:a,children:o})};0&&(module.exports={ControlledSheet,Sheet,SheetController,SheetFrame,SheetFrameFrame,SheetHandle,SheetHandleFrame,SheetOverlay,SheetOverlayFrame,createSheetScope});
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var Sheet_exports = {};
30
+ __export(Sheet_exports, {
31
+ ControlledSheet: () => ControlledSheet,
32
+ Sheet: () => Sheet,
33
+ SheetController: () => SheetController,
34
+ SheetFrame: () => SheetFrame,
35
+ SheetFrameFrame: () => SheetFrameFrame,
36
+ SheetHandle: () => SheetHandle,
37
+ SheetHandleFrame: () => SheetHandleFrame,
38
+ SheetOverlay: () => SheetOverlay,
39
+ SheetOverlayFrame: () => SheetOverlayFrame,
40
+ createSheetScope: () => import_SheetContext2.createSheetScope
41
+ });
42
+ module.exports = __toCommonJS(Sheet_exports);
43
+ var import_jsx_runtime = require("react/jsx-runtime");
44
+ var import_adapt = require("@tamagui/adapt");
45
+ var import_compose_refs = require("@tamagui/compose-refs");
46
+ var import_core = require("@tamagui/core");
47
+ var import_portal = require("@tamagui/portal");
48
+ var import_remove_scroll = require("@tamagui/remove-scroll");
49
+ var import_stacks = require("@tamagui/stacks");
50
+ var import_use_constant = require("@tamagui/use-constant");
51
+ var import_use_controllable_state = require("@tamagui/use-controllable-state");
52
+ var import_use_keyboard_visible = require("@tamagui/use-keyboard-visible");
53
+ var import_react = __toESM(require("react"));
54
+ var import_react_native = require("react-native");
55
+ var import_constants = require("./constants");
56
+ var import_SheetContext = require("./SheetContext");
57
+ var import_SheetScrollView = require("./SheetScrollView");
58
+ var import_SheetContext2 = require("./SheetContext");
59
+ const SheetHandleFrame = (0, import_core.styled)(import_stacks.XStack, {
60
+ name: import_constants.SHEET_HANDLE_NAME,
61
+ height: 10,
62
+ borderRadius: 100,
63
+ backgroundColor: "$background",
64
+ zIndex: 10,
65
+ marginHorizontal: "35%",
66
+ marginBottom: "$2",
67
+ opacity: 0.5,
68
+ hoverStyle: {
69
+ opacity: 0.7
70
+ },
71
+ variants: {
72
+ open: {
73
+ true: {
74
+ pointerEvents: "auto"
75
+ },
76
+ false: {
77
+ opacity: 0,
78
+ pointerEvents: "none"
79
+ }
80
+ }
81
+ }
82
+ });
83
+ const SheetHandle = SheetHandleFrame.extractable(
84
+ ({ __scopeSheet, ...props }) => {
85
+ const context = (0, import_SheetContext.useSheetContext)(import_constants.SHEET_HANDLE_NAME, __scopeSheet);
86
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
87
+ SheetHandleFrame,
88
+ {
89
+ onPress: () => {
90
+ const max = context.snapPoints.length + (context.dismissOnSnapToBottom ? -1 : 0);
91
+ const nextPos = (context.position + 1) % max;
92
+ context.setPosition(nextPos);
93
+ },
94
+ open: context.open,
95
+ ...props
96
+ }
97
+ );
98
+ }
99
+ );
100
+ const SHEET_OVERLAY_NAME = "SheetOverlay";
101
+ const SheetOverlayFrame = (0, import_core.styled)(import_stacks.ThemeableStack, {
102
+ name: SHEET_OVERLAY_NAME,
103
+ fullscreen: true,
104
+ backgrounded: true,
105
+ opacity: 0.5,
106
+ zIndex: 0,
107
+ variants: {
108
+ closed: {
109
+ true: {
110
+ opacity: 0,
111
+ pointerEvents: "none"
112
+ },
113
+ false: {
114
+ pointerEvents: "auto"
115
+ }
116
+ }
117
+ }
118
+ });
119
+ const SheetOverlay = SheetOverlayFrame.extractable(
120
+ ({ __scopeSheet, ...props }) => {
121
+ const context = (0, import_SheetContext.useSheetContext)(SHEET_OVERLAY_NAME, __scopeSheet);
122
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
123
+ SheetOverlayFrame,
124
+ {
125
+ closed: !context.open || context.hidden,
126
+ ...props,
127
+ onPress: (0, import_core.mergeEvent)(
128
+ props.onPress,
129
+ context.dismissOnOverlayPress ? () => {
130
+ context.setOpen(false);
131
+ } : void 0
132
+ )
133
+ }
134
+ );
135
+ }
136
+ );
137
+ const selectionStyleSheet = import_core.isClient ? document.createElement("style") : null;
138
+ if (selectionStyleSheet) {
139
+ document.head.appendChild(selectionStyleSheet);
140
+ }
141
+ const SheetFrameFrame = (0, import_core.styled)(import_stacks.YStack, {
142
+ name: import_constants.SHEET_NAME,
143
+ flex: 1,
144
+ backgroundColor: "$background",
145
+ borderTopLeftRadius: "$true",
146
+ borderTopRightRadius: "$true",
147
+ width: "100%",
148
+ maxHeight: "100%",
149
+ overflow: "hidden",
150
+ pointerEvents: "auto"
151
+ });
152
+ const SheetFrame = SheetFrameFrame.extractable(
153
+ (0, import_react.forwardRef)(
154
+ ({ __scopeSheet, ...props }, forwardedRef) => {
155
+ const context = (0, import_SheetContext.useSheetContext)(import_constants.SHEET_NAME, __scopeSheet);
156
+ const composedContentRef = (0, import_compose_refs.useComposedRefs)(forwardedRef, context.contentRef);
157
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SheetFrameFrame, { ref: composedContentRef, ...props });
158
+ }
159
+ )
160
+ );
161
+ const HIDDEN_SIZE = 1e4;
162
+ const sheetComponents = {
163
+ Handle: SheetHandle,
164
+ Frame: SheetFrame,
165
+ Overlay: SheetOverlay,
166
+ ScrollView: import_SheetScrollView.SheetScrollView
167
+ };
168
+ const ParentSheetContext = (0, import_react.createContext)({
169
+ zIndex: 40
170
+ });
171
+ const useSheetContoller = () => {
172
+ const controller = (0, import_react.useContext)(SheetControllerContext);
173
+ const isHidden = controller == null ? void 0 : controller.hidden;
174
+ const isShowingNonSheet = isHidden && (controller == null ? void 0 : controller.open);
175
+ return {
176
+ controller,
177
+ isHidden,
178
+ isShowingNonSheet
179
+ };
180
+ };
181
+ const Sheet = (0, import_core.withStaticProperties)(
182
+ (0, import_react.forwardRef)(function Sheet2(props, ref) {
183
+ const hydrated = (0, import_core.useDidFinishSSR)();
184
+ const { isShowingNonSheet } = useSheetContoller();
185
+ if (isShowingNonSheet || !hydrated) {
186
+ return null;
187
+ }
188
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SheetImplementation, { ref, ...props });
189
+ }),
190
+ sheetComponents
191
+ );
192
+ const SheetImplementation = (0, import_core.themeable)(
193
+ (0, import_react.forwardRef)(function SheetImplementation2(props, forwardedRef) {
194
+ const parentSheet = (0, import_react.useContext)(ParentSheetContext);
195
+ const { isHidden, controller } = useSheetContoller();
196
+ const {
197
+ __scopeSheet,
198
+ snapPoints: snapPointsProp = [80],
199
+ open: openProp,
200
+ defaultOpen,
201
+ children: childrenProp,
202
+ position: positionProp,
203
+ onPositionChange,
204
+ onOpenChange,
205
+ defaultPosition,
206
+ dismissOnOverlayPress = true,
207
+ animationConfig,
208
+ dismissOnSnapToBottom = false,
209
+ forceRemoveScrollEnabled = null,
210
+ disableDrag: disableDragProp,
211
+ modal = false,
212
+ zIndex = parentSheet.zIndex + 1,
213
+ moveOnKeyboardChange = false,
214
+ portalProps
215
+ } = props;
216
+ if (process.env.NODE_ENV === "development") {
217
+ if (snapPointsProp.some((p) => p < 0 || p > 100)) {
218
+ console.warn(
219
+ "\u26A0\uFE0F Invalid snapPoint given, snapPoints must be between 0 and 100, equal to percent height of frame"
220
+ );
221
+ }
222
+ }
223
+ const sheetRef = (0, import_react.useRef)(null);
224
+ const ref = (0, import_compose_refs.useComposedRefs)(forwardedRef, sheetRef);
225
+ const driver = (0, import_core.useAnimationDriver)();
226
+ if (!driver) {
227
+ throw new Error("Must set animations in tamagui.config.ts");
228
+ }
229
+ const disableDrag = disableDragProp ?? (controller == null ? void 0 : controller.disableDrag);
230
+ const keyboardIsVisible = (0, import_use_keyboard_visible.useKeyboardVisible)();
231
+ const themeName = (0, import_core.useThemeName)();
232
+ const contentRef = import_react.default.useRef(null);
233
+ const scrollBridge = (0, import_use_constant.useConstant)(() => ({
234
+ enabled: false,
235
+ y: 0,
236
+ paneY: 0,
237
+ paneMinY: 0,
238
+ scrollStartY: -1,
239
+ drag: () => {
240
+ },
241
+ release: () => {
242
+ },
243
+ scrollLock: false
244
+ }));
245
+ const onOpenChangeInternal = (val) => {
246
+ var _a;
247
+ (_a = controller == null ? void 0 : controller.onOpenChange) == null ? void 0 : _a.call(controller, val);
248
+ onOpenChange == null ? void 0 : onOpenChange(val);
249
+ };
250
+ const [open, setOpen] = (0, import_use_controllable_state.useControllableState)({
251
+ prop: (controller == null ? void 0 : controller.open) ?? openProp,
252
+ defaultProp: true,
253
+ onChange: onOpenChangeInternal,
254
+ strategy: "most-recent-wins",
255
+ transition: true
256
+ });
257
+ const [frameSize, setFrameSize] = (0, import_react.useState)(0);
258
+ const snapPoints = (0, import_react.useMemo)(
259
+ () => dismissOnSnapToBottom ? [...snapPointsProp, 0] : snapPointsProp,
260
+ // eslint-disable-next-line react-hooks/exhaustive-deps
261
+ [JSON.stringify(snapPointsProp), dismissOnSnapToBottom]
262
+ );
263
+ const [position_, setPosition_] = (0, import_use_controllable_state.useControllableState)({
264
+ prop: positionProp,
265
+ defaultProp: defaultPosition || (open ? 0 : -1),
266
+ onChange: onPositionChange,
267
+ strategy: "most-recent-wins",
268
+ transition: true
269
+ });
270
+ const position = open === false ? -1 : position_;
271
+ if (open && dismissOnSnapToBottom && position === snapPoints.length - 1) {
272
+ setPosition_(0);
273
+ }
274
+ const setPosition = (0, import_react.useCallback)(
275
+ (next) => {
276
+ if (dismissOnSnapToBottom && next === snapPoints.length - 1) {
277
+ setOpen(false);
278
+ } else {
279
+ setPosition_(next);
280
+ }
281
+ },
282
+ [dismissOnSnapToBottom, snapPoints.length, setPosition_, setOpen]
283
+ );
284
+ const { useAnimatedNumber, useAnimatedNumberReaction, useAnimatedNumberStyle } = driver;
285
+ const animatedNumber = useAnimatedNumber(HIDDEN_SIZE);
286
+ const at = (0, import_react.useRef)(0);
287
+ useAnimatedNumberReaction(
288
+ {
289
+ value: animatedNumber,
290
+ hostRef: sheetRef
291
+ },
292
+ (value) => {
293
+ if (!driver.isReactNative)
294
+ return;
295
+ at.current = value;
296
+ scrollBridge.paneY = value;
297
+ }
298
+ );
299
+ function stopSpring() {
300
+ animatedNumber.stop();
301
+ if (scrollBridge.onFinishAnimate) {
302
+ scrollBridge.onFinishAnimate();
303
+ scrollBridge.onFinishAnimate = void 0;
304
+ }
305
+ }
306
+ const shouldSetPositionOpen = open && position < 0;
307
+ (0, import_react.useEffect)(() => {
308
+ if (shouldSetPositionOpen) {
309
+ setPosition(0);
310
+ }
311
+ }, [setPosition, shouldSetPositionOpen]);
312
+ const positions = (0, import_react.useMemo)(
313
+ () => snapPoints.map((point) => getPercentSize(point, frameSize)),
314
+ [frameSize, snapPoints]
315
+ );
316
+ const [opacity, setOpacity] = (0, import_react.useState)(open ? 1 : 0);
317
+ if (open && opacity === 0) {
318
+ setOpacity(1);
319
+ }
320
+ (0, import_react.useEffect)(() => {
321
+ if (!open) {
322
+ const tm = setTimeout(() => {
323
+ setOpacity(0);
324
+ }, 400);
325
+ return () => {
326
+ clearTimeout(tm);
327
+ };
328
+ }
329
+ }, [open]);
330
+ const animateTo = (0, import_core.useEvent)((position2) => {
331
+ const current = animatedNumber.getValue();
332
+ if (isHidden && open)
333
+ return;
334
+ if (!current)
335
+ return;
336
+ if (frameSize === 0)
337
+ return;
338
+ const hiddenValue = frameSize === 0 ? HIDDEN_SIZE : frameSize;
339
+ const toValue = isHidden || position2 === -1 ? hiddenValue : positions[position2];
340
+ if (at.current === toValue)
341
+ return;
342
+ stopSpring();
343
+ if (isHidden) {
344
+ animatedNumber.setValue(toValue, {
345
+ type: "timing",
346
+ duration: 0
347
+ });
348
+ at.current = toValue;
349
+ return;
350
+ }
351
+ const overshootClamping = at.current === HIDDEN_SIZE;
352
+ animatedNumber.setValue(toValue, {
353
+ ...animationConfig,
354
+ type: "spring",
355
+ overshootClamping
356
+ });
357
+ });
358
+ (0, import_core.useIsomorphicLayoutEffect)(() => {
359
+ animateTo(position);
360
+ }, [isHidden, frameSize, position, animateTo]);
361
+ const [isShowingInnerSheet, setIsShowingInnerSheet] = (0, import_react.useState)(false);
362
+ const shouldHideParentSheet = !import_core.isWeb && modal && isShowingInnerSheet;
363
+ const parentSheetContext = (0, import_react.useContext)(SheetInsideSheetContext);
364
+ const onInnerSheet = (0, import_react.useCallback)((hasChild) => {
365
+ setIsShowingInnerSheet(hasChild);
366
+ }, []);
367
+ const panResponder = (0, import_react.useMemo)(
368
+ () => {
369
+ if (disableDrag)
370
+ return;
371
+ if (!frameSize)
372
+ return;
373
+ if (isShowingInnerSheet)
374
+ return;
375
+ const minY = positions[0];
376
+ scrollBridge.paneMinY = minY;
377
+ let startY = at.current;
378
+ function makeUnselectable(val) {
379
+ if (!selectionStyleSheet)
380
+ return;
381
+ if (!val) {
382
+ selectionStyleSheet.innerText = "";
383
+ } else {
384
+ selectionStyleSheet.innerText = ":root * { user-select: none !important; -webkit-user-select: none !important; }";
385
+ }
386
+ }
387
+ const release = ({ vy, dragAt }) => {
388
+ isExternalDrag = false;
389
+ previouslyScrolling = false;
390
+ makeUnselectable(false);
391
+ const at2 = dragAt + startY;
392
+ const end = at2 + frameSize * vy * 0.2;
393
+ let closestPoint = 0;
394
+ let dist = Infinity;
395
+ for (let i = 0; i < positions.length; i++) {
396
+ const position2 = positions[i];
397
+ const curDist = end > position2 ? end - position2 : position2 - end;
398
+ if (curDist < dist) {
399
+ dist = curDist;
400
+ closestPoint = i;
401
+ }
402
+ }
403
+ setPosition(closestPoint);
404
+ animateTo(closestPoint);
405
+ };
406
+ const finish = (_e, state) => {
407
+ release({
408
+ vy: state.vy,
409
+ dragAt: state.dy
410
+ });
411
+ };
412
+ let previouslyScrolling = false;
413
+ const onMoveShouldSet = (_e, { dy }) => {
414
+ const isScrolled = scrollBridge.y !== 0;
415
+ const isDraggingUp = dy < 0;
416
+ const isNearTop = scrollBridge.paneY - 5 <= scrollBridge.paneMinY;
417
+ if (isScrolled) {
418
+ previouslyScrolling = true;
419
+ return false;
420
+ }
421
+ if (isNearTop) {
422
+ if (!isScrolled && isDraggingUp) {
423
+ return false;
424
+ }
425
+ }
426
+ return Math.abs(dy) > 5;
427
+ };
428
+ const grant = () => {
429
+ makeUnselectable(true);
430
+ stopSpring();
431
+ startY = at.current;
432
+ };
433
+ let isExternalDrag = false;
434
+ scrollBridge.drag = (dy) => {
435
+ if (!isExternalDrag) {
436
+ isExternalDrag = true;
437
+ grant();
438
+ }
439
+ const to = dy + startY;
440
+ animatedNumber.setValue(resisted(to, minY), { type: "direct" });
441
+ };
442
+ scrollBridge.release = release;
443
+ return import_react_native.PanResponder.create({
444
+ onMoveShouldSetPanResponder: onMoveShouldSet,
445
+ onPanResponderGrant: grant,
446
+ onPanResponderMove: (_e, { dy }) => {
447
+ const toFull = dy + startY;
448
+ const to = resisted(toFull, minY);
449
+ animatedNumber.setValue(to, { type: "direct" });
450
+ },
451
+ onPanResponderEnd: finish,
452
+ onPanResponderTerminate: finish,
453
+ onPanResponderRelease: finish
454
+ });
455
+ },
456
+ // eslint-disable-next-line react-hooks/exhaustive-deps
457
+ [disableDrag, isShowingInnerSheet, animateTo, frameSize, positions, setPosition]
458
+ );
459
+ let handleComponent = null;
460
+ let overlayComponent = null;
461
+ let frameComponent = null;
462
+ import_react.default.Children.forEach(childrenProp, (child) => {
463
+ var _a, _b;
464
+ if ((0, import_react.isValidElement)(child)) {
465
+ const name = (_b = (_a = child.type) == null ? void 0 : _a["staticConfig"]) == null ? void 0 : _b.componentName;
466
+ switch (name) {
467
+ case "SheetHandle":
468
+ handleComponent = child;
469
+ break;
470
+ case "Sheet":
471
+ frameComponent = child;
472
+ break;
473
+ case "SheetOverlay":
474
+ overlayComponent = child;
475
+ break;
476
+ default:
477
+ console.warn("Warning: passed invalid child to Sheet", child);
478
+ }
479
+ }
480
+ });
481
+ const animatedStyle = useAnimatedNumberStyle(animatedNumber, (val) => {
482
+ const translateY = frameSize === 0 ? HIDDEN_SIZE : val;
483
+ return {
484
+ transform: [{ translateY }]
485
+ };
486
+ });
487
+ const sizeBeforeKeyboard = (0, import_react.useRef)(null);
488
+ (0, import_react.useEffect)(() => {
489
+ if (import_core.isWeb || !moveOnKeyboardChange)
490
+ return;
491
+ const keyboardDidShowListener = import_react_native.Keyboard.addListener("keyboardDidShow", (e) => {
492
+ if (sizeBeforeKeyboard.current !== null)
493
+ return;
494
+ sizeBeforeKeyboard.current = animatedNumber.getValue();
495
+ animatedNumber.setValue(
496
+ Math.max(animatedNumber.getValue() - e.endCoordinates.height, 0)
497
+ );
498
+ });
499
+ const keyboardDidHideListener = import_react_native.Keyboard.addListener("keyboardDidHide", () => {
500
+ if (sizeBeforeKeyboard.current === null)
501
+ return;
502
+ animatedNumber.setValue(sizeBeforeKeyboard.current);
503
+ sizeBeforeKeyboard.current = null;
504
+ });
505
+ return () => {
506
+ keyboardDidHideListener.remove();
507
+ keyboardDidShowListener.remove();
508
+ };
509
+ }, []);
510
+ const AnimatedView = driver["NumberView"] ?? driver.View;
511
+ (0, import_core.useIsomorphicLayoutEffect)(() => {
512
+ if (!(parentSheetContext && open))
513
+ return;
514
+ parentSheetContext(true);
515
+ return () => {
516
+ parentSheetContext(false);
517
+ };
518
+ }, [parentSheetContext, open]);
519
+ const nextParentContext = (0, import_react.useMemo)(
520
+ () => ({
521
+ zIndex
522
+ }),
523
+ [zIndex]
524
+ );
525
+ const handleLayout = (0, import_react.useCallback)(
526
+ (e) => {
527
+ var _a;
528
+ let next = (_a = e.nativeEvent) == null ? void 0 : _a.layout.height;
529
+ if (import_core.isWeb && import_core.isTouchable && !open) {
530
+ next += 100;
531
+ }
532
+ if (!next)
533
+ return;
534
+ setFrameSize(() => next);
535
+ },
536
+ [keyboardIsVisible]
537
+ );
538
+ const removeScrollEnabled = forceRemoveScrollEnabled ?? (open && modal);
539
+ const contents = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ParentSheetContext.Provider, { value: nextParentContext, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
540
+ import_SheetContext.SheetProvider,
541
+ {
542
+ modal,
543
+ contentRef,
544
+ frameSize,
545
+ dismissOnOverlayPress,
546
+ dismissOnSnapToBottom,
547
+ open,
548
+ hidden: !!isHidden,
549
+ scope: __scopeSheet,
550
+ position,
551
+ snapPoints,
552
+ setPosition,
553
+ setOpen,
554
+ scrollBridge,
555
+ children: [
556
+ shouldHideParentSheet ? null : overlayComponent,
557
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
558
+ AnimatedView,
559
+ {
560
+ ref,
561
+ ...panResponder == null ? void 0 : panResponder.panHandlers,
562
+ onLayout: handleLayout,
563
+ pointerEvents: open && !shouldHideParentSheet ? "auto" : "none",
564
+ animation: props.animation,
565
+ style: [
566
+ {
567
+ position: "absolute",
568
+ zIndex,
569
+ width: "100%",
570
+ height: "100%",
571
+ opacity
572
+ },
573
+ animatedStyle
574
+ ],
575
+ children: [
576
+ handleComponent,
577
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
578
+ import_remove_scroll.RemoveScroll,
579
+ {
580
+ forwardProps: true,
581
+ enabled: removeScrollEnabled,
582
+ allowPinchZoom: true,
583
+ shards: [contentRef],
584
+ removeScrollBar: false,
585
+ children: frameComponent
586
+ }
587
+ )
588
+ ]
589
+ }
590
+ )
591
+ ]
592
+ }
593
+ ) });
594
+ const adaptContext = (0, import_react.useContext)(import_adapt.AdaptParentContext);
595
+ if (modal) {
596
+ const modalContents = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_portal.Portal, { zIndex, ...portalProps, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, { forceClassName: true, name: themeName, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_adapt.AdaptParentContext.Provider, { value: adaptContext, children: contents }) }) });
597
+ if (import_core.isWeb) {
598
+ return modalContents;
599
+ }
600
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SheetInsideSheetContext.Provider, { value: onInnerSheet, children: modalContents });
601
+ }
602
+ return contents;
603
+ }),
604
+ { componentName: "Sheet" }
605
+ );
606
+ const SheetInsideSheetContext = (0, import_react.createContext)(null);
607
+ const ControlledSheet = Sheet;
608
+ function getPercentSize(point, frameSize) {
609
+ if (!frameSize)
610
+ return 0;
611
+ if (point === void 0) {
612
+ console.warn("No snapPoint");
613
+ return 0;
614
+ }
615
+ const pct = point / 100;
616
+ const next = Math.round(frameSize - pct * frameSize);
617
+ return next;
618
+ }
619
+ function resisted(y, minY, maxOverflow = 25) {
620
+ if (y < minY) {
621
+ const past = minY - y;
622
+ const pctPast = Math.min(maxOverflow, past) / maxOverflow;
623
+ const diminishBy = 1.1 - Math.pow(0.1, pctPast);
624
+ const extra = -diminishBy * maxOverflow;
625
+ return minY + extra;
626
+ }
627
+ return y;
628
+ }
629
+ const SheetControllerContext = (0, import_react.createContext)(null);
630
+ const SheetController = ({
631
+ children,
632
+ onOpenChange: onOpenChangeProp,
633
+ ...value
634
+ }) => {
635
+ const onOpenChange = (0, import_core.useEvent)(onOpenChangeProp);
636
+ const memoValue = (0, import_react.useMemo)(
637
+ () => ({
638
+ open: value.open,
639
+ hidden: value.hidden,
640
+ disableDrag: value.disableDrag,
641
+ onOpenChange
642
+ }),
643
+ [onOpenChange, value.open, value.hidden, value.disableDrag]
644
+ );
645
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SheetControllerContext.Provider, { value: memoValue, children });
646
+ };
647
+ // Annotate the CommonJS export names for ESM import in node:
648
+ 0 && (module.exports = {
649
+ ControlledSheet,
650
+ Sheet,
651
+ SheetController,
652
+ SheetFrame,
653
+ SheetFrameFrame,
654
+ SheetHandle,
655
+ SheetHandleFrame,
656
+ SheetOverlay,
657
+ SheetOverlayFrame,
658
+ createSheetScope
659
+ });
2
660
  //# sourceMappingURL=Sheet.js.map