Skip to content

Commit 5ce35bb

Browse files
chore: address review feedback for pinch zoom
Co-authored-by: siarheihuzarevich <[email protected]>
1 parent 0f7416e commit 5ce35bb

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

projects/f-flow/src/f-zoom/f-zoom.directive.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ import { EFZoomDirection } from './e-f-zoom-direction';
3333
import { EventExtensions } from '../drag-toolkit';
3434

3535
const PINCH_NORMALIZATION_FACTOR = 100;
36+
const PINCH_MOVEMENT_THRESHOLD = 0.5;
37+
const NORMALIZED_MIN = 0.1;
38+
const NORMALIZED_MAX = 1;
3639

3740
@Directive({
3841
selector: 'f-canvas[fZoom]',
@@ -144,7 +147,7 @@ export class FZoomDirective extends FZoomBase implements OnInit, AfterViewInit,
144147

145148
private _normalizeWheelStep(deltaY: number): number {
146149
const intensity = Math.abs(deltaY) / 100;
147-
const normalized = Math.max(0.1, Math.min(intensity, 1));
150+
const normalized = Math.max(NORMALIZED_MIN, Math.min(intensity, NORMALIZED_MAX));
148151

149152
return this.step * normalized;
150153
}
@@ -164,7 +167,7 @@ export class FZoomDirective extends FZoomBase implements OnInit, AfterViewInit,
164167
};
165168

166169
private _onTouchMove = (event: TouchEvent) => {
167-
if (event.touches.length !== 2 || this._pinchDistance == null) {
170+
if (event.touches.length !== 2 || this._pinchDistance === null) {
168171
return;
169172
}
170173

@@ -176,7 +179,7 @@ export class FZoomDirective extends FZoomBase implements OnInit, AfterViewInit,
176179

177180
const currentDistance = this._getTouchDistance(event.touches);
178181
const delta = currentDistance - this._pinchDistance;
179-
if (Math.abs(delta) < 0.5) {
182+
if (Math.abs(delta) < PINCH_MOVEMENT_THRESHOLD) {
180183
return;
181184
}
182185

@@ -244,7 +247,7 @@ export class FZoomDirective extends FZoomBase implements OnInit, AfterViewInit,
244247

245248
private _normalizePinchStep(delta: number): number {
246249
const intensity = Math.abs(delta) / PINCH_NORMALIZATION_FACTOR;
247-
const normalized = Math.max(0.1, Math.min(intensity, 1));
250+
const normalized = Math.max(NORMALIZED_MIN, Math.min(intensity, NORMALIZED_MAX));
248251

249252
return this.step * normalized;
250253
}

0 commit comments

Comments
 (0)