refac
This commit is contained in:
1 parent
49aab7451c
commit
ddc886fdc1
1 file changed
+15
-1
@@ -67,6 +67,15 @@
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const hasTextSelection = () => {
|
||||||
|
if (typeof window === 'undefined') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const selection = window.getSelection();
|
||||||
|
return !!selection && !selection.isCollapsed;
|
||||||
|
};
|
||||||
|
|
||||||
const canScrollHorizontally = (target: EventTarget | null, dx: number) => {
|
const canScrollHorizontally = (target: EventTarget | null, dx: number) => {
|
||||||
if (!(target instanceof Element) || dx === 0 || typeof window === 'undefined') {
|
if (!(target instanceof Element) || dx === 0 || typeof window === 'undefined') {
|
||||||
return false;
|
return false;
|
||||||
@@ -161,7 +170,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onTouchStart = (e: TouchEvent) => {
|
const onTouchStart = (e: TouchEvent) => {
|
||||||
if (!enabled || e.touches.length !== 1 || shouldSkipSwipe(e.target)) {
|
if (!enabled || e.touches.length !== 1 || shouldSkipSwipe(e.target) || hasTextSelection()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,6 +214,11 @@
|
|||||||
const absY = Math.abs(dy);
|
const absY = Math.abs(dy);
|
||||||
|
|
||||||
if (!locked) {
|
if (!locked) {
|
||||||
|
if (hasTextSelection()) {
|
||||||
|
cancelSwipe();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ((direction === 'open' && dx > 0) || (direction === 'close' && dx < 0)) {
|
if ((direction === 'open' && dx > 0) || (direction === 'close' && dx < 0)) {
|
||||||
swipeProgress = Math.max(0, Math.min(1, startProgress + dx / panelWidth));
|
swipeProgress = Math.max(0, Math.min(1, startProgress + dx / panelWidth));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user