@tamagui/sheet 1.27.0 → 1.27.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 (140) hide show
  1. package/dist/cjs/Sheet.js +1 -2
  2. package/dist/cjs/Sheet.js.map +1 -1
  3. package/dist/cjs/SheetContext.js.map +1 -1
  4. package/dist/cjs/SheetImplementationCustom.js +340 -0
  5. package/dist/cjs/SheetImplementationCustom.js.map +6 -0
  6. package/dist/cjs/constants.js +10 -0
  7. package/dist/cjs/constants.js.map +1 -1
  8. package/dist/cjs/contexts.js +35 -0
  9. package/dist/cjs/contexts.js.map +6 -0
  10. package/dist/cjs/createSheet.js +68 -342
  11. package/dist/cjs/createSheet.js.map +2 -2
  12. package/dist/cjs/helpers.js +38 -0
  13. package/dist/cjs/helpers.js.map +6 -0
  14. package/dist/cjs/index.js +2 -0
  15. package/dist/cjs/index.js.map +1 -1
  16. package/dist/cjs/nativeSheet.js +3 -5
  17. package/dist/cjs/nativeSheet.js.map +1 -1
  18. package/dist/cjs/useSheet.js +30 -0
  19. package/dist/cjs/useSheet.js.map +6 -0
  20. package/dist/cjs/useSheetChildren.js +4 -2
  21. package/dist/cjs/useSheetChildren.js.map +1 -1
  22. package/dist/cjs/useSheetController.js +2 -1
  23. package/dist/cjs/useSheetController.js.map +1 -1
  24. package/dist/cjs/useSheetProviderProps.js +30 -3
  25. package/dist/cjs/useSheetProviderProps.js.map +1 -1
  26. package/dist/esm/Sheet.js +1 -2
  27. package/dist/esm/Sheet.js.map +1 -1
  28. package/dist/esm/SheetContext.js.map +1 -1
  29. package/dist/esm/SheetImplementationCustom.js +336 -0
  30. package/dist/esm/SheetImplementationCustom.js.map +6 -0
  31. package/dist/esm/constants.js +8 -0
  32. package/dist/esm/constants.js.map +1 -1
  33. package/dist/esm/contexts.js +10 -0
  34. package/dist/esm/contexts.js.map +6 -0
  35. package/dist/esm/createSheet.js +72 -364
  36. package/dist/esm/createSheet.js.map +2 -2
  37. package/dist/esm/helpers.js +14 -0
  38. package/dist/esm/helpers.js.map +6 -0
  39. package/dist/esm/index.js +1 -0
  40. package/dist/esm/index.js.map +1 -1
  41. package/dist/esm/nativeSheet.js +3 -5
  42. package/dist/esm/nativeSheet.js.map +1 -1
  43. package/dist/esm/useSheet.js +6 -0
  44. package/dist/esm/useSheet.js.map +6 -0
  45. package/dist/esm/useSheetChildren.js +4 -2
  46. package/dist/esm/useSheetChildren.js.map +1 -1
  47. package/dist/esm/useSheetController.js +2 -1
  48. package/dist/esm/useSheetController.js.map +1 -1
  49. package/dist/esm/useSheetProviderProps.js +31 -4
  50. package/dist/esm/useSheetProviderProps.js.map +1 -1
  51. package/dist/jsx/Sheet.js +1 -2
  52. package/dist/jsx/Sheet.js.map +1 -1
  53. package/dist/jsx/Sheet.mjs +1 -2
  54. package/dist/jsx/Sheet.mjs.map +1 -1
  55. package/dist/jsx/SheetContext.js.map +1 -1
  56. package/dist/jsx/SheetContext.mjs.map +1 -1
  57. package/dist/jsx/SheetImplementationCustom.js +330 -0
  58. package/dist/jsx/SheetImplementationCustom.js.map +6 -0
  59. package/dist/jsx/SheetImplementationCustom.mjs +330 -0
  60. package/dist/jsx/SheetImplementationCustom.mjs.map +6 -0
  61. package/dist/jsx/constants.js +8 -0
  62. package/dist/jsx/constants.js.map +1 -1
  63. package/dist/jsx/constants.mjs +8 -0
  64. package/dist/jsx/constants.mjs.map +1 -1
  65. package/dist/jsx/contexts.js +10 -0
  66. package/dist/jsx/contexts.js.map +6 -0
  67. package/dist/jsx/contexts.mjs +10 -0
  68. package/dist/jsx/contexts.mjs.map +6 -0
  69. package/dist/jsx/createSheet.js +63 -354
  70. package/dist/jsx/createSheet.js.map +2 -2
  71. package/dist/jsx/createSheet.mjs +63 -354
  72. package/dist/jsx/createSheet.mjs.map +2 -2
  73. package/dist/jsx/helpers.js +14 -0
  74. package/dist/jsx/helpers.js.map +6 -0
  75. package/dist/jsx/helpers.mjs +14 -0
  76. package/dist/jsx/helpers.mjs.map +6 -0
  77. package/dist/jsx/index.js +1 -0
  78. package/dist/jsx/index.js.map +1 -1
  79. package/dist/jsx/index.mjs +1 -0
  80. package/dist/jsx/index.mjs.map +1 -1
  81. package/dist/jsx/nativeSheet.js +3 -5
  82. package/dist/jsx/nativeSheet.js.map +1 -1
  83. package/dist/jsx/nativeSheet.mjs +3 -5
  84. package/dist/jsx/nativeSheet.mjs.map +1 -1
  85. package/dist/jsx/useSheet.js +6 -0
  86. package/dist/jsx/useSheet.js.map +6 -0
  87. package/dist/jsx/useSheet.mjs +6 -0
  88. package/dist/jsx/useSheet.mjs.map +6 -0
  89. package/dist/jsx/useSheetChildren.js +4 -2
  90. package/dist/jsx/useSheetChildren.js.map +1 -1
  91. package/dist/jsx/useSheetChildren.mjs +4 -2
  92. package/dist/jsx/useSheetChildren.mjs.map +1 -1
  93. package/dist/jsx/useSheetController.js +2 -1
  94. package/dist/jsx/useSheetController.js.map +1 -1
  95. package/dist/jsx/useSheetController.mjs +2 -1
  96. package/dist/jsx/useSheetController.mjs.map +1 -1
  97. package/dist/jsx/useSheetProviderProps.js +31 -4
  98. package/dist/jsx/useSheetProviderProps.js.map +1 -1
  99. package/dist/jsx/useSheetProviderProps.mjs +31 -4
  100. package/dist/jsx/useSheetProviderProps.mjs.map +1 -1
  101. package/package.json +13 -13
  102. package/src/Sheet.tsx +0 -1
  103. package/src/SheetContext.tsx +1 -16
  104. package/src/SheetImplementationCustom.tsx +404 -0
  105. package/src/constants.tsx +10 -0
  106. package/src/contexts.ts +9 -0
  107. package/src/createSheet.tsx +88 -441
  108. package/src/helpers.tsx +10 -0
  109. package/src/index.ts +1 -0
  110. package/src/nativeSheet.tsx +3 -5
  111. package/src/useSheet.tsx +3 -0
  112. package/src/useSheetController.tsx +1 -0
  113. package/src/useSheetProviderProps.tsx +48 -7
  114. package/types/Sheet.d.ts +10 -6
  115. package/types/Sheet.d.ts.map +1 -1
  116. package/types/SheetContext.d.ts +100 -27
  117. package/types/SheetContext.d.ts.map +1 -1
  118. package/types/SheetImplementationCustom.d.ts +27 -0
  119. package/types/SheetImplementationCustom.d.ts.map +1 -0
  120. package/types/constants.d.ts +2 -0
  121. package/types/constants.d.ts.map +1 -1
  122. package/types/contexts.d.ts +6 -0
  123. package/types/contexts.d.ts.map +1 -0
  124. package/types/createSheet.d.ts +8 -4
  125. package/types/createSheet.d.ts.map +1 -1
  126. package/types/helpers.d.ts +2 -0
  127. package/types/helpers.d.ts.map +1 -0
  128. package/types/index.d.ts +1 -0
  129. package/types/index.d.ts.map +1 -1
  130. package/types/nativeSheet.d.ts.map +1 -1
  131. package/types/useSheet.d.ts +22 -0
  132. package/types/useSheet.d.ts.map +1 -0
  133. package/types/useSheetChildren.d.ts +1 -0
  134. package/types/useSheetChildren.d.ts.map +1 -1
  135. package/types/useSheetController.d.ts +1 -0
  136. package/types/useSheetController.d.ts.map +1 -1
  137. package/types/useSheetProviderProps.d.ts +8 -3
  138. package/types/useSheetProviderProps.d.ts.map +1 -1
  139. package/src/useSheetChildren.tsx +0 -47
  140. package/src/useSheetSnapPoints.tsx +0 -60
@@ -1,57 +1,29 @@
1
- import { AdaptParentContext } from '@tamagui/adapt'
2
1
  import { useComposedRefs } from '@tamagui/compose-refs'
3
2
  import {
4
3
  GetProps,
5
4
  StackProps,
6
5
  TamaguiComponentExpectingVariants,
7
- Theme,
8
- isClient,
9
- isTouchable,
10
- isWeb,
11
6
  mergeEvent,
12
- themeable,
13
- useAnimationDriver,
14
7
  useDidFinishSSR,
15
- useEvent,
16
- useIsomorphicLayoutEffect,
17
- useThemeName,
18
8
  withStaticProperties,
19
9
  } from '@tamagui/core'
20
- import { Portal } from '@tamagui/portal'
21
10
  import { RemoveScroll } from '@tamagui/remove-scroll'
22
- import { useKeyboardVisible } from '@tamagui/use-keyboard-visible'
23
11
  import {
24
12
  FunctionComponent,
25
13
  RefAttributes,
26
- createContext,
27
14
  forwardRef,
28
- useCallback,
29
- useContext,
30
- useEffect,
15
+ useLayoutEffect,
31
16
  useMemo,
32
- useRef,
33
- useState,
34
17
  } from 'react'
35
- import {
36
- Animated,
37
- GestureResponderEvent,
38
- Keyboard,
39
- PanResponder,
40
- PanResponderGestureState,
41
- Platform,
42
- View,
43
- } from 'react-native'
18
+ import { Platform, View } from 'react-native'
44
19
 
45
20
  import { SHEET_HANDLE_NAME, SHEET_NAME, SHEET_OVERLAY_NAME } from './constants'
46
21
  import { getNativeSheet } from './nativeSheet'
47
- import { SheetProvider, useSheetContext } from './SheetContext'
22
+ import { useSheetContext } from './SheetContext'
23
+ import { SheetImplementationCustom } from './SheetImplementationCustom'
48
24
  import { SheetScrollView } from './SheetScrollView'
49
25
  import { SheetProps, SheetScopedProps } from './types'
50
- import { useSheetChildren } from './useSheetChildren'
51
26
  import { useSheetController } from './useSheetController'
52
- import { useSheetOpenState } from './useSheetOpenState'
53
- import { useSheetProviderProps } from './useSheetProviderProps'
54
- import { useSheetSnapPoints } from './useSheetSnapPoints'
55
27
 
56
28
  type SharedSheetProps = {
57
29
  open?: boolean
@@ -65,15 +37,15 @@ export type CreateSheetProps = {
65
37
  Overlay: TamaguiComponentExpectingVariants<BaseProps, SharedSheetProps>
66
38
  }
67
39
 
68
- const selectionStyleSheet = isClient ? document.createElement('style') : null
69
- if (selectionStyleSheet) {
70
- document.head.appendChild(selectionStyleSheet)
71
- }
72
-
73
40
  export function createSheet({ Handle, Frame, Overlay }: CreateSheetProps) {
74
41
  const SheetHandle = Handle.extractable(
75
42
  ({ __scopeSheet, ...props }: SheetScopedProps<GetProps<typeof Handle>>) => {
76
43
  const context = useSheetContext(SHEET_HANDLE_NAME, __scopeSheet)
44
+
45
+ if (context.onlyShowFrame) {
46
+ return null
47
+ }
48
+
77
49
  return (
78
50
  <Handle
79
51
  onPress={() => {
@@ -95,22 +67,46 @@ export function createSheet({ Handle, Frame, Overlay }: CreateSheetProps) {
95
67
  * -----------------------------------------------------------------------------------------------*/
96
68
 
97
69
  const SheetOverlay = Overlay.extractable(
98
- ({ __scopeSheet, ...props }: SheetScopedProps<GetProps<typeof Overlay>>) => {
70
+ (propsIn: SheetScopedProps<GetProps<typeof Overlay>>) => {
71
+ const { __scopeSheet, ...props } = propsIn
99
72
  const context = useSheetContext(SHEET_OVERLAY_NAME, __scopeSheet)
100
- return (
101
- <Overlay
102
- open={context.open && !context.hidden}
103
- {...props}
104
- onPress={mergeEvent(
105
- props.onPress as any,
106
- context.dismissOnOverlayPress
107
- ? () => {
108
- context.setOpen(false)
109
- }
110
- : undefined
111
- )}
112
- />
73
+
74
+ // this ones a bit weird for legacy reasons, we need to hoist it above <Sheet /> AnimatedView
75
+ // so we just pass it up to context
76
+
77
+ const element = useMemo(
78
+ () => (
79
+ <Overlay
80
+ open={context.open && !context.hidden}
81
+ {...props}
82
+ onPress={mergeEvent(
83
+ props.onPress as any,
84
+ context.dismissOnOverlayPress
85
+ ? () => {
86
+ context.setOpen(false)
87
+ }
88
+ : undefined
89
+ )}
90
+ />
91
+ ),
92
+ [
93
+ context.open,
94
+ props,
95
+ context.hidden,
96
+ props.onPress,
97
+ context.dismissOnOverlayPress,
98
+ ]
113
99
  )
100
+
101
+ useLayoutEffect(() => {
102
+ context.onOverlayComponent?.(element)
103
+ }, [element])
104
+
105
+ if (context.onlyShowFrame) {
106
+ return null
107
+ }
108
+
109
+ return null
114
110
  }
115
111
  )
116
112
 
@@ -121,12 +117,51 @@ export function createSheet({ Handle, Frame, Overlay }: CreateSheetProps) {
121
117
  const SheetFrame = Frame.extractable(
122
118
  forwardRef(
123
119
  (
124
- { __scopeSheet, ...props }: SheetScopedProps<GetProps<typeof Frame>>,
120
+ {
121
+ __scopeSheet,
122
+ children,
123
+ ...props
124
+ }: SheetScopedProps<
125
+ GetProps<typeof Frame> & {
126
+ disableHideBottomOverflow?: boolean
127
+ }
128
+ >,
125
129
  forwardedRef
126
130
  ) => {
127
131
  const context = useSheetContext(SHEET_NAME, __scopeSheet)
128
132
  const composedContentRef = useComposedRefs(forwardedRef, context.contentRef)
129
- return <Frame ref={composedContentRef} {...props} />
133
+
134
+ return (
135
+ <>
136
+ <RemoveScroll
137
+ forwardProps
138
+ enabled={context.removeScrollEnabled}
139
+ allowPinchZoom
140
+ shards={[context.contentRef]}
141
+ // causes lots of bugs on touch web on site
142
+ removeScrollBar={false}
143
+ >
144
+ <Frame ref={composedContentRef} {...props}>
145
+ {children}
146
+ </Frame>
147
+ </RemoveScroll>
148
+
149
+ {/* below frame hide when bouncing past 100% */}
150
+ {!props.disableHideBottomOverflow && (
151
+ <Frame
152
+ {...props}
153
+ children={null}
154
+ position="absolute"
155
+ bottom={0}
156
+ maxHeight={300}
157
+ left={0}
158
+ right={0}
159
+ borderRadius={0}
160
+ shadowOpacity={0}
161
+ />
162
+ )}
163
+ </>
164
+ )
130
165
  }
131
166
  )
132
167
  )
@@ -174,392 +209,4 @@ export function createSheet({ Handle, Frame, Overlay }: CreateSheetProps) {
174
209
  })
175
210
  }
176
211
 
177
- // set all the way off screen
178
- const HIDDEN_SIZE = 10_000
179
-
180
- const ParentSheetContext = createContext({
181
- zIndex: 100_000,
182
- })
183
-
184
- const SheetImplementationCustom = themeable(
185
- forwardRef<View, SheetProps>(function SheetImplementationCustom(props, forwardedRef) {
186
- const parentSheet = useContext(ParentSheetContext)
187
-
188
- const {
189
- animationConfig,
190
- forceRemoveScrollEnabled = null,
191
- disableDrag: disableDragProp,
192
- modal = false,
193
- zIndex = parentSheet.zIndex + 1,
194
- moveOnKeyboardChange = false,
195
- portalProps,
196
- } = props
197
-
198
- const state = useSheetOpenState(props)
199
- const providerProps = useSheetProviderProps(props, state)
200
- const { positions, maxSnapPoint, screenSize } = useSheetSnapPoints(providerProps)
201
-
202
- const { position, contentRef, setPosition, scrollBridge, frameSize, setFrameSize } =
203
- providerProps
204
-
205
- const { open, isHidden, controller } = state
206
-
207
- const { frameComponent, handleComponent, bottomCoverComponent, overlayComponent } =
208
- useSheetChildren(props.children)
209
-
210
- const sheetRef = useRef<View>(null)
211
- const ref = useComposedRefs(forwardedRef, sheetRef)
212
-
213
- const driver = useAnimationDriver()
214
- if (!driver) {
215
- throw new Error('Must set animations in tamagui.config.ts')
216
- }
217
-
218
- const disableDrag = disableDragProp ?? controller?.disableDrag
219
- const keyboardIsVisible = useKeyboardVisible()
220
- const themeName = useThemeName()
221
-
222
- const { useAnimatedNumber, useAnimatedNumberReaction, useAnimatedNumberStyle } =
223
- driver
224
-
225
- const animatedNumber = useAnimatedNumber(HIDDEN_SIZE)
226
-
227
- // native only fix
228
- const at = useRef(0)
229
-
230
- useAnimatedNumberReaction(
231
- {
232
- value: animatedNumber,
233
- hostRef: sheetRef,
234
- },
235
- (value) => {
236
- if (!driver.isReactNative) return
237
- at.current = value
238
- scrollBridge.paneY = value
239
- }
240
- )
241
-
242
- function stopSpring() {
243
- animatedNumber.stop()
244
- if (scrollBridge.onFinishAnimate) {
245
- scrollBridge.onFinishAnimate()
246
- scrollBridge.onFinishAnimate = undefined
247
- }
248
- }
249
-
250
- // we need to set this *after* fully closed to 0, to avoid it overlapping
251
- // the page when resizing quickly on web for example
252
- const [opacity, setOpacity] = useState(open ? 1 : 0)
253
- if (open && opacity === 0) {
254
- setOpacity(1)
255
- }
256
- useEffect(() => {
257
- if (!open) {
258
- // need to wait for animation complete, for now lets just do it naively
259
- const tm = setTimeout(() => {
260
- setOpacity(0)
261
- }, 400)
262
- return () => {
263
- clearTimeout(tm)
264
- }
265
- }
266
- }, [open])
267
-
268
- const animateTo = useEvent((position: number) => {
269
- const current = animatedNumber.getValue()
270
- if (isHidden && open) return
271
- if (!current) return
272
- if (frameSize === 0) return
273
- const hiddenValue = frameSize === 0 ? HIDDEN_SIZE : screenSize
274
- const toValue = isHidden || position === -1 ? hiddenValue : positions[position]
275
- if (at.current === toValue) return
276
- stopSpring()
277
- if (isHidden) {
278
- animatedNumber.setValue(toValue, {
279
- type: 'timing',
280
- duration: 0,
281
- })
282
- at.current = toValue
283
- return
284
- }
285
- // dont bounce on initial measure to bottom
286
- const overshootClamping = at.current === HIDDEN_SIZE
287
- animatedNumber.setValue(toValue, {
288
- ...animationConfig,
289
- type: 'spring',
290
- overshootClamping,
291
- })
292
- })
293
-
294
- useIsomorphicLayoutEffect(() => {
295
- animateTo(position)
296
- }, [isHidden, frameSize, position, animateTo])
297
-
298
- /**
299
- * This is a hacky workaround for native:
300
- */
301
- const [isShowingInnerSheet, setIsShowingInnerSheet] = useState(false)
302
- const shouldHideParentSheet = !isWeb && modal && isShowingInnerSheet
303
- const parentSheetContext = useContext(SheetInsideSheetContext)
304
- const onInnerSheet = useCallback((hasChild: boolean) => {
305
- setIsShowingInnerSheet(hasChild)
306
- }, [])
307
-
308
- const panResponder = useMemo(
309
- () => {
310
- if (disableDrag) return
311
- if (!frameSize) return
312
- if (isShowingInnerSheet) return
313
-
314
- const minY = positions[0]
315
- scrollBridge.paneMinY = minY
316
- let startY = at.current
317
-
318
- function makeUnselectable(val: boolean) {
319
- if (!selectionStyleSheet) return
320
- if (!val) {
321
- selectionStyleSheet.innerText = ''
322
- } else {
323
- selectionStyleSheet.innerText =
324
- ':root * { user-select: none !important; -webkit-user-select: none !important; }'
325
- }
326
- }
327
-
328
- const release = ({ vy, dragAt }: { dragAt: number; vy: number }) => {
329
- isExternalDrag = false
330
- previouslyScrolling = false
331
- makeUnselectable(false)
332
- const at = dragAt + startY
333
- // seems liky vy goes up to about 4 at the very most (+ is down, - is up)
334
- // lets base our multiplier on the total layout height
335
- const end = at + frameSize * vy * 0.2
336
- let closestPoint = 0
337
- let dist = Infinity
338
- for (let i = 0; i < positions.length; i++) {
339
- const position = positions[i]
340
- const curDist = end > position ? end - position : position - end
341
- if (curDist < dist) {
342
- dist = curDist
343
- closestPoint = i
344
- }
345
- }
346
- // have to call both because state may not change but need to snap back
347
- setPosition(closestPoint)
348
- animateTo(closestPoint)
349
- }
350
-
351
- const finish = (_e: GestureResponderEvent, state: PanResponderGestureState) => {
352
- release({
353
- vy: state.vy,
354
- dragAt: state.dy,
355
- })
356
- }
357
-
358
- let previouslyScrolling = false
359
-
360
- const onMoveShouldSet = (
361
- _e: GestureResponderEvent,
362
- { dy }: PanResponderGestureState
363
- ) => {
364
- const isScrolled = scrollBridge.y !== 0
365
- const isDraggingUp = dy < 0
366
- // we can treat near top instead of exactly to avoid trouble with springs
367
- const isNearTop = scrollBridge.paneY - 5 <= scrollBridge.paneMinY
368
- if (isScrolled) {
369
- previouslyScrolling = true
370
- return false
371
- }
372
- // prevent drag once at top and pulling up
373
- if (isNearTop) {
374
- if (!isScrolled && isDraggingUp) {
375
- return false
376
- }
377
- }
378
- // we could do some detection of other touchables and cancel here..
379
- return Math.abs(dy) > 5
380
- }
381
-
382
- const grant = () => {
383
- makeUnselectable(true)
384
- stopSpring()
385
- startY = at.current
386
- }
387
-
388
- let isExternalDrag = false
389
-
390
- scrollBridge.drag = (dy) => {
391
- if (!isExternalDrag) {
392
- isExternalDrag = true
393
- grant()
394
- }
395
- const to = dy + startY
396
- animatedNumber.setValue(resisted(to, minY), { type: 'direct' })
397
- }
398
-
399
- scrollBridge.release = release
400
-
401
- return PanResponder.create({
402
- onMoveShouldSetPanResponder: onMoveShouldSet,
403
- onPanResponderGrant: grant,
404
- onPanResponderMove: (_e, { dy }) => {
405
- const toFull = dy + startY
406
- const to = resisted(toFull, minY)
407
- animatedNumber.setValue(to, { type: 'direct' })
408
- },
409
- onPanResponderEnd: finish,
410
- onPanResponderTerminate: finish,
411
- onPanResponderRelease: finish,
412
- })
413
- },
414
- // eslint-disable-next-line react-hooks/exhaustive-deps
415
- [disableDrag, isShowingInnerSheet, animateTo, frameSize, positions, setPosition]
416
- )
417
-
418
- const animatedStyle = useAnimatedNumberStyle(animatedNumber, (val) => {
419
- 'worklet'
420
- const translateY = frameSize === 0 ? HIDDEN_SIZE : val
421
- return {
422
- transform: [{ translateY }],
423
- }
424
- })
425
-
426
- const sizeBeforeKeyboard = useRef<number | null>(null)
427
- useEffect(() => {
428
- if (isWeb || !moveOnKeyboardChange) return
429
- const keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', (e) => {
430
- if (sizeBeforeKeyboard.current !== null) return
431
- sizeBeforeKeyboard.current = animatedNumber.getValue()
432
- animatedNumber.setValue(
433
- Math.max(animatedNumber.getValue() - e.endCoordinates.height, 0)
434
- )
435
- })
436
- const keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', () => {
437
- if (sizeBeforeKeyboard.current === null) return
438
- animatedNumber.setValue(sizeBeforeKeyboard.current)
439
- sizeBeforeKeyboard.current = null
440
- })
441
-
442
- return () => {
443
- keyboardDidHideListener.remove()
444
- keyboardDidShowListener.remove()
445
- }
446
- }, [])
447
-
448
- // temp until reanimated useAnimatedNumber fix
449
- const AnimatedView = (driver['NumberView'] ?? driver.View) as typeof Animated.View
450
-
451
- useIsomorphicLayoutEffect(() => {
452
- if (!(parentSheetContext && open)) return
453
- parentSheetContext(true)
454
- return () => {
455
- parentSheetContext(false)
456
- }
457
- }, [parentSheetContext, open])
458
-
459
- const nextParentContext = useMemo(
460
- () => ({
461
- zIndex,
462
- }),
463
- [zIndex]
464
- )
465
-
466
- const handleLayout = useCallback(
467
- (e) => {
468
- let next = e.nativeEvent?.layout.height
469
- if (isWeb && isTouchable && !open) {
470
- // temp fix ios bug where it doesn't go below dynamic bottom...
471
- next += 100
472
- }
473
- if (!next) return
474
- setFrameSize(() => next)
475
- },
476
- [keyboardIsVisible]
477
- )
478
-
479
- const removeScrollEnabled = forceRemoveScrollEnabled ?? (open && modal)
480
-
481
- const contents = (
482
- <ParentSheetContext.Provider value={nextParentContext}>
483
- <SheetProvider {...providerProps}>
484
- {shouldHideParentSheet ? null : overlayComponent}
485
-
486
- <AnimatedView
487
- ref={ref}
488
- {...panResponder?.panHandlers}
489
- onLayout={handleLayout}
490
- pointerEvents={open && !shouldHideParentSheet ? 'auto' : 'none'}
491
- // @ts-ignore
492
- animation={props.animation}
493
- style={[
494
- {
495
- position: 'absolute',
496
- zIndex,
497
- width: '100%',
498
- height: `${maxSnapPoint}%`,
499
- opacity,
500
- },
501
- animatedStyle,
502
- ]}
503
- >
504
- {handleComponent}
505
-
506
- {bottomCoverComponent}
507
- {/* @ts-ignore */}
508
- <RemoveScroll
509
- forwardProps
510
- enabled={removeScrollEnabled}
511
- allowPinchZoom
512
- shards={[contentRef]}
513
- // causes lots of bugs on touch web on site
514
- removeScrollBar={false}
515
- >
516
- {frameComponent}
517
- </RemoveScroll>
518
- </AnimatedView>
519
- </SheetProvider>
520
- </ParentSheetContext.Provider>
521
- )
522
-
523
- const adaptContext = useContext(AdaptParentContext)
524
-
525
- if (modal) {
526
- const modalContents = (
527
- <Portal zIndex={zIndex} {...portalProps}>
528
- <Theme forceClassName name={themeName}>
529
- <AdaptParentContext.Provider value={adaptContext}>
530
- {contents}
531
- </AdaptParentContext.Provider>
532
- </Theme>
533
- </Portal>
534
- )
535
-
536
- if (isWeb) {
537
- return modalContents
538
- }
539
-
540
- // on native we don't support multiple modals yet... fix for now is to hide outer one
541
- return (
542
- <SheetInsideSheetContext.Provider value={onInnerSheet}>
543
- {modalContents}
544
- </SheetInsideSheetContext.Provider>
545
- )
546
- }
547
-
548
- return contents
549
- })
550
- )
551
-
552
- const SheetInsideSheetContext = createContext<((hasChild: boolean) => void) | null>(null)
553
-
554
212
  /* -------------------------------------------------------------------------------------------------*/
555
-
556
- function resisted(y: number, minY: number, maxOverflow = 25) {
557
- if (y < minY) {
558
- const past = minY - y
559
- const pctPast = Math.min(maxOverflow, past) / maxOverflow
560
- const diminishBy = 1.1 - Math.pow(0.1, pctPast)
561
- const extra = -diminishBy * maxOverflow
562
- return minY + extra
563
- }
564
- return y
565
- }
@@ -0,0 +1,10 @@
1
+ export function resisted(y: number, minY: number, maxOverflow = 25) {
2
+ if (y < minY) {
3
+ const past = minY - y
4
+ const pctPast = Math.min(maxOverflow, past) / maxOverflow
5
+ const diminishBy = 1.1 - Math.pow(0.1, pctPast)
6
+ const extra = -diminishBy * maxOverflow
7
+ return minY + extra
8
+ }
9
+ return y
10
+ }
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './Sheet'
2
+ export * from './useSheet'
2
3
  export * from './createSheet'
3
4
  export * from './SheetController'
4
5
  export * from './useSheetController'
@@ -3,7 +3,6 @@ import { FunctionComponent, useEffect, useRef } from 'react'
3
3
 
4
4
  import { SheetProvider } from './SheetContext'
5
5
  import { SheetProps } from './types'
6
- import { useSheetChildren } from './useSheetChildren'
7
6
  import { useSheetOpenState } from './useSheetOpenState'
8
7
  import { useSheetProviderProps } from './useSheetProviderProps'
9
8
 
@@ -26,7 +25,6 @@ export function setupNativeSheet(platform: SheetNativePlatforms, Implementation:
26
25
  const providerProps = useSheetProviderProps(props, state)
27
26
  // const { position } = providerProps
28
27
  // const { positions } = useSheetSnapPoints(providerProps)
29
- const { frameComponent } = useSheetChildren(props.children)
30
28
 
31
29
  const { open, setOpen } = state
32
30
  const ref = useRef<{
@@ -45,9 +43,9 @@ export function setupNativeSheet(platform: SheetNativePlatforms, Implementation:
45
43
 
46
44
  return (
47
45
  <>
48
- <SheetProvider {...providerProps}>
46
+ <SheetProvider {...providerProps} onlyShowFrame>
49
47
  <Implementation ref={ref} onModalDismiss={() => setOpen(false)}>
50
- {frameComponent}
48
+ {props.children}
51
49
  </Implementation>
52
50
 
53
51
  {/* for some reason select triggers wont show on native if this isn't inside the actual tree not inside implementation... */}
@@ -59,7 +57,7 @@ export function setupNativeSheet(platform: SheetNativePlatforms, Implementation:
59
57
  width={0}
60
58
  height={0}
61
59
  >
62
- {frameComponent}
60
+ {props.children}
63
61
  </YStack>
64
62
  </SheetProvider>
65
63
  </>
@@ -0,0 +1,3 @@
1
+ import { useSheetContext } from './SheetContext'
2
+
3
+ export const useSheet = () => useSheetContext('', undefined)
@@ -8,6 +8,7 @@ export const useSheetController = () => {
8
8
  controller,
9
9
  isHidden,
10
10
  isShowingNonSheet,
11
+ disableDrag: controller?.disableDrag,
11
12
  }
12
13
  }
13
14