Skip to content

Commit

Permalink
fix(month-view): add 1px drag sensitivity
Browse files Browse the repository at this point in the history
Fixes #1012
  • Loading branch information
mattlewis92 committed Jun 27, 2019
1 parent f7ad18d commit 4a0e581
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { isInside } from './util';
import { isInside, isWithinThreshold } from './util';
import { ValidateDragParams } from 'angular-draggable-droppable';

const DRAG_THRESHOLD = 1;

export class CalendarDragHelper {
private readonly startPosition: ClientRect;

Expand All @@ -26,9 +24,6 @@ export class CalendarDragHelper {
dragAlreadyMoved: boolean;
transform: ValidateDragParams['transform'];
}): boolean {
const isWithinThreshold =
Math.abs(x) > DRAG_THRESHOLD || Math.abs(y) > DRAG_THRESHOLD;

if (snapDraggedEvents) {
const newRect: ClientRect = Object.assign({}, this.startPosition, {
left: this.startPosition.left + transform.x,
Expand All @@ -38,11 +33,11 @@ export class CalendarDragHelper {
});

return (
(isWithinThreshold || dragAlreadyMoved) &&
(isWithinThreshold({ x, y }) || dragAlreadyMoved) &&
isInside(this.dragContainerElement.getBoundingClientRect(), newRect)
);
} else {
return isWithinThreshold || dragAlreadyMoved;
return isWithinThreshold({ x, y }) || dragAlreadyMoved;
}
}
}
5 changes: 5 additions & 0 deletions projects/angular-calendar/src/modules/common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,8 @@ export function getWeekViewPeriod(
return { viewStart, viewEnd };
}
}

export function isWithinThreshold({ x, y }: { x: number; y: number }) {
const DRAG_THRESHOLD = 1;
return Math.abs(x) > DRAG_THRESHOLD || Math.abs(y) > DRAG_THRESHOLD;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
TemplateRef
} from '@angular/core';
import { MonthViewDay, CalendarEvent } from 'calendar-utils';
import { trackByEventId } from '../common/util';
import { isWithinThreshold, trackByEventId } from '../common/util';
import { PlacementArray } from 'positioning';

@Component({
Expand All @@ -25,6 +25,7 @@ import { PlacementArray } from 'positioning';
let-tooltipAppendToBody="tooltipAppendToBody"
let-tooltipDelay="tooltipDelay"
let-trackByEventId="trackByEventId"
let-validateDrag="validateDrag"
>
<div class="cal-cell-top">
<span class="cal-day-badge" *ngIf="day.badgeTotal > 0">{{
Expand Down Expand Up @@ -55,6 +56,7 @@ import { PlacementArray } from 'positioning';
dragActiveClass="cal-drag-active"
[dropData]="{ event: event, draggedFrom: day }"
[dragAxis]="{ x: event.draggable, y: event.draggable }"
[validateDrag]="validateDrag"
(mwlClick)="eventClicked.emit({ event: event })"
></div>
</div>
Expand All @@ -72,7 +74,8 @@ import { PlacementArray } from 'positioning';
tooltipTemplate: tooltipTemplate,
tooltipAppendToBody: tooltipAppendToBody,
tooltipDelay: tooltipDelay,
trackByEventId: trackByEventId
trackByEventId: trackByEventId,
validateDrag: validateDrag
}"
>
</ng-template>
Expand Down Expand Up @@ -117,4 +120,6 @@ export class CalendarMonthCellComponent {
}>();

trackByEventId = trackByEventId;

validateDrag = isWithinThreshold;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
AnimationTriggerMetadata
} from '@angular/animations';
import { CalendarEvent } from 'calendar-utils';
import { trackByEventId } from '../common/util';
import { isWithinThreshold, trackByEventId } from '../common/util';

export const collapseAnimation: AnimationTriggerMetadata = trigger('collapse', [
transition('void => *', [
Expand All @@ -35,6 +35,7 @@ export const collapseAnimation: AnimationTriggerMetadata = trigger('collapse', [
let-eventClicked="eventClicked"
let-isOpen="isOpen"
let-trackByEventId="trackByEventId"
let-validateDrag="validateDrag"
>
<div class="cal-open-day-events" [@collapse] *ngIf="isOpen">
<div
Expand All @@ -45,6 +46,7 @@ export const collapseAnimation: AnimationTriggerMetadata = trigger('collapse', [
dragActiveClass="cal-drag-active"
[dropData]="{ event: event }"
[dragAxis]="{ x: event.draggable, y: event.draggable }"
[validateDrag]="validateDrag"
>
<span
class="cal-event"
Expand Down Expand Up @@ -74,7 +76,8 @@ export const collapseAnimation: AnimationTriggerMetadata = trigger('collapse', [
events: events,
eventClicked: eventClicked,
isOpen: isOpen,
trackByEventId: trackByEventId
trackByEventId: trackByEventId,
validateDrag: validateDrag
}"
>
</ng-template>
Expand All @@ -98,4 +101,6 @@ export class CalendarOpenDayEventsComponent {
}>();

trackByEventId = trackByEventId;

validateDrag = isWithinThreshold;
}

3 comments on commit 4a0e581

@GIOkafor
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattlewis92 Can you also implement this for the week and day views, seems like the threshold for those are too low still. Thanks again for the great work.

@mattlewis92
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It already is implemented for the week and day views: https://github.com/mattlewis92/angular-calendar/blob/master/projects/angular-calendar/src/modules/week/calendar-week-view.component.ts#L155 It was only the month view that was missing it

@GIOkafor
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome thanks

Please sign in to comment.