@trackunit/react-drawer 1.7.78 → 1.7.80
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/index.cjs.js +8 -9
- package/index.esm.js +9 -10
- package/package.json +6 -6
package/index.cjs.js
CHANGED
|
@@ -361,7 +361,7 @@ const useSwipeHandlers = ({ ref, closingThreshold, onCloseGesture, onOpenGesture
|
|
|
361
361
|
const [dragDistance, setDragDistance] = react.useState(0);
|
|
362
362
|
const currentY = react.useRef(0);
|
|
363
363
|
const [currentHeight, setCurrentHeight] = react.useState(0);
|
|
364
|
-
const geometry = reactComponents.
|
|
364
|
+
const geometry = reactComponents.useMeasureElement(ref);
|
|
365
365
|
const [threshold, setThreshold] = react.useState(0);
|
|
366
366
|
react.useEffect(() => {
|
|
367
367
|
setThreshold(currentHeight * closingThreshold);
|
|
@@ -369,7 +369,7 @@ const useSwipeHandlers = ({ ref, closingThreshold, onCloseGesture, onOpenGesture
|
|
|
369
369
|
const handlers = reactSwipeable.useSwipeable({
|
|
370
370
|
onTouchStartOrOnMouseDown: () => {
|
|
371
371
|
const y = getElementYTranslation(ref.current);
|
|
372
|
-
const height = geometry
|
|
372
|
+
const height = geometry?.height ?? 0;
|
|
373
373
|
currentY.current = y;
|
|
374
374
|
setCurrentHeight(height);
|
|
375
375
|
setDragDistance(y);
|
|
@@ -434,8 +434,7 @@ const SNAP_POINT_TRANSITION = "transform 500ms cubic-bezier(0.32,0.72,0,1)";
|
|
|
434
434
|
*/
|
|
435
435
|
const SwipeableDrawer = ({ open, onClose, onOpenGesture, onSnapPointChange, children, keepMountedWhenClosed, className, position = "bottom", snapPoints, activeSnapPoint: activeSnapPointProp = null, container, ref, ...others }) => {
|
|
436
436
|
const drawerRef = react.useRef(null);
|
|
437
|
-
const
|
|
438
|
-
const containerGeometry = reactComponents.useGeometry(containerRef);
|
|
437
|
+
const { geometry: containerGeometry, ref: containerMeasureRef } = reactComponents.useMeasure();
|
|
439
438
|
react.useImperativeHandle(ref, () => drawerRef.current);
|
|
440
439
|
const [activeSnapPoint, setActiveSnapPoint] = react.useState(activeSnapPointProp);
|
|
441
440
|
const [snapPointOffsets, setSnapPointOffsets] = react.useState([]);
|
|
@@ -452,7 +451,7 @@ const SwipeableDrawer = ({ open, onClose, onOpenGesture, onSnapPointChange, chil
|
|
|
452
451
|
}
|
|
453
452
|
const direction = draggedBy > 0 ? -1 : 1;
|
|
454
453
|
// If the velocity is greater than the threshold and the dragged distance is less than 40% of the container height, snap to the next snap point
|
|
455
|
-
if (velocity > VELOCITY_THRESHOLD && Math.abs(draggedBy) < containerGeometry
|
|
454
|
+
if (velocity > VELOCITY_THRESHOLD && Math.abs(draggedBy) < (containerGeometry?.height ?? 0) * 0.4) {
|
|
456
455
|
const newSnapPoint = snapPoints[activeSnapPointIndex + direction] ?? null;
|
|
457
456
|
if (newSnapPoint) {
|
|
458
457
|
setActiveSnapPoint(newSnapPoint);
|
|
@@ -507,7 +506,7 @@ const SwipeableDrawer = ({ open, onClose, onOpenGesture, onSnapPointChange, chil
|
|
|
507
506
|
if (!snapPoints || !drawerRef.current) {
|
|
508
507
|
return;
|
|
509
508
|
}
|
|
510
|
-
const containerSize =
|
|
509
|
+
const containerSize = containerGeometry && containerGeometry.height > 0 ? containerGeometry.height : window.innerHeight;
|
|
511
510
|
const newSnapPointOffsets = snapPoints.map(snapPoint => {
|
|
512
511
|
// If snapPoint is a number, it is a percentage of the container size
|
|
513
512
|
if (typeof snapPoint === "number") {
|
|
@@ -521,12 +520,12 @@ const SwipeableDrawer = ({ open, onClose, onOpenGesture, onSnapPointChange, chil
|
|
|
521
520
|
return 0;
|
|
522
521
|
});
|
|
523
522
|
setSnapPointOffsets(newSnapPointOffsets);
|
|
524
|
-
}, [snapPoints, drawerRef,
|
|
523
|
+
}, [snapPoints, drawerRef, containerGeometry]);
|
|
525
524
|
react.useEffect(() => {
|
|
526
525
|
if (container) {
|
|
527
|
-
|
|
526
|
+
containerMeasureRef(container);
|
|
528
527
|
}
|
|
529
|
-
}, [container]);
|
|
528
|
+
}, [container, containerMeasureRef]);
|
|
530
529
|
react.useEffect(() => {
|
|
531
530
|
if (!snapPoints || snapPoints.length === 0) {
|
|
532
531
|
return;
|
package/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import { registerTranslations } from '@trackunit/i18n-library-translation';
|
|
3
|
-
import { useViewportBreakpoints, Portal, Icon,
|
|
3
|
+
import { useViewportBreakpoints, Portal, Icon, useMeasureElement, useMeasure } from '@trackunit/react-components';
|
|
4
4
|
import { useEffect, useState, useCallback, useRef, useImperativeHandle, useMemo } from 'react';
|
|
5
5
|
import { cvaMerge } from '@trackunit/css-class-variance-utilities';
|
|
6
6
|
import { useSwipeable } from 'react-swipeable';
|
|
@@ -359,7 +359,7 @@ const useSwipeHandlers = ({ ref, closingThreshold, onCloseGesture, onOpenGesture
|
|
|
359
359
|
const [dragDistance, setDragDistance] = useState(0);
|
|
360
360
|
const currentY = useRef(0);
|
|
361
361
|
const [currentHeight, setCurrentHeight] = useState(0);
|
|
362
|
-
const geometry =
|
|
362
|
+
const geometry = useMeasureElement(ref);
|
|
363
363
|
const [threshold, setThreshold] = useState(0);
|
|
364
364
|
useEffect(() => {
|
|
365
365
|
setThreshold(currentHeight * closingThreshold);
|
|
@@ -367,7 +367,7 @@ const useSwipeHandlers = ({ ref, closingThreshold, onCloseGesture, onOpenGesture
|
|
|
367
367
|
const handlers = useSwipeable({
|
|
368
368
|
onTouchStartOrOnMouseDown: () => {
|
|
369
369
|
const y = getElementYTranslation(ref.current);
|
|
370
|
-
const height = geometry
|
|
370
|
+
const height = geometry?.height ?? 0;
|
|
371
371
|
currentY.current = y;
|
|
372
372
|
setCurrentHeight(height);
|
|
373
373
|
setDragDistance(y);
|
|
@@ -432,8 +432,7 @@ const SNAP_POINT_TRANSITION = "transform 500ms cubic-bezier(0.32,0.72,0,1)";
|
|
|
432
432
|
*/
|
|
433
433
|
const SwipeableDrawer = ({ open, onClose, onOpenGesture, onSnapPointChange, children, keepMountedWhenClosed, className, position = "bottom", snapPoints, activeSnapPoint: activeSnapPointProp = null, container, ref, ...others }) => {
|
|
434
434
|
const drawerRef = useRef(null);
|
|
435
|
-
const
|
|
436
|
-
const containerGeometry = useGeometry(containerRef);
|
|
435
|
+
const { geometry: containerGeometry, ref: containerMeasureRef } = useMeasure();
|
|
437
436
|
useImperativeHandle(ref, () => drawerRef.current);
|
|
438
437
|
const [activeSnapPoint, setActiveSnapPoint] = useState(activeSnapPointProp);
|
|
439
438
|
const [snapPointOffsets, setSnapPointOffsets] = useState([]);
|
|
@@ -450,7 +449,7 @@ const SwipeableDrawer = ({ open, onClose, onOpenGesture, onSnapPointChange, chil
|
|
|
450
449
|
}
|
|
451
450
|
const direction = draggedBy > 0 ? -1 : 1;
|
|
452
451
|
// If the velocity is greater than the threshold and the dragged distance is less than 40% of the container height, snap to the next snap point
|
|
453
|
-
if (velocity > VELOCITY_THRESHOLD && Math.abs(draggedBy) < containerGeometry
|
|
452
|
+
if (velocity > VELOCITY_THRESHOLD && Math.abs(draggedBy) < (containerGeometry?.height ?? 0) * 0.4) {
|
|
454
453
|
const newSnapPoint = snapPoints[activeSnapPointIndex + direction] ?? null;
|
|
455
454
|
if (newSnapPoint) {
|
|
456
455
|
setActiveSnapPoint(newSnapPoint);
|
|
@@ -505,7 +504,7 @@ const SwipeableDrawer = ({ open, onClose, onOpenGesture, onSnapPointChange, chil
|
|
|
505
504
|
if (!snapPoints || !drawerRef.current) {
|
|
506
505
|
return;
|
|
507
506
|
}
|
|
508
|
-
const containerSize =
|
|
507
|
+
const containerSize = containerGeometry && containerGeometry.height > 0 ? containerGeometry.height : window.innerHeight;
|
|
509
508
|
const newSnapPointOffsets = snapPoints.map(snapPoint => {
|
|
510
509
|
// If snapPoint is a number, it is a percentage of the container size
|
|
511
510
|
if (typeof snapPoint === "number") {
|
|
@@ -519,12 +518,12 @@ const SwipeableDrawer = ({ open, onClose, onOpenGesture, onSnapPointChange, chil
|
|
|
519
518
|
return 0;
|
|
520
519
|
});
|
|
521
520
|
setSnapPointOffsets(newSnapPointOffsets);
|
|
522
|
-
}, [snapPoints, drawerRef,
|
|
521
|
+
}, [snapPoints, drawerRef, containerGeometry]);
|
|
523
522
|
useEffect(() => {
|
|
524
523
|
if (container) {
|
|
525
|
-
|
|
524
|
+
containerMeasureRef(container);
|
|
526
525
|
}
|
|
527
|
-
}, [container]);
|
|
526
|
+
}, [container, containerMeasureRef]);
|
|
528
527
|
useEffect(() => {
|
|
529
528
|
if (!snapPoints || snapPoints.length === 0) {
|
|
530
529
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-drawer",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.80",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"react": "19.0.0",
|
|
11
11
|
"react-swipeable": "^7.0.1",
|
|
12
|
-
"@trackunit/react-components": "1.10.
|
|
13
|
-
"@trackunit/css-class-variance-utilities": "1.7.
|
|
14
|
-
"@trackunit/ui-icons": "1.7.
|
|
15
|
-
"@trackunit/i18n-library-translation": "1.7.
|
|
16
|
-
"@trackunit/react-test-setup": "1.4.
|
|
12
|
+
"@trackunit/react-components": "1.10.20",
|
|
13
|
+
"@trackunit/css-class-variance-utilities": "1.7.52",
|
|
14
|
+
"@trackunit/ui-icons": "1.7.53",
|
|
15
|
+
"@trackunit/i18n-library-translation": "1.7.64",
|
|
16
|
+
"@trackunit/react-test-setup": "1.4.52"
|
|
17
17
|
},
|
|
18
18
|
"module": "./index.esm.js",
|
|
19
19
|
"main": "./index.cjs.js",
|