Skip to content

Commit

Permalink
BackHandler: specify function return type for handler (#28192)
Browse files Browse the repository at this point in the history
Summary:
Following the comment DefinitelyTyped/DefinitelyTyped#42618 (comment)

Modify the flowtype of BackHandler function to have more specific return type.

## Changelog

[General] [Changed] - Changed type of BackHandler to be more specific.
Pull Request resolved: #28192

Test Plan: No flow error in RNTester

Reviewed By: TheSavior

Differential Revision: D20771113

Pulled By: hramos

fbshipit-source-id: 5ca65e2a2b3f8726b8fb4606473d8fad5b0ce730
  • Loading branch information
Naturalclar authored and facebook-github-bot committed Apr 23, 2020
1 parent 4d9fa4b commit a903d1b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions Libraries/Utilities/BackHandler.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ type TBackHandler = {|
+exitApp: () => void,
+addEventListener: (
eventName: BackPressEventName,
handler: Function,
handler: () => ?boolean,
) => {remove: () => void, ...},
+removeEventListener: (
eventName: BackPressEventName,
handler: Function,
handler: () => ?boolean,
) => void,
|};
const BackHandler: TBackHandler = {
Expand All @@ -87,7 +87,7 @@ const BackHandler: TBackHandler = {
*/
addEventListener: function(
eventName: BackPressEventName,
handler: Function,
handler: () => ?boolean,
): {remove: () => void, ...} {
if (_backPressSubscriptions.indexOf(handler) === -1) {
_backPressSubscriptions.push(handler);
Expand All @@ -102,7 +102,7 @@ const BackHandler: TBackHandler = {
*/
removeEventListener: function(
eventName: BackPressEventName,
handler: Function,
handler: () => ?boolean,
): void {
if (_backPressSubscriptions.indexOf(handler) !== -1) {
_backPressSubscriptions.splice(
Expand Down
8 changes: 4 additions & 4 deletions Libraries/Utilities/BackHandler.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ type TBackHandler = {|
+exitApp: () => void,
+addEventListener: (
eventName: BackPressEventName,
handler: Function,
handler: () => ?boolean,
) => {remove: () => void, ...},
+removeEventListener: (
eventName: BackPressEventName,
handler: Function,
handler: () => ?boolean,
) => void,
|};

Expand Down Expand Up @@ -93,7 +93,7 @@ if (Platform.isTV) {

addEventListener: function(
eventName: BackPressEventName,
handler: Function,
handler: () => ?boolean,
): {remove: () => void, ...} {
_backPressSubscriptions.add(handler);
return {
Expand All @@ -103,7 +103,7 @@ if (Platform.isTV) {

removeEventListener: function(
eventName: BackPressEventName,
handler: Function,
handler: () => ?boolean,
): void {
_backPressSubscriptions.delete(handler);
},
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Utilities/__mocks__/BackHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const BackHandler = {

addEventListener: function(
eventName: BackPressEventName,
handler: Function,
handler: () => ?boolean,
): {remove: () => void} {
_backPressSubscriptions.add(handler);
return {
Expand All @@ -26,7 +26,7 @@ const BackHandler = {

removeEventListener: function(
eventName: BackPressEventName,
handler: Function,
handler: () => ?boolean,
): void {
_backPressSubscriptions.delete(handler);
},
Expand Down

0 comments on commit a903d1b

Please sign in to comment.