react-native/Libraries/Utilities
Christoph Jerolimov c3e42b5531 Fix that BackHandler was not called on Android (#19077)
Summary:
This fixes issues #18954 and #15497

The transformation from Set to (an reversed) Array does not work on Android devices when the remote debugging was started with `react-native run-android`.

<!--
  Required: Write your motivation here.
  If this PR fixes an issue, type "Fixes #issueNumber" to automatically close the issue when the PR is merged.
-->

Add the following code to your App.js and run the app with `react-native run-android` in an Android device:

```
  componentDidMount() {
    BackHandler.addEventListener('hardwareBackPress', () => {
      console.warn('Callback called. Do not close app. Do nothing at all.');
      return true; // Do not close the app.
    });
  }
```

After adding this, the app should NOT close when you press the back button. Without this fix, the app closes (which is the default behaviour).

See also the comments from Victoriayangx in #18954 and #15497.

<!--
  Does this PR require a documentation change?
  Create a PR at https://github.com/facebook/react-native-website and add a link to it here.
-->

<!--
  Required.
  Help reviewers and the release process by writing your own release notes. See below for an example.
-->

[ANDROID] [BUGFIX] [BackHandler] - Fix that BackHandler was not called on Android

<!--
  **INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.**

    CATEGORY
  [----------]      TYPE
  [ CLI      ] [-------------]    LOCATION
  [ DOCS     ] [ BREAKING    ] [-------------]
  [ GENERAL  ] [ BUGFIX      ] [ {Component} ]
  [ INTERNAL ] [ ENHANCEMENT ] [ {Filename}  ]
  [ IOS      ] [ FEATURE     ] [ {Directory} ]   |-----------|
  [ ANDROID  ] [ MINOR       ] [ {Framework} ] - | {Message} |
  [----------] [-------------] [-------------]   |-----------|

 EXAMPLES:

 [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things
 [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput
 [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with
 [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word
 [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position
 [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see
-->
Pull Request resolved: https://github.com/facebook/react-native/pull/19077

Reviewed By: yns88

Differential Revision: D9692298

Pulled By: hramos

fbshipit-source-id: 4526b07a4924055ebc9c42e02615c27aa5c97fbb
2018-09-07 10:26:20 -07:00
..
__mocks__ Prettier React Native Libraries 2018-05-10 19:10:38 -07:00
__tests__ Modified deepFreezeAndThrowOnMutationInDev to use Object.prototype.ha… (#19598) 2018-06-07 02:44:27 -07:00
differ Prettier React Native Libraries 2018-05-10 19:10:38 -07:00
BackAndroid.js Prettier React Native Libraries 2018-05-10 19:10:38 -07:00
BackHandler.android.js Fix that BackHandler was not called on Android (#19077) 2018-09-07 10:26:20 -07:00
BackHandler.ios.js Switch to Platform.isTV to pass Android Flow 2018-06-10 13:45:57 -07:00
DeviceInfo.js Adding flow strict local to remaining possible files in xplat/JS 2018-08-09 08:54:44 -07:00
Dimensions.js Prettier React Native Libraries 2018-05-10 19:10:38 -07:00
HMRClient.js Remove @providesModule from all modules 2018-04-25 07:37:10 -07:00
HMRLoadingView.android.js Replace '@flow strict(-local)' with '@flow' in .android.js files 2018-08-08 10:48:19 -07:00
HMRLoadingView.ios.js Adding flow strict local to remaining possible files in xplat/JS 2018-08-09 08:54:44 -07:00
HeapCapture.js Adding flow strict local to remaining possible files in xplat/JS 2018-08-09 08:54:44 -07:00
JSDevSupportModule.js Adding flow strict local to remaining possible files in xplat/JS 2018-08-09 08:54:44 -07:00
MatrixMath.js Bump Prettier to 1.13.4 on xplat 2018-06-06 05:32:06 -07:00
PerformanceLogger.js Flow v0.76.0 2018-07-09 08:17:51 -07:00
PixelRatio.js Add to PixelRation documentation information about iPhone SE and iPho… (#20695) 2018-08-20 14:48:40 -07:00
Platform.android.js Replace '@flow strict(-local)' with '@flow' in .android.js files 2018-08-08 10:48:19 -07:00
Platform.ios.js Prettier React Native Libraries 2018-05-10 19:10:38 -07:00
PlatformOS.android.js Replace '@flow strict(-local)' with '@flow' in .android.js files 2018-08-08 10:48:19 -07:00
PlatformOS.ios.js Flow strictify possible files in RN core 2018-06-20 00:47:21 -07:00
PolyfillFunctions.js Remove @providesModule from all modules 2018-04-25 07:37:10 -07:00
RCTLog.js Prettier React Native Libraries 2018-05-10 19:10:38 -07:00
SceneTracker.js Flow strictify possible files in RN core 2018-06-20 00:47:21 -07:00
binaryToBase64.js Prettier React Native Libraries 2018-05-10 19:10:38 -07:00
buildStyleInterpolator.js Prettier React Native Libraries 2018-05-10 19:10:38 -07:00
clamp.js Flow strictify possible files in RN core 2018-06-20 00:47:21 -07:00
createStrictShapeTypeChecker.js Prettier React Native Libraries 2018-05-10 19:10:38 -07:00
deepFreezeAndThrowOnMutationInDev.js Modified deepFreezeAndThrowOnMutationInDev to use Object.prototype.ha… (#19598) 2018-06-07 02:44:27 -07:00
defineLazyObjectProperty.js Prettier React Native Libraries 2018-05-10 19:10:38 -07:00
deprecatedPropType.js Adding flow strict local to remaining possible files in xplat/JS 2018-08-09 08:54:44 -07:00
dismissKeyboard.js Add flow strict-local annotation to the dismissKeyboard module 2018-08-03 11:47:19 -07:00
groupByEveryN.js Flow strictify possible files in RN core 2018-06-20 00:47:21 -07:00
infoLog.js Prettier React Native Libraries 2018-05-10 19:10:38 -07:00
logError.js Flow strictify possible files in RN core 2018-06-20 00:47:21 -07:00
mapWithSeparator.js Flow strictify possible files in RN core 2018-06-20 00:47:21 -07:00
mergeIntoFast.js Prettier React Native Libraries 2018-05-10 19:10:38 -07:00
stringifySafe.js Prettier React Native Libraries 2018-05-10 19:10:38 -07:00
truncate.js Prettier React Native Libraries 2018-05-10 19:10:38 -07:00