Skip to content

Commit 089466e

Browse files
authored
Merge branch '@akwasniewski/native-detector-web' into @akwasniewski/v3-web-typing
2 parents 8579092 + 4d916f5 commit 089466e

File tree

5 files changed

+18
-15
lines changed

5 files changed

+18
-15
lines changed

packages/react-native-gesture-handler/src/v3/HostGestureDetector.web.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useRef, useCallback } from 'react';
1+
import { useEffect, useRef } from 'react';
22
import { View } from 'react-native';
33
import RNGestureHandlerModule from '../RNGestureHandlerModule.web';
44
import { ActionType } from '../ActionType';
@@ -17,13 +17,13 @@ const HostGestureDetector = (props: GestureHandlerDetectorProps) => {
1717
const propsRef = useRef<PropsRef>(props);
1818
const attachedHandlerTags = useRef<Set<number>>(new Set<number>());
1919

20-
const detachHandlers = useCallback((oldHandlerTags: Set<number>) => {
20+
const detachHandlers = (oldHandlerTags: Set<number>) => {
2121
oldHandlerTags.forEach((tag) => {
2222
RNGestureHandlerModule.detachGestureHandler(tag);
2323
});
24-
}, []);
24+
};
2525

26-
const attachHandlers = useCallback((currentHandlerTags: Set<number>) => {
26+
const attachHandlers = (currentHandlerTags: Set<number>) => {
2727
const oldHandlerTags =
2828
attachedHandlerTags.current.difference(currentHandlerTags);
2929
const newHandlerTags = currentHandlerTags.difference(
@@ -41,7 +41,7 @@ const HostGestureDetector = (props: GestureHandlerDetectorProps) => {
4141
);
4242
});
4343
attachedHandlerTags.current = currentHandlerTags;
44-
}, []);
44+
};
4545

4646
useEffect(() => {
4747
attachHandlers(new Set(handlerTags));

packages/react-native-gesture-handler/src/web/handlers/GestureHandler.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default abstract class GestureHandler implements IGestureHandler {
3131
private _enabled = false;
3232

3333
private viewRef: number | null = null;
34-
protected propsRef: React.RefObject<PropsRef> | null = null;
34+
private propsRef: React.RefObject<PropsRef> | null = null;
3535
private actionType: ActionType | null = null;
3636
private forAnimated: boolean | null = null;
3737
private _handlerTag!: number;
@@ -363,7 +363,7 @@ export default abstract class GestureHandler implements IGestureHandler {
363363
}
364364
this.ensurePropsRef();
365365
const { onGestureHandlerEvent, onGestureHandlerTouchEvent }: PropsRef =
366-
this.propsRef.current;
366+
this.propsRef!.current;
367367

368368
const touchEvent: ResultEvent | undefined = this.transformTouchEvent(event);
369369

@@ -389,7 +389,7 @@ export default abstract class GestureHandler implements IGestureHandler {
389389
onGestureHandlerEvent,
390390
onGestureHandlerStateChange,
391391
onGestureHandlerAnimatedEvent,
392-
}: PropsRef = this.propsRef.current;
392+
}: PropsRef = this.propsRef!.current;
393393
const resultEvent: ResultEvent = this.transformEventData(
394394
newState,
395395
oldState
@@ -578,14 +578,12 @@ export default abstract class GestureHandler implements IGestureHandler {
578578
timeStamp: Date.now(),
579579
};
580580

581-
const { onGestureHandlerEvent }: PropsRef = this.propsRef.current;
581+
const { onGestureHandlerEvent }: PropsRef = this.propsRef!.current;
582582

583583
invokeNullableMethod(onGestureHandlerEvent, cancelEvent);
584584
}
585585

586-
protected ensurePropsRef(): asserts this is this & {
587-
propsRef: React.RefObject<PropsRef>;
588-
} {
586+
protected ensurePropsRef(): void {
589587
if (!this.propsRef) {
590588
throw new Error(
591589
tagMessage('Cannot handle event when component props are null')

packages/react-native-gesture-handler/src/web/handlers/NativeViewGestureHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default class NativeViewGestureHandler extends GestureHandler {
4545
if (this.config.disallowInterruption !== undefined) {
4646
this.disallowInterruption = this.config.disallowInterruption;
4747
}
48-
if (this.delegate.isInitialized) {
48+
if (this.delegate.initialized) {
4949
// this function is called on handler creation, which happens before initializing delegate
5050
const view = this.delegate.view as HTMLElement;
5151
this.restoreViewStyles(view);

packages/react-native-gesture-handler/src/web/tools/GestureHandlerDelegate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface MeasureResult {
88
}
99

1010
export interface GestureHandlerDelegate<TComponent, THandler> {
11-
isInitialized: boolean;
11+
readonly initialized: boolean;
1212
view: TComponent;
1313

1414
init(viewRef: number, handler: THandler): void;

packages/react-native-gesture-handler/src/web/tools/GestureHandlerWebDelegate.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ interface DefaultViewStyles {
2222
export class GestureHandlerWebDelegate
2323
implements GestureHandlerDelegate<HTMLElement, IGestureHandler>
2424
{
25-
public isInitialized = false;
25+
private isInitialized = false;
2626
private _view: HTMLElement | null = null;
2727

2828
private gestureHandler!: IGestureHandler;
@@ -240,7 +240,12 @@ export class GestureHandlerWebDelegate
240240

241241
return this._view;
242242
}
243+
243244
public set view(value: HTMLElement) {
244245
this._view = value;
245246
}
247+
248+
get initialized(): boolean {
249+
return this.isInitialized;
250+
}
246251
}

0 commit comments

Comments
 (0)