Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Web] Migrate to get and set #3263

Merged
merged 7 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/RNGestureHandlerModule.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
handlerTag,
new GestureClass(new GestureHandlerWebDelegate())
);
InteractionManager.getInstance().configureInteractions(
InteractionManager.instance.configureInteractions(
NodeManager.getHandler(handlerTag),
config as unknown as Config
);
Expand All @@ -63,12 +63,11 @@
}

// @ts-ignore Types should be HTMLElement or React.Component
NodeManager.getHandler(handlerTag).init(newView, propsRef);

Check warning on line 66 in src/RNGestureHandlerModule.web.ts

View workflow job for this annotation

GitHub Actions / check

Unsafe call of an `any` typed value
},
updateGestureHandler(handlerTag: number, newConfig: Config) {
NodeManager.getHandler(handlerTag).updateGestureConfig(newConfig);

InteractionManager.getInstance().configureInteractions(
InteractionManager.instance.configureInteractions(
NodeManager.getHandler(handlerTag),
newConfig
);
Expand Down
39 changes: 24 additions & 15 deletions src/web/detectors/RotationGestureDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export default class RotationGestureDetector
private previousTime = 0;

private previousAngle = 0;
private rotation = 0;
private _rotation = 0;
latekvo marked this conversation as resolved.
Show resolved Hide resolved

private anchorX = 0;
private anchorY = 0;
private _anchorX = 0;
private _anchorY = 0;

private isInProgress = false;

Expand Down Expand Up @@ -85,7 +85,7 @@ export default class RotationGestureDetector
return;
}

const pointerIDs: IterableIterator<number> = tracker.getData().keys();
const pointerIDs: IterableIterator<number> = tracker.trackedPointers.keys();

this.keyPointers[0] = pointerIDs.next().value as number;
this.keyPointers[1] = pointerIDs.next().value as number;
Expand Down Expand Up @@ -143,24 +143,33 @@ export default class RotationGestureDetector
return true;
}

public getTimeDelta(): number {
return this.currentTime + this.previousTime;
public reset(): void {
this.keyPointers = [NaN, NaN];
this.isInProgress = false;
}

public getAnchorX(): number {
return this.anchorX;
public get anchorX() {
return this._anchorX;
}
private set anchorX(value: number) {
this._anchorX = value;
}
j-piasecki marked this conversation as resolved.
Show resolved Hide resolved

public getAnchorY(): number {
return this.anchorY;
public get anchorY() {
return this._anchorY;
}
private set anchorY(value: number) {
this._anchorY = value;
}

public getRotation(): number {
return this.rotation;
public get rotation() {
return this._rotation;
}
private set rotation(value: number) {
this._rotation = value;
}

public reset(): void {
this.keyPointers = [NaN, NaN];
this.isInProgress = false;
public get timeDelta() {
return this.currentTime + this.previousTime;
}
}
47 changes: 28 additions & 19 deletions src/web/detectors/ScaleGestureDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export default class ScaleGestureDetector implements ScaleGestureListener {
public onScale: (detector: ScaleGestureDetector) => boolean;
public onScaleEnd: (detector: ScaleGestureDetector) => void;

private focusX!: number;
private focusY!: number;
private _focusX!: number;
private _focusY!: number;

private currentSpan!: number;
private _currentSpan!: number;
private prevSpan!: number;
private initialSpan!: number;

Expand All @@ -42,7 +42,7 @@ export default class ScaleGestureDetector implements ScaleGestureListener {
this.currentTime = event.time;

const action: EventTypes = event.eventType;
const numOfPointers = tracker.getTrackedPointersCount();
const numOfPointers = tracker.trackedPointersCount;

const streamComplete: boolean =
action === EventTypes.UP ||
Expand Down Expand Up @@ -86,7 +86,7 @@ export default class ScaleGestureDetector implements ScaleGestureListener {
let devSumX = 0;
let devSumY = 0;

tracker.getData().forEach((value, key) => {
tracker.trackedPointers.forEach((value, key) => {
if (key === ignoredPointer) {
return;
}
Expand Down Expand Up @@ -145,27 +145,36 @@ export default class ScaleGestureDetector implements ScaleGestureListener {
return true;
}

public getCurrentSpan(): number {
return this.currentSpan;
}
public calculateScaleFactor(numOfPointers: number): number {
if (numOfPointers < 2) {
return 1;
}

public getFocusX(): number {
return this.focusX;
return this.prevSpan > 0 ? this.currentSpan / this.prevSpan : 1;
}
latekvo marked this conversation as resolved.
Show resolved Hide resolved

public getFocusY(): number {
return this.focusY;
public get currentSpan() {
return this._currentSpan;
}
private set currentSpan(value: number) {
this._currentSpan = value;
}

public getTimeDelta(): number {
return this.currentTime - this.prevTime;
public get focusX() {
return this._focusX;
}
private set focusX(value: number) {
this._focusX = value;
}

public getScaleFactor(numOfPointers: number): number {
if (numOfPointers < 2) {
return 1;
}
public get focusY() {
return this._focusY;
}
private set focusY(value: number) {
this._focusY = value;
}

return this.prevSpan > 0 ? this.currentSpan / this.prevSpan : 1;
public get timeDelta() {
return this.currentTime - this.prevTime;
}
}
13 changes: 6 additions & 7 deletions src/web/handlers/FlingGestureHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,29 +125,28 @@ export default class FlingGestureHandler extends GestureHandler {
}

private newPointerAction(): void {
if (this.currentState === State.UNDETERMINED) {
if (this.state === State.UNDETERMINED) {
this.startFling();
}

if (this.currentState !== State.BEGAN) {
if (this.state !== State.BEGAN) {
return;
}

this.tryEndFling();

if (
this.tracker.getTrackedPointersCount() >
this.maxNumberOfPointersSimultaneously
this.tracker.trackedPointersCount > this.maxNumberOfPointersSimultaneously
) {
this.maxNumberOfPointersSimultaneously =
this.tracker.getTrackedPointersCount();
this.tracker.trackedPointersCount;
}
}

private pointerMoveAction(event: AdaptedEvent): void {
this.tracker.track(event);

if (this.currentState !== State.BEGAN) {
if (this.state !== State.BEGAN) {
return;
}

Expand Down Expand Up @@ -177,7 +176,7 @@ export default class FlingGestureHandler extends GestureHandler {
}

private onUp(event: AdaptedEvent): void {
if (this.currentState === State.BEGAN) {
if (this.state === State.BEGAN) {
this.endFling();
}

Expand Down
Loading
Loading