Skip to content

Commit b0d384d

Browse files
committed
type predicate using protected props ref
1 parent 686fadd commit b0d384d

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

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

Lines changed: 5 additions & 6 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-
private propsRef: React.RefObject<PropsRef> | null = null;
34+
protected propsRef: React.RefObject<PropsRef> | null = null;
3535
private actionType: ActionType | null = null;
3636
private forAnimated: boolean | null = null;
3737
private _handlerTag!: number;
@@ -365,7 +365,7 @@ export default abstract class GestureHandler implements IGestureHandler {
365365
}
366366
this.ensurePropsRef();
367367
const { onGestureHandlerEvent, onGestureHandlerTouchEvent }: PropsRef =
368-
this.propsRef!.current;
368+
this.propsRef.current;
369369

370370
const touchEvent: ResultTouchEvent | undefined =
371371
this.transformTouchEvent(event);
@@ -392,7 +392,7 @@ export default abstract class GestureHandler implements IGestureHandler {
392392
onGestureHandlerEvent,
393393
onGestureHandlerStateChange,
394394
onGestureHandlerAnimatedEvent,
395-
}: PropsRef = this.propsRef!.current;
395+
}: PropsRef = this.propsRef.current;
396396
const resultEvent: ResultEvent = this.transformEventData(
397397
newState,
398398
oldState
@@ -582,20 +582,19 @@ export default abstract class GestureHandler implements IGestureHandler {
582582
timeStamp: Date.now(),
583583
};
584584

585-
const { onGestureHandlerEvent }: PropsRef = this.propsRef!.current;
585+
const { onGestureHandlerEvent }: PropsRef = this.propsRef.current;
586586

587587
invokeNullableMethod(onGestureHandlerEvent, cancelEvent);
588588
}
589589

590-
protected ensurePropsRef(): this is this & {
590+
protected ensurePropsRef(): asserts this is this & {
591591
propsRef: React.RefObject<PropsRef>;
592592
} {
593593
if (!this.propsRef) {
594594
throw new Error(
595595
tagMessage('Cannot handle event when component props are null')
596596
);
597597
}
598-
return true;
599598
}
600599

601600
protected transformNativeEvent(): Record<string, unknown> {

0 commit comments

Comments
 (0)