Skip to content

Commit 3f1ff42

Browse files
akwasniewskij-piasecki
authored andcommitted
[Web] fixed repeated listener registration (#3626)
## Description On web, In `EventManagers`, the `registerListeners` was called twice for each handler of a `Button` ## Test plan * Add a console.log to both `registerListners()` and `unregisterListeners()` in `web/tools/KeyboardEventManager` (or any other event manager) * Observe logs in the `Web styles reset` example in the example app
1 parent 74c2f5e commit 3f1ff42

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,9 +566,12 @@ export default abstract class GestureHandler implements IGestureHandler {
566566

567567
public updateGestureConfig({ enabled = true, ...props }: Config): void {
568568
this._config = { enabled: enabled, ...props };
569-
this.enabled = enabled;
570569

571-
this.delegate.onEnabledChange(enabled);
570+
if (this.enabled !== enabled) {
571+
this.delegate.onEnabledChange(enabled);
572+
}
573+
574+
this.enabled = enabled;
572575

573576
if (this.config.shouldCancelWhenOutside !== undefined) {
574577
this.shouldCancelWhenOutside = this.config.shouldCancelWhenOutside;

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,6 @@ export class GestureHandlerWebDelegate
174174

175175
if (enabled) {
176176
this.eventManagers.forEach((manager) => {
177-
// It may look like managers will be registered twice when handler is mounted for the first time.
178-
// However, `init` method is called AFTER `updateGestureConfig` - it means that delegate has not
179-
// been initialized yet, so this code won't be executed.
180-
//
181-
// Also, because we use defined functions, not lambdas, they will not be registered multiple times.
182177
manager.registerListeners();
183178
});
184179
} else {

0 commit comments

Comments
 (0)