@tamagui/sheet 1.0.1-beta.133 → 1.0.1-beta.136
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/RemoveScrollProps.js +17 -0
- package/dist/cjs/RemoveScrollProps.js.map +7 -0
- package/dist/cjs/SHEET_HANDLE_NAME.js +35 -0
- package/dist/cjs/SHEET_HANDLE_NAME.js.map +7 -0
- package/dist/cjs/Sheet.js +61 -118
- package/dist/cjs/Sheet.js.map +2 -2
- package/dist/cjs/SheetContext.js +38 -0
- package/dist/cjs/SheetContext.js.map +7 -0
- package/dist/cjs/SheetScrollView.js +115 -0
- package/dist/cjs/SheetScrollView.js.map +7 -0
- package/dist/cjs/types.js +17 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/esm/RemoveScrollProps.js +1 -0
- package/dist/esm/RemoveScrollProps.js.map +7 -0
- package/dist/esm/SHEET_HANDLE_NAME.js +9 -0
- package/dist/esm/SHEET_HANDLE_NAME.js.map +7 -0
- package/dist/esm/Sheet.js +54 -113
- package/dist/esm/Sheet.js.map +2 -2
- package/dist/esm/SheetContext.js +11 -0
- package/dist/esm/SheetContext.js.map +7 -0
- package/dist/esm/SheetScrollView.js +88 -0
- package/dist/esm/SheetScrollView.js.map +7 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +7 -0
- package/dist/jsx/RemoveScrollProps.js +1 -0
- package/dist/jsx/RemoveScrollProps.js.map +7 -0
- package/dist/jsx/SHEET_HANDLE_NAME.js +9 -0
- package/dist/jsx/SHEET_HANDLE_NAME.js.map +7 -0
- package/dist/jsx/Sheet.js +58 -101
- package/dist/jsx/Sheet.js.map +2 -2
- package/dist/jsx/SheetContext.js +11 -0
- package/dist/jsx/SheetContext.js.map +7 -0
- package/dist/jsx/SheetScrollView.js +77 -0
- package/dist/jsx/SheetScrollView.js.map +7 -0
- package/dist/jsx/types.js +1 -0
- package/dist/jsx/types.js.map +7 -0
- package/package.json +9 -8
- package/src/SHEET_HANDLE_NAME.tsx +4 -0
- package/src/Sheet.tsx +82 -203
- package/src/SheetContext.tsx +25 -0
- package/src/SheetScrollView.tsx +109 -0
- package/src/types.tsx +44 -0
- package/types/SHEET_HANDLE_NAME.d.ts +4 -0
- package/types/Sheet.d.ts +21 -56
- package/types/SheetContext.d.ts +36 -0
- package/types/SheetScrollView.d.ts +4 -0
- package/types/types.d.ts +40 -0
|
@@ -0,0 +1,115 @@
|
|
|
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(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var SheetScrollView_exports = {};
|
|
23
|
+
__export(SheetScrollView_exports, {
|
|
24
|
+
SheetScrollView: () => SheetScrollView
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(SheetScrollView_exports);
|
|
27
|
+
var import_react = __toESM(require("react"));
|
|
28
|
+
var import_react_native = require("react-native");
|
|
29
|
+
var import_SheetContext = require("./SheetContext");
|
|
30
|
+
const SHEET_SCROLL_VIEW_NAME = "SheetScrollView";
|
|
31
|
+
const SheetScrollView = (0, import_react.forwardRef)(({ __scopeSheet, ...props }, ref) => {
|
|
32
|
+
const { scrollBridge } = (0, import_SheetContext.useSheetContext)(SHEET_SCROLL_VIEW_NAME, __scopeSheet);
|
|
33
|
+
const [scrollEnabled, setScrollEnabled] = (0, import_react.useState)(true);
|
|
34
|
+
const state = (0, import_react.useRef)({
|
|
35
|
+
lastPageY: 0,
|
|
36
|
+
dragAt: 0,
|
|
37
|
+
dys: [],
|
|
38
|
+
isScrolling: false
|
|
39
|
+
});
|
|
40
|
+
const release = () => {
|
|
41
|
+
scrollBridge.scrollStartY = -1;
|
|
42
|
+
state.current.isScrolling = false;
|
|
43
|
+
setScrollEnabled(true);
|
|
44
|
+
let vy = 0;
|
|
45
|
+
if (state.current.dys.length) {
|
|
46
|
+
const recentDys = state.current.dys.slice(-10);
|
|
47
|
+
const dist = recentDys.length ? recentDys.reduce((a, b) => a + b, 0) : 0;
|
|
48
|
+
const avgDy = dist / recentDys.length;
|
|
49
|
+
vy = avgDy * 0.04;
|
|
50
|
+
console.table([{ vy, avgDy, dist, recentDys }]);
|
|
51
|
+
}
|
|
52
|
+
state.current.dys = [];
|
|
53
|
+
scrollBridge.release({
|
|
54
|
+
dragAt: state.current.dragAt,
|
|
55
|
+
vy
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react_native.ScrollView, {
|
|
59
|
+
ref,
|
|
60
|
+
scrollEventThrottle: 8,
|
|
61
|
+
scrollEnabled,
|
|
62
|
+
onScroll: (e) => {
|
|
63
|
+
const { y } = e.nativeEvent.contentOffset;
|
|
64
|
+
scrollBridge.y = y;
|
|
65
|
+
if (y > 0) {
|
|
66
|
+
scrollBridge.scrollStartY = -1;
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
onStartShouldSetResponder: () => {
|
|
70
|
+
scrollBridge.scrollStartY = -1;
|
|
71
|
+
return true;
|
|
72
|
+
},
|
|
73
|
+
onMoveShouldSetResponder: () => true,
|
|
74
|
+
onResponderMove: (e) => {
|
|
75
|
+
const { pageY } = e.nativeEvent;
|
|
76
|
+
if (state.current.isScrolling) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (scrollBridge.scrollStartY === -1) {
|
|
80
|
+
scrollBridge.scrollStartY = pageY;
|
|
81
|
+
state.current.lastPageY = pageY;
|
|
82
|
+
}
|
|
83
|
+
const dragAt = pageY - scrollBridge.scrollStartY;
|
|
84
|
+
const dy = pageY - state.current.lastPageY;
|
|
85
|
+
state.current.lastPageY = pageY;
|
|
86
|
+
const isDraggingUp = dy < 0;
|
|
87
|
+
const isPaneAtTop = scrollBridge.paneY <= scrollBridge.paneMinY;
|
|
88
|
+
if ((dy === 0 || isDraggingUp) && isPaneAtTop) {
|
|
89
|
+
state.current.isScrolling = true;
|
|
90
|
+
setScrollEnabled(true);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
setScrollEnabled(false);
|
|
94
|
+
scrollBridge.drag(dragAt);
|
|
95
|
+
state.current.dragAt = dragAt;
|
|
96
|
+
state.current.dys.push(dy);
|
|
97
|
+
if (state.current.dys.length > 100) {
|
|
98
|
+
state.current.dys = state.current.dys.slice(-10);
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
onResponderRelease: release,
|
|
102
|
+
...props,
|
|
103
|
+
style: [
|
|
104
|
+
{
|
|
105
|
+
flex: 1
|
|
106
|
+
},
|
|
107
|
+
props.style
|
|
108
|
+
]
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
112
|
+
0 && (module.exports = {
|
|
113
|
+
SheetScrollView
|
|
114
|
+
});
|
|
115
|
+
//# sourceMappingURL=SheetScrollView.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/SheetScrollView.tsx"],
|
|
4
|
+
"sourcesContent": ["import React, { forwardRef, useRef, useState } from 'react'\nimport { ScrollView, ScrollViewProps } from 'react-native'\n\nimport { useSheetContext } from './SheetContext'\nimport { SheetScopedProps } from './types'\n\n/* -------------------------------------------------------------------------------------------------\n * SheetScrollView\n * -----------------------------------------------------------------------------------------------*/\n\nconst SHEET_SCROLL_VIEW_NAME = 'SheetScrollView'\n\nexport const SheetScrollView = forwardRef<ScrollView, ScrollViewProps>(\n ({ __scopeSheet, ...props }: SheetScopedProps<ScrollViewProps>, ref) => {\n const { scrollBridge } = useSheetContext(SHEET_SCROLL_VIEW_NAME, __scopeSheet)\n const [scrollEnabled, setScrollEnabled] = useState(true)\n const state = useRef({\n lastPageY: 0,\n dragAt: 0,\n dys: [] as number[], // store a few recent dys to get velocity on release\n isScrolling: false,\n })\n\n const release = () => {\n scrollBridge.scrollStartY = -1\n state.current.isScrolling = false\n setScrollEnabled(true)\n let vy = 0\n if (state.current.dys.length) {\n const recentDys = state.current.dys.slice(-10)\n const dist = recentDys.length ? recentDys.reduce((a, b) => a + b, 0) : 0\n const avgDy = dist / recentDys.length\n vy = avgDy * 0.04\n console.table([{ vy, avgDy, dist, recentDys }])\n }\n state.current.dys = []\n scrollBridge.release({\n dragAt: state.current.dragAt,\n vy,\n })\n }\n\n return (\n <ScrollView\n ref={ref}\n scrollEventThrottle={8}\n scrollEnabled={scrollEnabled}\n onScroll={(e) => {\n const { y } = e.nativeEvent.contentOffset\n scrollBridge.y = y\n if (y > 0) {\n scrollBridge.scrollStartY = -1\n }\n }}\n onStartShouldSetResponder={() => {\n scrollBridge.scrollStartY = -1\n return true\n }}\n onMoveShouldSetResponder={() => true}\n onResponderMove={(e) => {\n const { pageY } = e.nativeEvent\n\n if (state.current.isScrolling) {\n return\n }\n\n if (scrollBridge.scrollStartY === -1) {\n scrollBridge.scrollStartY = pageY\n state.current.lastPageY = pageY\n }\n\n const dragAt = pageY - scrollBridge.scrollStartY\n const dy = pageY - state.current.lastPageY\n state.current.lastPageY = pageY // after dy\n // const isAboveStart = dragAt <= 0\n // const isDraggingDown = dy > 0\n // const isScrollAtTop = scrollBridge.y <= 0\n const isDraggingUp = dy < 0\n const isPaneAtTop = scrollBridge.paneY <= scrollBridge.paneMinY\n\n if ((dy === 0 || isDraggingUp) && isPaneAtTop) {\n state.current.isScrolling = true\n setScrollEnabled(true)\n return\n }\n\n setScrollEnabled(false)\n scrollBridge.drag(dragAt)\n state.current.dragAt = dragAt\n state.current.dys.push(dy)\n // only do every so often, cut down to 10 again\n if (state.current.dys.length > 100) {\n state.current.dys = state.current.dys.slice(-10)\n }\n }}\n onResponderRelease={release}\n // onResponderEnd={release}\n // onResponderTerminate={release}\n {...props}\n style={[\n {\n flex: 1,\n },\n props.style,\n ]}\n />\n )\n }\n)\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAoD;AACpD,0BAA4C;AAE5C,0BAAgC;AAOhC,MAAM,yBAAyB;AAExB,MAAM,kBAAkB,6BAC7B,CAAC,EAAE,iBAAiB,SAA4C,QAAQ;AACtE,QAAM,EAAE,iBAAiB,yCAAgB,wBAAwB,YAAY;AAC7E,QAAM,CAAC,eAAe,oBAAoB,2BAAS,IAAI;AACvD,QAAM,QAAQ,yBAAO;AAAA,IACnB,WAAW;AAAA,IACX,QAAQ;AAAA,IACR,KAAK,CAAC;AAAA,IACN,aAAa;AAAA,EACf,CAAC;AAED,QAAM,UAAU,MAAM;AACpB,iBAAa,eAAe;AAC5B,UAAM,QAAQ,cAAc;AAC5B,qBAAiB,IAAI;AACrB,QAAI,KAAK;AACT,QAAI,MAAM,QAAQ,IAAI,QAAQ;AAC5B,YAAM,YAAY,MAAM,QAAQ,IAAI,MAAM,GAAG;AAC7C,YAAM,OAAO,UAAU,SAAS,UAAU,OAAO,CAAC,GAAG,MAAM,IAAI,GAAG,CAAC,IAAI;AACvE,YAAM,QAAQ,OAAO,UAAU;AAC/B,WAAK,QAAQ;AACb,cAAQ,MAAM,CAAC,EAAE,IAAI,OAAO,MAAM,UAAU,CAAC,CAAC;AAAA,IAChD;AACA,UAAM,QAAQ,MAAM,CAAC;AACrB,iBAAa,QAAQ;AAAA,MACnB,QAAQ,MAAM,QAAQ;AAAA,MACtB;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SACE,mDAAC;AAAA,IACC;AAAA,IACA,qBAAqB;AAAA,IACrB;AAAA,IACA,UAAU,CAAC,MAAM;AACf,YAAM,EAAE,MAAM,EAAE,YAAY;AAC5B,mBAAa,IAAI;AACjB,UAAI,IAAI,GAAG;AACT,qBAAa,eAAe;AAAA,MAC9B;AAAA,IACF;AAAA,IACA,2BAA2B,MAAM;AAC/B,mBAAa,eAAe;AAC5B,aAAO;AAAA,IACT;AAAA,IACA,0BAA0B,MAAM;AAAA,IAChC,iBAAiB,CAAC,MAAM;AACtB,YAAM,EAAE,UAAU,EAAE;AAEpB,UAAI,MAAM,QAAQ,aAAa;AAC7B;AAAA,MACF;AAEA,UAAI,aAAa,iBAAiB,IAAI;AACpC,qBAAa,eAAe;AAC5B,cAAM,QAAQ,YAAY;AAAA,MAC5B;AAEA,YAAM,SAAS,QAAQ,aAAa;AACpC,YAAM,KAAK,QAAQ,MAAM,QAAQ;AACjC,YAAM,QAAQ,YAAY;AAI1B,YAAM,eAAe,KAAK;AAC1B,YAAM,cAAc,aAAa,SAAS,aAAa;AAEvD,UAAK,QAAO,KAAK,iBAAiB,aAAa;AAC7C,cAAM,QAAQ,cAAc;AAC5B,yBAAiB,IAAI;AACrB;AAAA,MACF;AAEA,uBAAiB,KAAK;AACtB,mBAAa,KAAK,MAAM;AACxB,YAAM,QAAQ,SAAS;AACvB,YAAM,QAAQ,IAAI,KAAK,EAAE;AAEzB,UAAI,MAAM,QAAQ,IAAI,SAAS,KAAK;AAClC,cAAM,QAAQ,MAAM,MAAM,QAAQ,IAAI,MAAM,GAAG;AAAA,MACjD;AAAA,IACF;AAAA,IACA,oBAAoB;AAAA,IAGnB,GAAG;AAAA,IACJ,OAAO;AAAA,MACL;AAAA,QACE,MAAM;AAAA,MACR;AAAA,MACA,MAAM;AAAA,IACR;AAAA,GACF;AAEJ,CACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
17
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/types.tsx"],
|
|
4
|
+
"sourcesContent": ["import { ScopedProps } from '@tamagui/create-context'\nimport { RemoveScroll } from '@tamagui/remove-scroll'\nimport React, { ReactNode } from 'react'\nimport { Animated } from 'react-native'\n\nexport type SheetProps = ScopedProps<\n {\n open?: boolean\n defaultOpen?: boolean\n onChangeOpen?: OpenChangeHandler\n position?: number\n defaultPosition?: number\n snapPoints?: number[]\n onChangePosition?: PositionChangeHandler\n children?: ReactNode\n dismissOnOverlayPress?: boolean\n dismissOnSnapToBottom?: boolean\n animationConfig?: Animated.SpringAnimationConfig\n handleDisableScroll?: boolean\n disableDrag?: boolean\n modal?: boolean\n },\n 'Sheet'\n>\n\nexport type PositionChangeHandler = (position: number) => void\n\ntype OpenChangeHandler = ((open: boolean) => void) | React.Dispatch<React.SetStateAction<boolean>>\n\nexport type RemoveScrollProps = React.ComponentProps<typeof RemoveScroll>\n\nexport type SheetScopedProps<A> = ScopedProps<A, 'Sheet'>\n\nexport type ScrollBridge = {\n enabled: boolean\n y: number\n paneY: number\n paneMinY: number\n scrollStartY: number\n drag: (dy: number) => void\n release: (state: { dragAt: number; vy: number }) => void\n scrollLock: boolean\n onFinishAnimate?: () => void\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=RemoveScrollProps.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/SHEET_HANDLE_NAME.tsx"],
|
|
4
|
+
"sourcesContent": ["export const constants = {}\n\nexport const SHEET_NAME = 'Sheet'\nexport const SHEET_HANDLE_NAME = 'SheetHandle'\n"],
|
|
5
|
+
"mappings": "AAAO,MAAM,YAAY,CAAC;AAEnB,MAAM,aAAa;AACnB,MAAM,oBAAoB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/esm/Sheet.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
2
2
|
import {
|
|
3
|
-
Slot,
|
|
4
3
|
Theme,
|
|
5
|
-
composeEventHandlers,
|
|
6
4
|
isClient,
|
|
7
5
|
isWeb,
|
|
8
6
|
mergeEvent,
|
|
@@ -14,9 +12,7 @@ import {
|
|
|
14
12
|
useThemeName,
|
|
15
13
|
withStaticProperties
|
|
16
14
|
} from "@tamagui/core";
|
|
17
|
-
import { createContextScope } from "@tamagui/create-context";
|
|
18
15
|
import { Portal } from "@tamagui/portal";
|
|
19
|
-
import { RemoveScroll } from "@tamagui/remove-scroll";
|
|
20
16
|
import { XStack, YStack } from "@tamagui/stacks";
|
|
21
17
|
import { useControllableState } from "@tamagui/use-controllable-state";
|
|
22
18
|
import React, {
|
|
@@ -32,41 +28,45 @@ import React, {
|
|
|
32
28
|
} from "react";
|
|
33
29
|
import {
|
|
34
30
|
Animated,
|
|
35
|
-
PanResponder
|
|
36
|
-
ScrollView
|
|
31
|
+
PanResponder
|
|
37
32
|
} from "react-native";
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
33
|
+
import { SHEET_HANDLE_NAME, SHEET_NAME } from "./SHEET_HANDLE_NAME";
|
|
34
|
+
import { SheetProvider, useSheetContext } from "./SheetContext";
|
|
35
|
+
import { SheetScrollView } from "./SheetScrollView";
|
|
36
|
+
import { createSheetScope } from "./SheetContext";
|
|
42
37
|
const SheetHandleFrame = styled(XStack, {
|
|
43
38
|
name: SHEET_HANDLE_NAME,
|
|
44
39
|
height: 10,
|
|
45
40
|
borderRadius: 100,
|
|
46
41
|
backgroundColor: "$background",
|
|
47
|
-
position: "absolute",
|
|
48
|
-
pointerEvents: "auto",
|
|
49
42
|
zIndex: 10,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
left: "35%",
|
|
53
|
-
right: "35%",
|
|
43
|
+
marginHorizontal: "35%",
|
|
44
|
+
marginBottom: "$2",
|
|
54
45
|
opacity: 0.5,
|
|
55
46
|
hoverStyle: {
|
|
56
47
|
opacity: 0.7
|
|
48
|
+
},
|
|
49
|
+
variants: {
|
|
50
|
+
open: {
|
|
51
|
+
true: {
|
|
52
|
+
pointerEvents: "auto"
|
|
53
|
+
},
|
|
54
|
+
false: {
|
|
55
|
+
opacity: 0,
|
|
56
|
+
pointerEvents: "none"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
57
59
|
}
|
|
58
60
|
});
|
|
59
61
|
const SheetHandle = SheetHandleFrame.extractable(({ __scopeSheet, ...props }) => {
|
|
60
62
|
const context = useSheetContext(SHEET_HANDLE_NAME, __scopeSheet);
|
|
61
|
-
if (context.open === false) {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
63
|
return /* @__PURE__ */ React.createElement(SheetHandleFrame, {
|
|
65
64
|
onPress: () => {
|
|
66
65
|
const max = context.snapPoints.length + (context.dismissOnSnapToBottom ? -1 : 0);
|
|
67
66
|
const nextPos = (context.position + 1) % max;
|
|
68
67
|
context.setPosition(nextPos);
|
|
69
68
|
},
|
|
69
|
+
open: context.open,
|
|
70
70
|
...props
|
|
71
71
|
});
|
|
72
72
|
});
|
|
@@ -91,81 +91,12 @@ const SheetOverlayFrame = styled(YStack, {
|
|
|
91
91
|
});
|
|
92
92
|
const SheetOverlay = SheetOverlayFrame.extractable(({ __scopeSheet, ...props }) => {
|
|
93
93
|
const context = useSheetContext(SHEET_OVERLAY_NAME, __scopeSheet);
|
|
94
|
-
return /* @__PURE__ */ React.createElement(
|
|
95
|
-
enabled: context.open && context.modal,
|
|
96
|
-
as: Slot,
|
|
97
|
-
allowPinchZoom: context.allowPinchZoom,
|
|
98
|
-
shards: [context.contentRef],
|
|
99
|
-
removeScrollBar: false
|
|
100
|
-
}, /* @__PURE__ */ React.createElement(SheetOverlayFrame, {
|
|
94
|
+
return /* @__PURE__ */ React.createElement(SheetOverlayFrame, {
|
|
101
95
|
closed: !context.open || context.hidden,
|
|
102
96
|
...props,
|
|
103
97
|
onPress: mergeEvent(props.onPress, context.dismissOnOverlayPress ? () => {
|
|
104
98
|
context.setOpen(false);
|
|
105
99
|
} : void 0)
|
|
106
|
-
}));
|
|
107
|
-
});
|
|
108
|
-
const SHEET_SCROLL_VIEW_NAME = "SheetScrollView";
|
|
109
|
-
const SheetScrollView = forwardRef(({ __scopeSheet, ...props }, ref) => {
|
|
110
|
-
const { scrollBridge } = useSheetContext(SHEET_SCROLL_VIEW_NAME, __scopeSheet);
|
|
111
|
-
const [scrollEnabled, setScrollEnabled] = useState(true);
|
|
112
|
-
const state = useRef({
|
|
113
|
-
dy: 0,
|
|
114
|
-
dys: []
|
|
115
|
-
});
|
|
116
|
-
const release = () => {
|
|
117
|
-
setScrollEnabled(true);
|
|
118
|
-
const recentDys = state.current.dys.slice(-10);
|
|
119
|
-
const dist = recentDys.length ? recentDys.reduce((a, b, i) => a + b - (recentDys[i - 1] ?? recentDys[0]), 0) : 0;
|
|
120
|
-
const avgDy = dist / recentDys.length;
|
|
121
|
-
const vy = avgDy * 0.075;
|
|
122
|
-
state.current.dys = [];
|
|
123
|
-
scrollBridge.release({
|
|
124
|
-
dy: state.current.dy,
|
|
125
|
-
vy
|
|
126
|
-
});
|
|
127
|
-
};
|
|
128
|
-
return /* @__PURE__ */ React.createElement(ScrollView, {
|
|
129
|
-
ref,
|
|
130
|
-
scrollEventThrottle: 16,
|
|
131
|
-
...props,
|
|
132
|
-
scrollEnabled: props.scrollEnabled || scrollEnabled,
|
|
133
|
-
onScroll: composeEventHandlers(props.onScroll, (e) => {
|
|
134
|
-
const { y } = e.nativeEvent.contentOffset;
|
|
135
|
-
scrollBridge.y = y;
|
|
136
|
-
if (y > 0) {
|
|
137
|
-
scrollBridge.scrollStartY = -1;
|
|
138
|
-
}
|
|
139
|
-
}),
|
|
140
|
-
onResponderMove: composeEventHandlers(props.onResponderMove, (e) => {
|
|
141
|
-
const { pageY } = e.nativeEvent;
|
|
142
|
-
if (scrollBridge.y <= 0) {
|
|
143
|
-
if (scrollBridge.scrollStartY === -1) {
|
|
144
|
-
scrollBridge.scrollStartY = pageY;
|
|
145
|
-
}
|
|
146
|
-
const dy = pageY - scrollBridge.scrollStartY;
|
|
147
|
-
if (dy <= 0) {
|
|
148
|
-
setScrollEnabled(true);
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
setScrollEnabled(false);
|
|
152
|
-
scrollBridge.drag(dy);
|
|
153
|
-
state.current.dy = dy;
|
|
154
|
-
state.current.dys.push(dy);
|
|
155
|
-
if (state.current.dys.length > 100) {
|
|
156
|
-
state.current.dys = state.current.dys.slice(-10);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}),
|
|
160
|
-
onResponderReject: composeEventHandlers(props.onResponderReject, release),
|
|
161
|
-
onResponderTerminate: composeEventHandlers(props.onResponderTerminate, release),
|
|
162
|
-
onResponderRelease: composeEventHandlers(props.onResponderRelease, release),
|
|
163
|
-
style: [
|
|
164
|
-
{
|
|
165
|
-
flex: 1
|
|
166
|
-
},
|
|
167
|
-
props.style
|
|
168
|
-
]
|
|
169
100
|
});
|
|
170
101
|
});
|
|
171
102
|
const selectionStyleSheet = isClient ? document.createElement("style") : null;
|
|
@@ -208,7 +139,7 @@ const Sheet = withStaticProperties(themeable(forwardRef(function Sheet2(props, r
|
|
|
208
139
|
dismissOnSnapToBottom = false,
|
|
209
140
|
disableDrag: disableDragProp,
|
|
210
141
|
modal = false,
|
|
211
|
-
|
|
142
|
+
handleDisableScroll = true
|
|
212
143
|
} = props;
|
|
213
144
|
if (process.env.NODE_ENV === "development") {
|
|
214
145
|
if (snapPointsProp.some((p) => p < 0 || p > 100)) {
|
|
@@ -223,11 +154,14 @@ const Sheet = withStaticProperties(themeable(forwardRef(function Sheet2(props, r
|
|
|
223
154
|
const scrollBridge = useConstant(() => ({
|
|
224
155
|
enabled: false,
|
|
225
156
|
y: 0,
|
|
157
|
+
paneY: 0,
|
|
158
|
+
paneMinY: 0,
|
|
226
159
|
scrollStartY: -1,
|
|
227
160
|
drag: () => {
|
|
228
161
|
},
|
|
229
162
|
release: () => {
|
|
230
|
-
}
|
|
163
|
+
},
|
|
164
|
+
scrollLock: false
|
|
231
165
|
}));
|
|
232
166
|
const onChangeOpenInternal = (val) => {
|
|
233
167
|
var _a;
|
|
@@ -274,6 +208,10 @@ const Sheet = withStaticProperties(themeable(forwardRef(function Sheet2(props, r
|
|
|
274
208
|
var _a;
|
|
275
209
|
(_a = spring.current) == null ? void 0 : _a.stop();
|
|
276
210
|
spring.current = null;
|
|
211
|
+
if (scrollBridge.onFinishAnimate) {
|
|
212
|
+
scrollBridge.onFinishAnimate();
|
|
213
|
+
scrollBridge.onFinishAnimate = void 0;
|
|
214
|
+
}
|
|
277
215
|
}
|
|
278
216
|
const shouldSetPositionOpen = open && position < 0;
|
|
279
217
|
useEffect(() => {
|
|
@@ -327,6 +265,7 @@ const Sheet = withStaticProperties(themeable(forwardRef(function Sheet2(props, r
|
|
|
327
265
|
useEffect(() => {
|
|
328
266
|
positionValue.current.addListener(({ value }) => {
|
|
329
267
|
at.current = value;
|
|
268
|
+
scrollBridge.paneY = value;
|
|
330
269
|
});
|
|
331
270
|
return () => {
|
|
332
271
|
positionValue.current.removeAllListeners();
|
|
@@ -339,6 +278,7 @@ const Sheet = withStaticProperties(themeable(forwardRef(function Sheet2(props, r
|
|
|
339
278
|
return;
|
|
340
279
|
const pos = positionValue.current;
|
|
341
280
|
const minY = positions[0];
|
|
281
|
+
scrollBridge.paneMinY = minY;
|
|
342
282
|
let startY = at.current;
|
|
343
283
|
function makeUnselectable(val) {
|
|
344
284
|
if (!selectionStyleSheet)
|
|
@@ -349,12 +289,12 @@ const Sheet = withStaticProperties(themeable(forwardRef(function Sheet2(props, r
|
|
|
349
289
|
selectionStyleSheet.innerText = `:root * { user-select: none !important; -webkit-user-select: none !important; }`;
|
|
350
290
|
}
|
|
351
291
|
}
|
|
352
|
-
const release = ({ vy,
|
|
292
|
+
const release = ({ vy, dragAt }) => {
|
|
353
293
|
isExternalDrag = false;
|
|
354
294
|
previouslyScrolling = false;
|
|
355
295
|
makeUnselectable(false);
|
|
356
|
-
const at2 =
|
|
357
|
-
const end = at2 + frameSize * vy * 0.
|
|
296
|
+
const at2 = dragAt + startY;
|
|
297
|
+
const end = at2 + frameSize * vy * 0.2;
|
|
358
298
|
let closestPoint = 0;
|
|
359
299
|
let dist = Infinity;
|
|
360
300
|
for (let i = 0; i < positions.length; i++) {
|
|
@@ -369,23 +309,26 @@ const Sheet = withStaticProperties(themeable(forwardRef(function Sheet2(props, r
|
|
|
369
309
|
animateTo(closestPoint);
|
|
370
310
|
};
|
|
371
311
|
const finish = (_e, state) => {
|
|
372
|
-
release(
|
|
312
|
+
release({
|
|
313
|
+
vy: state.vy,
|
|
314
|
+
dragAt: state.dy
|
|
315
|
+
});
|
|
373
316
|
};
|
|
374
317
|
let previouslyScrolling = false;
|
|
375
318
|
const onMoveShouldSet = (_e, { dy }) => {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
}
|
|
381
|
-
if (scrollBridge.y === 0 && dy < 0) {
|
|
382
|
-
return false;
|
|
383
|
-
}
|
|
319
|
+
const isScrolled = scrollBridge.y !== 0;
|
|
320
|
+
if (isScrolled) {
|
|
321
|
+
previouslyScrolling = true;
|
|
322
|
+
return false;
|
|
384
323
|
}
|
|
385
324
|
if (previouslyScrolling) {
|
|
386
325
|
previouslyScrolling = false;
|
|
387
326
|
return true;
|
|
388
327
|
}
|
|
328
|
+
const isDraggingUp = dy < 0;
|
|
329
|
+
if (!isScrolled && isDraggingUp) {
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
389
332
|
return Math.abs(dy) > 8;
|
|
390
333
|
};
|
|
391
334
|
const grant = () => {
|
|
@@ -394,24 +337,24 @@ const Sheet = withStaticProperties(themeable(forwardRef(function Sheet2(props, r
|
|
|
394
337
|
startY = at.current;
|
|
395
338
|
};
|
|
396
339
|
let isExternalDrag = false;
|
|
340
|
+
function setPositionValue(next) {
|
|
341
|
+
pos.setValue(next);
|
|
342
|
+
}
|
|
397
343
|
scrollBridge.drag = (dy) => {
|
|
398
344
|
if (!isExternalDrag) {
|
|
399
345
|
isExternalDrag = true;
|
|
400
346
|
grant();
|
|
401
347
|
}
|
|
402
348
|
const to = dy + startY;
|
|
403
|
-
|
|
349
|
+
setPositionValue(resisted(to, minY));
|
|
404
350
|
};
|
|
405
351
|
scrollBridge.release = release;
|
|
406
352
|
return PanResponder.create({
|
|
407
|
-
onMoveShouldSetPanResponder:
|
|
408
|
-
const res = onMoveShouldSet(...args);
|
|
409
|
-
return res;
|
|
410
|
-
},
|
|
353
|
+
onMoveShouldSetPanResponder: onMoveShouldSet,
|
|
411
354
|
onPanResponderGrant: grant,
|
|
412
355
|
onPanResponderMove: (_e, { dy }) => {
|
|
413
356
|
const to = dy + startY;
|
|
414
|
-
|
|
357
|
+
setPositionValue(resisted(to, minY));
|
|
415
358
|
},
|
|
416
359
|
onPanResponderEnd: finish,
|
|
417
360
|
onPanResponderTerminate: finish,
|
|
@@ -450,7 +393,6 @@ const Sheet = withStaticProperties(themeable(forwardRef(function Sheet2(props, r
|
|
|
450
393
|
contentRef,
|
|
451
394
|
dismissOnOverlayPress,
|
|
452
395
|
dismissOnSnapToBottom,
|
|
453
|
-
allowPinchZoom,
|
|
454
396
|
open,
|
|
455
397
|
hidden: isHidden,
|
|
456
398
|
scope: __scopeSheet,
|
|
@@ -459,7 +401,7 @@ const Sheet = withStaticProperties(themeable(forwardRef(function Sheet2(props, r
|
|
|
459
401
|
setPosition,
|
|
460
402
|
setOpen,
|
|
461
403
|
scrollBridge
|
|
462
|
-
}, isResizing ? null : overlayComponent,
|
|
404
|
+
}, isResizing ? null : overlayComponent, /* @__PURE__ */ React.createElement(Animated.View, {
|
|
463
405
|
ref,
|
|
464
406
|
...panResponder == null ? void 0 : panResponder.panHandlers,
|
|
465
407
|
onLayout: (e) => {
|
|
@@ -478,7 +420,7 @@ const Sheet = withStaticProperties(themeable(forwardRef(function Sheet2(props, r
|
|
|
478
420
|
height: "100%",
|
|
479
421
|
transform: [{ translateY }]
|
|
480
422
|
}
|
|
481
|
-
}, isResizing ? null : frameComponent));
|
|
423
|
+
}, handleComponent, isResizing ? null : frameComponent));
|
|
482
424
|
if (modal) {
|
|
483
425
|
return /* @__PURE__ */ React.createElement(Portal, null, /* @__PURE__ */ React.createElement(Theme, {
|
|
484
426
|
name: themeName
|
|
@@ -538,7 +480,6 @@ export {
|
|
|
538
480
|
SheetHandleFrame,
|
|
539
481
|
SheetOverlay,
|
|
540
482
|
SheetOverlayFrame,
|
|
541
|
-
SheetScrollView,
|
|
542
483
|
createSheetScope
|
|
543
484
|
};
|
|
544
485
|
//# sourceMappingURL=Sheet.js.map
|