@hanzogui/sheet 8.0.1 → 8.1.1
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.
- package/dist/cjs/GestureDetectorWrapper.native.js.map +1 -1
- package/dist/cjs/GestureSheetContext.native.js.map +1 -1
- package/dist/cjs/Sheet.native.js.map +1 -1
- package/dist/cjs/SheetContext.native.js.map +1 -1
- package/dist/cjs/SheetController.native.js.map +1 -1
- package/dist/cjs/SheetImplementationCustom.native.js.map +1 -1
- package/dist/cjs/SheetScrollView.native.js.map +1 -1
- package/dist/cjs/constants.native.js.map +1 -1
- package/dist/cjs/contexts.native.js.map +1 -1
- package/dist/cjs/controller.native.js.map +1 -1
- package/dist/cjs/createSheet.native.js.map +1 -1
- package/dist/cjs/gestureState.native.js.map +1 -1
- package/dist/cjs/helpers.native.js.map +1 -1
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/keyboardAvoidance.native.js.map +1 -1
- package/dist/cjs/nativeSheet.native.js.map +1 -1
- package/dist/cjs/setupGestureHandler.native.js.map +1 -1
- package/dist/cjs/types.native.js.map +1 -1
- package/dist/cjs/useGestureHandlerPan.native.js.map +1 -1
- package/dist/cjs/useSheet.native.js.map +1 -1
- package/dist/cjs/useSheetController.native.js.map +1 -1
- package/dist/cjs/useSheetOffscreenSize.native.js.map +1 -1
- package/dist/cjs/useSheetOpenState.native.js.map +1 -1
- package/dist/cjs/useSheetProviderProps.native.js.map +1 -1
- package/dist/cjs/webViewport.native.js.map +1 -1
- package/package.json +36 -21
- package/types/Sheet.d.ts +43 -43
- package/types/Sheet.d.ts.map +1 -1
- package/types/SheetImplementationCustom.d.ts +2 -2
- package/types/SheetScrollView.d.ts +10 -10
- package/types/createSheet.d.ts +22 -22
- package/.turbo/turbo-build.log +0 -2
- package/test/keyboardAvoidance.test.ts +0 -269
- package/tsconfig.json +0 -57
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, test } from 'vitest'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
getKeyboardAdjustedSheetY,
|
|
5
|
-
getKeyboardOccludedHeight,
|
|
6
|
-
getSheetReleasePosition,
|
|
7
|
-
} from '../src/keyboardAvoidance'
|
|
8
|
-
import {
|
|
9
|
-
getWebKeyboardBottomInset,
|
|
10
|
-
getWebKeyboardResizeHeight,
|
|
11
|
-
getWebVisualViewportOffsetTop,
|
|
12
|
-
} from '../src/webViewport'
|
|
13
|
-
|
|
14
|
-
const originalWindow = globalThis.window
|
|
15
|
-
const originalDocument = globalThis.document
|
|
16
|
-
|
|
17
|
-
function setWebViewport({
|
|
18
|
-
clientHeight,
|
|
19
|
-
visualViewportHeight,
|
|
20
|
-
offsetTop = 0,
|
|
21
|
-
}: {
|
|
22
|
-
clientHeight: number
|
|
23
|
-
visualViewportHeight: number
|
|
24
|
-
offsetTop?: number
|
|
25
|
-
}) {
|
|
26
|
-
Object.defineProperty(globalThis, 'document', {
|
|
27
|
-
configurable: true,
|
|
28
|
-
value: {
|
|
29
|
-
documentElement: {
|
|
30
|
-
clientHeight,
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
})
|
|
34
|
-
Object.defineProperty(globalThis, 'window', {
|
|
35
|
-
configurable: true,
|
|
36
|
-
value: {
|
|
37
|
-
innerHeight: clientHeight,
|
|
38
|
-
visualViewport: {
|
|
39
|
-
height: visualViewportHeight,
|
|
40
|
-
offsetTop,
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
})
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
afterEach(() => {
|
|
47
|
-
Object.defineProperty(globalThis, 'window', {
|
|
48
|
-
configurable: true,
|
|
49
|
-
value: originalWindow,
|
|
50
|
-
})
|
|
51
|
-
Object.defineProperty(globalThis, 'document', {
|
|
52
|
-
configurable: true,
|
|
53
|
-
value: originalDocument,
|
|
54
|
-
})
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
describe('getKeyboardAdjustedSheetY', () => {
|
|
58
|
-
const base = {
|
|
59
|
-
sheetY: 320,
|
|
60
|
-
screenSize: 844,
|
|
61
|
-
isKeyboardVisible: true,
|
|
62
|
-
keyboardHeight: 300,
|
|
63
|
-
safeAreaTop: 44,
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
test('keeps the original position when translation is disabled', () => {
|
|
67
|
-
expect(
|
|
68
|
-
getKeyboardAdjustedSheetY({
|
|
69
|
-
...base,
|
|
70
|
-
shouldTranslate: false,
|
|
71
|
-
})
|
|
72
|
-
).toBe(base.sheetY)
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
test('shifts sheets up by keyboard height and caps at safe area', () => {
|
|
76
|
-
expect(
|
|
77
|
-
getKeyboardAdjustedSheetY({
|
|
78
|
-
...base,
|
|
79
|
-
shouldTranslate: true,
|
|
80
|
-
})
|
|
81
|
-
).toBe(44)
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
test('keeps a smaller fit sheet at its natural height and moves it with the keyboard', () => {
|
|
85
|
-
expect(
|
|
86
|
-
getKeyboardAdjustedSheetY({
|
|
87
|
-
...base,
|
|
88
|
-
sheetY: 500,
|
|
89
|
-
shouldTranslate: true,
|
|
90
|
-
})
|
|
91
|
-
).toBe(200)
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
test('does not shift hidden keyboard or offscreen close positions', () => {
|
|
95
|
-
expect(
|
|
96
|
-
getKeyboardAdjustedSheetY({
|
|
97
|
-
...base,
|
|
98
|
-
isKeyboardVisible: false,
|
|
99
|
-
shouldTranslate: true,
|
|
100
|
-
})
|
|
101
|
-
).toBe(base.sheetY)
|
|
102
|
-
expect(
|
|
103
|
-
getKeyboardAdjustedSheetY({
|
|
104
|
-
...base,
|
|
105
|
-
sheetY: base.screenSize,
|
|
106
|
-
shouldTranslate: true,
|
|
107
|
-
})
|
|
108
|
-
).toBe(base.screenSize)
|
|
109
|
-
})
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
describe('getKeyboardOccludedHeight', () => {
|
|
113
|
-
const base = {
|
|
114
|
-
frameSize: 700,
|
|
115
|
-
isKeyboardVisible: true,
|
|
116
|
-
keyboardHeight: 300,
|
|
117
|
-
screenSize: 844,
|
|
118
|
-
sheetY: 59,
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
test('returns overflow below the keyboard top after the sheet is clamped', () => {
|
|
122
|
-
expect(getKeyboardOccludedHeight(base)).toBe(215)
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
test('returns zero when the keyboard-adjusted sheet clears the keyboard', () => {
|
|
126
|
-
expect(
|
|
127
|
-
getKeyboardOccludedHeight({
|
|
128
|
-
...base,
|
|
129
|
-
frameSize: 400,
|
|
130
|
-
sheetY: 144,
|
|
131
|
-
})
|
|
132
|
-
).toBe(0)
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
test('ignores hidden keyboard and offscreen sheet positions', () => {
|
|
136
|
-
expect(
|
|
137
|
-
getKeyboardOccludedHeight({
|
|
138
|
-
...base,
|
|
139
|
-
isKeyboardVisible: false,
|
|
140
|
-
})
|
|
141
|
-
).toBe(0)
|
|
142
|
-
expect(
|
|
143
|
-
getKeyboardOccludedHeight({
|
|
144
|
-
...base,
|
|
145
|
-
sheetY: base.screenSize,
|
|
146
|
-
})
|
|
147
|
-
).toBe(0)
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
test('clamps occlusion to the frame height', () => {
|
|
151
|
-
expect(
|
|
152
|
-
getKeyboardOccludedHeight({
|
|
153
|
-
...base,
|
|
154
|
-
frameSize: 120,
|
|
155
|
-
keyboardHeight: 1000,
|
|
156
|
-
sheetY: 0,
|
|
157
|
-
})
|
|
158
|
-
).toBe(120)
|
|
159
|
-
})
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
describe('getSheetReleasePosition', () => {
|
|
163
|
-
// WEB keyboard-fit-dismiss threshold (the 75de9c9694 web keyboard-handoff fix):
|
|
164
|
-
// when the keyboard is up, a fit+dismiss sheet only dismisses after enough
|
|
165
|
-
// ACTUAL travel, ignoring a velocity-projected short drag.
|
|
166
|
-
test('web: keeps a keyboard-fit sheet open when velocity projects a short drag to dismiss', () => {
|
|
167
|
-
expect(
|
|
168
|
-
getSheetReleasePosition({
|
|
169
|
-
positions: [0, 844],
|
|
170
|
-
projectedEnd: 480,
|
|
171
|
-
currentPosition: 150,
|
|
172
|
-
frameSize: 591,
|
|
173
|
-
dismissOnSnapToBottom: true,
|
|
174
|
-
snapPointsMode: 'fit',
|
|
175
|
-
isKeyboardVisible: true,
|
|
176
|
-
isWeb: true,
|
|
177
|
-
})
|
|
178
|
-
).toBe(0)
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
test('web: allows a keyboard-fit sheet to dismiss after enough actual travel', () => {
|
|
182
|
-
expect(
|
|
183
|
-
getSheetReleasePosition({
|
|
184
|
-
positions: [0, 844],
|
|
185
|
-
projectedEnd: 560,
|
|
186
|
-
currentPosition: 225,
|
|
187
|
-
frameSize: 591,
|
|
188
|
-
dismissOnSnapToBottom: true,
|
|
189
|
-
snapPointsMode: 'fit',
|
|
190
|
-
isKeyboardVisible: true,
|
|
191
|
-
isWeb: true,
|
|
192
|
-
})
|
|
193
|
-
).toBe(1)
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
// NATIVE must NOT apply the web threshold — it snaps purely by projected
|
|
197
|
-
// position (the pre-rework v2.1.0 behavior). regression guard: with the
|
|
198
|
-
// threshold leaking into native, this short-projected drag wrongly stayed open
|
|
199
|
-
// (0); native should snap to the nearest point (here: dismiss, index 1).
|
|
200
|
-
test('native: snaps a keyboard-fit sheet by projected position, ignoring the web threshold', () => {
|
|
201
|
-
expect(
|
|
202
|
-
getSheetReleasePosition({
|
|
203
|
-
positions: [0, 844],
|
|
204
|
-
projectedEnd: 480,
|
|
205
|
-
currentPosition: 150,
|
|
206
|
-
frameSize: 591,
|
|
207
|
-
dismissOnSnapToBottom: true,
|
|
208
|
-
snapPointsMode: 'fit',
|
|
209
|
-
isKeyboardVisible: true,
|
|
210
|
-
isWeb: false,
|
|
211
|
-
})
|
|
212
|
-
).toBe(1)
|
|
213
|
-
})
|
|
214
|
-
|
|
215
|
-
test('native: a projected-open drag snaps back open', () => {
|
|
216
|
-
expect(
|
|
217
|
-
getSheetReleasePosition({
|
|
218
|
-
positions: [0, 844],
|
|
219
|
-
projectedEnd: 200,
|
|
220
|
-
currentPosition: 300,
|
|
221
|
-
frameSize: 591,
|
|
222
|
-
dismissOnSnapToBottom: true,
|
|
223
|
-
snapPointsMode: 'fit',
|
|
224
|
-
isKeyboardVisible: true,
|
|
225
|
-
isWeb: false,
|
|
226
|
-
})
|
|
227
|
-
).toBe(0)
|
|
228
|
-
})
|
|
229
|
-
|
|
230
|
-
test('keeps normal multi-snap release behavior outside keyboard-fit dismiss', () => {
|
|
231
|
-
expect(
|
|
232
|
-
getSheetReleasePosition({
|
|
233
|
-
positions: [0, 360, 844],
|
|
234
|
-
projectedEnd: 310,
|
|
235
|
-
currentPosition: 90,
|
|
236
|
-
frameSize: 591,
|
|
237
|
-
dismissOnSnapToBottom: true,
|
|
238
|
-
snapPointsMode: 'percent',
|
|
239
|
-
isKeyboardVisible: true,
|
|
240
|
-
isWeb: true,
|
|
241
|
-
})
|
|
242
|
-
).toBe(1)
|
|
243
|
-
})
|
|
244
|
-
})
|
|
245
|
-
|
|
246
|
-
describe('web viewport keyboard metrics', () => {
|
|
247
|
-
test('separates keyboard resize height from bottom inset when Safari pans the visual viewport', () => {
|
|
248
|
-
setWebViewport({
|
|
249
|
-
clientHeight: 678,
|
|
250
|
-
visualViewportHeight: 452,
|
|
251
|
-
offsetTop: 158,
|
|
252
|
-
})
|
|
253
|
-
|
|
254
|
-
expect(getWebKeyboardResizeHeight()).toBe(226)
|
|
255
|
-
expect(getWebVisualViewportOffsetTop()).toBe(158)
|
|
256
|
-
expect(getWebKeyboardBottomInset()).toBe(68)
|
|
257
|
-
})
|
|
258
|
-
|
|
259
|
-
test('matches resize height and bottom inset when the visual viewport is not panned', () => {
|
|
260
|
-
setWebViewport({
|
|
261
|
-
clientHeight: 678,
|
|
262
|
-
visualViewportHeight: 452,
|
|
263
|
-
})
|
|
264
|
-
|
|
265
|
-
expect(getWebKeyboardResizeHeight()).toBe(226)
|
|
266
|
-
expect(getWebVisualViewportOffsetTop()).toBe(0)
|
|
267
|
-
expect(getWebKeyboardBottomInset()).toBe(226)
|
|
268
|
-
})
|
|
269
|
-
})
|
package/tsconfig.json
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../../tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"composite": true,
|
|
5
|
-
"strict": true
|
|
6
|
-
},
|
|
7
|
-
"references": [
|
|
8
|
-
{
|
|
9
|
-
"path": "../../core/animations-react-native"
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
"path": "../../core/compose-refs"
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
"path": "../../core/constants"
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
"path": "../../core/core"
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"path": "../../core/create-context"
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
"path": "../../core/helpers"
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
"path": "../../core/use-constant"
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
"path": "../../core/use-controllable-state"
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"path": "../../core/use-keyboard-visible"
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
"path": "../animate-presence"
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
"path": "../portal"
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
"path": "../remove-scroll"
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
"path": "../scroll-view"
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
"path": "../stacks"
|
|
49
|
-
}
|
|
50
|
-
],
|
|
51
|
-
"exclude": [
|
|
52
|
-
"types",
|
|
53
|
-
"dist",
|
|
54
|
-
"test",
|
|
55
|
-
"**/__tests__"
|
|
56
|
-
]
|
|
57
|
-
}
|