Skip to content

Commit

Permalink
(AppState) fix removeEventListener adding another listener when type …
Browse files Browse the repository at this point in the history
…is blur or focus (#33491)

Summary:
I noticed the `AppState.removeEventListener` was in fact calling `addListener` instead of `removeListener` when type is blur or focus.

I know this method is deprecated but it can't hurt to fix it.

## Changelog

[General] [Fixed] - AppState.removeEventListener correctly removes listener for blur and focus events

Pull Request resolved: #33491

Test Plan: I've thought about adding a unit test, but it isn't that easy since AppState is mocked and the method is deprecated so I don't think it is worth investing too much for it.

Reviewed By: cortinico

Differential Revision: D35139808

Pulled By: GijsWeterings

fbshipit-source-id: 9d8ba157db3a62ea53759e1246f483182faf12f1
  • Loading branch information
AntoineDoubovetzky authored and facebook-github-bot committed Mar 25, 2022
1 parent 8237ff2 commit 9aab25e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Libraries/AppState/AppState.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class AppState {
case 'focus':
// $FlowIssue[invalid-tuple-arity] Flow cannot refine handler based on the event type
// $FlowIssue[incompatible-call]
emitter.addListener('appStateFocusChange', listener);
emitter.removeListener('appStateFocusChange', listener);
return;
}
throw new Error('Trying to unsubscribe from unknown event: ' + type);
Expand Down

0 comments on commit 9aab25e

Please sign in to comment.