@lodev09/react-native-true-sheet 3.10.0 → 3.11.0-beta.0
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/android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt +11 -4
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewController.kt +10 -5
- package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetStackManager.kt +2 -5
- package/lib/module/TrueSheet.js +3 -0
- package/lib/module/TrueSheet.js.map +1 -1
- package/lib/module/TrueSheet.web.js +604 -376
- package/lib/module/TrueSheet.web.js.map +1 -1
- package/lib/module/TrueSheetProvider.js.map +1 -1
- package/lib/module/TrueSheetProvider.web.js +141 -100
- package/lib/module/TrueSheetProvider.web.js.map +1 -1
- package/lib/module/mocks/index.js.map +1 -1
- package/lib/module/reanimated/ReanimatedTrueSheet.web.js.map +1 -1
- package/lib/module/reanimated/useReanimatedPositionChangeHandler.web.js +2 -3
- package/lib/module/reanimated/useReanimatedPositionChangeHandler.web.js.map +1 -1
- package/lib/module/web/constants.js +16 -0
- package/lib/module/web/constants.js.map +1 -0
- package/lib/module/web/vaul/README.md +9 -0
- package/lib/module/web/vaul/browser.js +30 -0
- package/lib/module/web/vaul/browser.js.map +1 -0
- package/lib/module/web/vaul/constants.js +14 -0
- package/lib/module/web/vaul/constants.js.map +1 -0
- package/lib/module/web/vaul/context.js +57 -0
- package/lib/module/web/vaul/context.js.map +1 -0
- package/lib/module/web/vaul/helpers.js +93 -0
- package/lib/module/web/vaul/helpers.js.map +1 -0
- package/lib/module/web/vaul/index.js +1206 -0
- package/lib/module/web/vaul/index.js.map +1 -0
- package/lib/module/web/vaul/style.css +264 -0
- package/lib/module/web/vaul/types.js +2 -0
- package/lib/module/web/vaul/types.js.map +1 -0
- package/lib/module/web/vaul/use-composed-refs.js +34 -0
- package/lib/module/web/vaul/use-composed-refs.js.map +1 -0
- package/lib/module/web/vaul/use-controllable-state.js +54 -0
- package/lib/module/web/vaul/use-controllable-state.js.map +1 -0
- package/lib/module/web/vaul/use-position-fixed.js +123 -0
- package/lib/module/web/vaul/use-position-fixed.js.map +1 -0
- package/lib/module/web/vaul/use-prevent-scroll.js +258 -0
- package/lib/module/web/vaul/use-prevent-scroll.js.map +1 -0
- package/lib/module/web/vaul/use-scale-background.js +57 -0
- package/lib/module/web/vaul/use-scale-background.js.map +1 -0
- package/lib/module/web/vaul/use-snap-points.js +294 -0
- package/lib/module/web/vaul/use-snap-points.js.map +1 -0
- package/lib/typescript/src/TrueSheet.d.ts +2 -2
- package/lib/typescript/src/TrueSheet.d.ts.map +1 -1
- package/lib/typescript/src/TrueSheet.types.d.ts +79 -36
- package/lib/typescript/src/TrueSheet.types.d.ts.map +1 -1
- package/lib/typescript/src/TrueSheet.web.d.ts +3 -11
- package/lib/typescript/src/TrueSheet.web.d.ts.map +1 -1
- package/lib/typescript/src/TrueSheetProvider.d.ts +2 -2
- package/lib/typescript/src/TrueSheetProvider.d.ts.map +1 -1
- package/lib/typescript/src/TrueSheetProvider.web.d.ts +17 -14
- package/lib/typescript/src/TrueSheetProvider.web.d.ts.map +1 -1
- package/lib/typescript/src/mocks/index.d.ts +1 -2
- package/lib/typescript/src/mocks/index.d.ts.map +1 -1
- package/lib/typescript/src/navigation/types.d.ts +1 -1
- package/lib/typescript/src/navigation/types.d.ts.map +1 -1
- package/lib/typescript/src/reanimated/ReanimatedTrueSheet.web.d.ts +0 -1
- package/lib/typescript/src/reanimated/ReanimatedTrueSheet.web.d.ts.map +1 -1
- package/lib/typescript/src/reanimated/useReanimatedPositionChangeHandler.web.d.ts +2 -3
- package/lib/typescript/src/reanimated/useReanimatedPositionChangeHandler.web.d.ts.map +1 -1
- package/lib/typescript/src/web/constants.d.ts +14 -0
- package/lib/typescript/src/web/constants.d.ts.map +1 -0
- package/lib/typescript/src/web/vaul/browser.d.ts +8 -0
- package/lib/typescript/src/web/vaul/browser.d.ts.map +1 -0
- package/lib/typescript/src/web/vaul/constants.d.ts +12 -0
- package/lib/typescript/src/web/vaul/constants.d.ts.map +1 -0
- package/lib/typescript/src/web/vaul/context.d.ts +45 -0
- package/lib/typescript/src/web/vaul/context.d.ts.map +1 -0
- package/lib/typescript/src/web/vaul/helpers.d.ts +17 -0
- package/lib/typescript/src/web/vaul/helpers.d.ts.map +1 -0
- package/lib/typescript/src/web/vaul/index.d.ts +210 -0
- package/lib/typescript/src/web/vaul/index.d.ts.map +1 -0
- package/lib/typescript/src/web/vaul/types.d.ts +7 -0
- package/lib/typescript/src/web/vaul/types.d.ts.map +1 -0
- package/lib/typescript/src/web/vaul/use-composed-refs.d.ts +14 -0
- package/lib/typescript/src/web/vaul/use-composed-refs.d.ts.map +1 -0
- package/lib/typescript/src/web/vaul/use-controllable-state.d.ts +9 -0
- package/lib/typescript/src/web/vaul/use-controllable-state.d.ts.map +1 -0
- package/lib/typescript/src/web/vaul/use-position-fixed.d.ts +19 -0
- package/lib/typescript/src/web/vaul/use-position-fixed.d.ts.map +1 -0
- package/lib/typescript/src/web/vaul/use-prevent-scroll.d.ts +18 -0
- package/lib/typescript/src/web/vaul/use-prevent-scroll.d.ts.map +1 -0
- package/lib/typescript/src/web/vaul/use-scale-background.d.ts +2 -0
- package/lib/typescript/src/web/vaul/use-scale-background.d.ts.map +1 -0
- package/lib/typescript/src/web/vaul/use-snap-points.d.ts +37 -0
- package/lib/typescript/src/web/vaul/use-snap-points.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/TrueSheet.tsx +9 -1
- package/src/TrueSheet.types.ts +88 -38
- package/src/TrueSheet.web.tsx +675 -450
- package/src/TrueSheetProvider.tsx +2 -4
- package/src/TrueSheetProvider.web.tsx +193 -125
- package/src/mocks/index.ts +1 -2
- package/src/navigation/types.ts +0 -1
- package/src/reanimated/ReanimatedTrueSheet.web.tsx +0 -1
- package/src/reanimated/useReanimatedPositionChangeHandler.web.ts +2 -3
- package/src/web/constants.ts +13 -0
- package/src/web/vaul/README.md +9 -0
- package/src/web/vaul/browser.ts +38 -0
- package/src/web/vaul/constants.ts +18 -0
- package/src/web/vaul/context.ts +87 -0
- package/src/web/vaul/helpers.ts +124 -0
- package/src/web/vaul/index.tsx +1590 -0
- package/src/web/vaul/style.css +264 -0
- package/src/web/vaul/types.ts +7 -0
- package/src/web/vaul/use-composed-refs.ts +35 -0
- package/src/web/vaul/use-controllable-state.ts +66 -0
- package/src/web/vaul/use-position-fixed.ts +147 -0
- package/src/web/vaul/use-prevent-scroll.ts +309 -0
- package/src/web/vaul/use-scale-background.ts +64 -0
- package/src/web/vaul/use-snap-points.ts +433 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { AnyFunction, DrawerDirection } from './types';
|
|
2
|
+
|
|
3
|
+
interface Style {
|
|
4
|
+
[key: string]: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const cache = new WeakMap();
|
|
8
|
+
|
|
9
|
+
export function isInView(el: HTMLElement): boolean {
|
|
10
|
+
const rect = el.getBoundingClientRect();
|
|
11
|
+
|
|
12
|
+
if (!window.visualViewport) return false;
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
rect.top >= 0 &&
|
|
16
|
+
rect.left >= 0 &&
|
|
17
|
+
// Need + 40 for safari detection
|
|
18
|
+
rect.bottom <= window.visualViewport.height - 40 &&
|
|
19
|
+
rect.right <= window.visualViewport.width
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function set(
|
|
24
|
+
el: Element | HTMLElement | null | undefined,
|
|
25
|
+
styles: Style,
|
|
26
|
+
ignoreCache = false
|
|
27
|
+
) {
|
|
28
|
+
if (!el || !(el instanceof HTMLElement)) return;
|
|
29
|
+
let originalStyles: Style = {};
|
|
30
|
+
|
|
31
|
+
Object.entries(styles).forEach(([key, value]: [string, string]) => {
|
|
32
|
+
if (key.startsWith('--')) {
|
|
33
|
+
el.style.setProperty(key, value);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
originalStyles[key] = (el.style as any)[key];
|
|
38
|
+
(el.style as any)[key] = value;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
if (ignoreCache) return;
|
|
42
|
+
|
|
43
|
+
cache.set(el, originalStyles);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function reset(el: Element | HTMLElement | null, prop?: string) {
|
|
47
|
+
if (!el || !(el instanceof HTMLElement)) return;
|
|
48
|
+
let originalStyles = cache.get(el);
|
|
49
|
+
|
|
50
|
+
if (!originalStyles) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (prop) {
|
|
55
|
+
(el.style as any)[prop] = originalStyles[prop];
|
|
56
|
+
} else {
|
|
57
|
+
Object.entries(originalStyles).forEach(([key, value]) => {
|
|
58
|
+
(el.style as any)[key] = value;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const isVertical = (direction: DrawerDirection) => {
|
|
64
|
+
switch (direction) {
|
|
65
|
+
case 'top':
|
|
66
|
+
case 'bottom':
|
|
67
|
+
return true;
|
|
68
|
+
case 'left':
|
|
69
|
+
case 'right':
|
|
70
|
+
return false;
|
|
71
|
+
default:
|
|
72
|
+
return direction satisfies never;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export function getTranslate(element: HTMLElement, direction: DrawerDirection): number | null {
|
|
77
|
+
if (!element) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
const style = window.getComputedStyle(element);
|
|
81
|
+
const transform =
|
|
82
|
+
// @ts-ignore
|
|
83
|
+
style.transform || style.webkitTransform || style.mozTransform;
|
|
84
|
+
let mat = transform.match(/^matrix3d\((.+)\)$/);
|
|
85
|
+
if (mat) {
|
|
86
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix3d
|
|
87
|
+
return parseFloat(mat[1].split(', ')[isVertical(direction) ? 13 : 12]);
|
|
88
|
+
}
|
|
89
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix
|
|
90
|
+
mat = transform.match(/^matrix\((.+)\)$/);
|
|
91
|
+
return mat ? parseFloat(mat[1].split(', ')[isVertical(direction) ? 5 : 4]) : null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function dampenValue(v: number) {
|
|
95
|
+
return 8 * (Math.log(v + 1) - 2);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function assignStyle(
|
|
99
|
+
element: HTMLElement | null | undefined,
|
|
100
|
+
style: Partial<CSSStyleDeclaration>
|
|
101
|
+
) {
|
|
102
|
+
if (!element) return () => {};
|
|
103
|
+
|
|
104
|
+
const prevStyle = element.style.cssText;
|
|
105
|
+
Object.assign(element.style, style);
|
|
106
|
+
|
|
107
|
+
return () => {
|
|
108
|
+
element.style.cssText = prevStyle;
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Receives functions as arguments and returns a new function that calls all.
|
|
114
|
+
*/
|
|
115
|
+
export function chain<T>(...fns: T[]) {
|
|
116
|
+
return (...args: T extends AnyFunction ? Parameters<T> : never) => {
|
|
117
|
+
for (const fn of fns) {
|
|
118
|
+
if (typeof fn === 'function') {
|
|
119
|
+
// @ts-ignore
|
|
120
|
+
fn(...args);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|