Skip to content

Commit

Permalink
feat: add isFirstDrag property on drag event #796
Browse files Browse the repository at this point in the history
  • Loading branch information
daybrush committed Nov 23, 2022
1 parent c8209e0 commit 7ade6a2
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"@scena/matrix": "^1.1.1",
"css-to-mat": "^1.0.3",
"framework-utils": "^1.1.0",
"gesto": "^1.13.4",
"gesto": "^1.14.0",
"overlap-area": "^1.1.0",
"react-compat-css-styled": "^1.0.9",
"react-css-styled": "^1.0.4"
Expand All @@ -126,7 +126,7 @@
"@scena/matrix": "^1.1.1",
"css-to-mat": "^1.0.3",
"framework-utils": "^1.1.0",
"gesto": "^1.13.4",
"gesto": "^1.14.0",
"overlap-area": "^1.1.0",
"react-compat-css-styled": "^1.0.9",
"react-css-styled": "^1.0.4"
Expand Down
2 changes: 1 addition & 1 deletion packages/react-compat-moveable/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"@scena/matrix": "^1.1.1",
"css-to-mat": "^1.0.3",
"framework-utils": "^1.1.0",
"gesto": "^1.13.4",
"gesto": "^1.14.0",
"overlap-area": "^1.1.0",
"react-compat-css-styled": "^1.0.9",
"react-css-styled": "^1.0.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-moveable/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"@scena/matrix": "^1.1.1",
"css-to-mat": "^1.0.3",
"framework-utils": "^1.1.0",
"gesto": "^1.13.4",
"gesto": "^1.14.0",
"overlap-area": "^1.1.0",
"react-css-styled": "^1.0.4"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export default class CustomGesto {
public move(delta: number[], inputEvent: any): OnCustomDrag {
let clientX!: number;
let clientY!: number;
let isFirstDrag = false;

if (!this.isFlag) {
this.prevX = delta[0];
this.prevY = delta[1];
Expand All @@ -72,12 +74,18 @@ export default class CustomGesto {

this.isFlag = true;
} else {
const isPrevDrag = this.isDrag;

clientX = this.prevX + delta[0];
clientY = this.prevY + delta[1];

if (delta[0] || delta[1]) {
this.isDrag = true;
}

if (!isPrevDrag && this.isDrag) {
isFirstDrag = true;
}
}

this.prevX = clientX;
Expand All @@ -88,6 +96,7 @@ export default class CustomGesto {
clientX,
clientY,
inputEvent,
isFirstDrag,
isDrag: this.isDrag,
distX: clientX - this.startX,
distY: clientY - this.startY,
Expand Down
5 changes: 5 additions & 0 deletions packages/react-moveable/src/react-moveable/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,10 @@ export interface OnEvent {
* The vertical coordinate within the application's client area at which the event occurred.
*/
clientY: number;
/**
* Whether this is the first drag in the drag event
*/
isFirstDrag: number;
/**
* Objects that can send information to the following events.
*/
Expand Down Expand Up @@ -2727,6 +2731,7 @@ export interface OnCustomDrag extends GestoTypes.Position {
type: string;
inputEvent: any;
isDrag: boolean;
isFirstDrag: boolean;
datas: IObject<any>;
originalDatas: IObject<any>;
parentEvent: boolean;
Expand Down
2 changes: 2 additions & 0 deletions packages/react-moveable/src/react-moveable/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,7 @@ export function fillParams<T extends IObject<any>>(
currentTarget: moveable,
moveable,
datas: datas.datas,
isFirstDrag: !!e.isFirstDrag,
stopDrag() {
e.stop?.();
},
Expand Down Expand Up @@ -1012,6 +1013,7 @@ export function fillEndParams<T extends IObject<any>>(
lastEvent: datas.lastEvent,
isDouble: e.isDouble,
datas: datas.datas,
isFirstDrag: !!e.isFirstDrag,
} as any;
}
export function catchEvent<EventName extends keyof Props, Props extends IObject<any> = MoveableProps>(
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13360,10 +13360,10 @@ gensync@^1.0.0-beta.1, gensync@^1.0.0-beta.2:
resolved "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz"
integrity sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==

gesto@^1.13.1, gesto@^1.13.4, gesto@^1.3.0, gesto@^1.5.1:
version "1.13.4"
resolved "https://registry.npmjs.org/gesto/-/gesto-1.13.4.tgz#5f53608dfac589e21acd2b905f51fb259f15a77f"
integrity sha512-TkXGgv8nC/IIjOO2dMrgCNovSnuRfPTJybmtwponzGihCje8QgLEdMf+h/RERu6O+wq8FZTSJ6ihIO9ytt4/Qg==
gesto@^1.13.1, gesto@^1.14.0, gesto@^1.3.0, gesto@^1.5.1:
version "1.14.0"
resolved "https://registry.npmjs.org/gesto/-/gesto-1.14.0.tgz#cb50213f80bf5a1ce5af1dd2bba7c3bb5338dfbc"
integrity sha512-b89RyxAQb65t0HVJHPWi1+Ren66QoMaXpV5do3k7LRJAwunESYlJr520/4pNrMQGUkqopLMZjEceUE2uBqcgeQ==
dependencies:
"@daybrush/utils" "^1.7.1"
"@scena/event-emitter" "^1.0.2"
Expand Down

0 comments on commit 7ade6a2

Please sign in to comment.