Skip to content

Commit 2ba5ae8

Browse files
committed
native gesture bugfix
1 parent b0d384d commit 2ba5ae8

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ export default class NativeViewGestureHandler extends GestureHandler {
4646
if (this.config.disallowInterruption !== undefined) {
4747
this.disallowInterruption = this.config.disallowInterruption;
4848
}
49-
50-
const view = this.delegate.view as HTMLElement;
51-
this.restoreViewStyles(view);
49+
if (this.delegate.isInitialized) {
50+
// this function is called on handler creation, which happens before initializing delegate
51+
const view = this.delegate.view as HTMLElement;
52+
this.restoreViewStyles(view);
53+
}
5254
}
5355

5456
private restoreViewStyles(view: HTMLElement) {

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

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

1010
export interface GestureHandlerDelegate<TComponent, THandler> {
11+
isInitialized: boolean;
1112
view: TComponent;
1213

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

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Config } from '../interfaces';
1212
import { MouseButton } from '../../handlers/gestureHandlerCommon';
1313
import KeyboardEventManager from './KeyboardEventManager';
1414
import WheelEventManager from './WheelEventManager';
15+
import { tagMessage } from '../../utils';
1516

1617
interface DefaultViewStyles {
1718
userSelect: string;
@@ -21,7 +22,7 @@ interface DefaultViewStyles {
2122
export class GestureHandlerWebDelegate
2223
implements GestureHandlerDelegate<HTMLElement, IGestureHandler>
2324
{
24-
private isInitialized = false;
25+
public isInitialized = false;
2526
private _view: HTMLElement | null = null;
2627

2728
private gestureHandler!: IGestureHandler;
@@ -233,7 +234,11 @@ export class GestureHandlerWebDelegate
233234
}
234235

235236
public get view() {
236-
return this._view!;
237+
if (!this._view) {
238+
throw new Error(tagMessage("component's view is null"));
239+
}
240+
241+
return this._view;
237242
}
238243
public set view(value: HTMLElement) {
239244
this._view = value;

0 commit comments

Comments
 (0)