Skip to content

Commit

Permalink
fix: occur unset for idle state #917
Browse files Browse the repository at this point in the history
  • Loading branch information
daybrush committed May 16, 2023
1 parent 875fc19 commit a9d1de8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/react-moveable/src/MoveableGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,8 @@ class MoveableGroup extends MoveableManager<GroupableProps> {
const isTargetChanged = added.length || removed.length;

if (isTargetChanged || prevTarget !== nextTarget) {
unset(this, "targetGesto");
unset(this, "controlGesto");
unset(this, false);
unset(this, true);
this.updateState({ gestos: {} });
}
if (prevTarget !== nextTarget) {
Expand Down
8 changes: 4 additions & 4 deletions packages/react-moveable/src/MoveableManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ export default class MoveableManager<T = {}>
if (viewContainer) {
this._changeAbleViewClassNames([]);
}
unset(this, "targetGesto");
unset(this, "controlGesto");
unset(this, false);
unset(this, true);

const events = this.events;
for (const name in events) {
Expand Down Expand Up @@ -924,11 +924,11 @@ export default class MoveableManager<T = {}>
|| this._isTargetChanged(true);

if (isUnset) {
unset(this, "targetGesto");
unset(this, false);
this.updateState({ gestos: {} });
}
if (!hasControlAble) {
unset(this, "controlGesto");
unset(this, true);
}

if (target && hasTargetAble && !this.targetGesto) {
Expand Down
14 changes: 11 additions & 3 deletions packages/react-moveable/src/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -989,9 +989,17 @@ export function roundSign(num: number) {
return Math.round(num % 1 === -0.5 ? num - 1 : num);
}

export function unset(self: any, name: string) {
self[name]?.unset();
self[name] = null;
export function unset(self: MoveableManagerInterface, isControl: boolean) {
const gestoName = isControl ? "controlGesto" : "targetGesto";
const gesto = self[gestoName];

if (gesto?.isIdle() === false) {
self[isControl ? "controlAbles" : "targetAbles"].forEach(able => {
able.unset && able.unset(self);
});
}
gesto?.unset();
self[gestoName] = null as any;
}

export function fillCSSObject(style: Record<string, any>, resolvedEvent?: any): CSSObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ export default function App() {
ref={moveableRef}
draggable={true}
target={targets}
onClickGroup={() => {
if (targets.length === 2) {
setTargets([".cube1", ".cube2", ".cube3"]);
} else if (targets.length === 3) {
setTargets([".cube1", ".cube2", ".cube3", ".cube4"]);
}
onDragGroupStart={() => {
requestAnimationFrame(() => {
if (targets.length === 2) {
setTargets([".cube1", ".cube2", ".cube3"]);
} else if (targets.length === 3) {
setTargets([".cube1", ".cube2", ".cube3", ".cube4"]);
}
});
}}
onDrag={e => {
e.target.style.cssText += e.cssText;
Expand Down

0 comments on commit a9d1de8

Please sign in to comment.