From c2cf510ff8fc3ed2558feb85e27a5e4b2d8b8416 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Tue, 2 Aug 2016 18:16:02 -0700 Subject: [PATCH] Improve the BackAndroid example to be more clear Summary: The example of `BackAndroid` caused a bit of confusion for beginners (see #8822), so I thought we should clarify the functionality a bit. I added a comment indicating that a user would have to implement `this.onMainScreen` and `this.goBack` on their own, this was the original problem. Closes https://github.com/facebook/react-native/pull/8829 Differential Revision: D3660332 fbshipit-source-id: d84a29586c6a1a439f386e6b88220d7b0a275129 --- Libraries/Utilities/BackAndroid.android.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Libraries/Utilities/BackAndroid.android.js b/Libraries/Utilities/BackAndroid.android.js index b459e0b5cad..04adcde2515 100644 --- a/Libraries/Utilities/BackAndroid.android.js +++ b/Libraries/Utilities/BackAndroid.android.js @@ -44,13 +44,16 @@ RCTDeviceEventEmitter.addListener(DEVICE_BACK_EVENT, function() { * * Example: * - * ```js + * ```javascript * BackAndroid.addEventListener('hardwareBackPress', function() { - * if (!this.onMainScreen()) { - * this.goBack(); - * return true; - * } - * return false; + * // this.onMainScreen and this.goBack are just examples, you need to use your own implementation here + * // Typically you would use the navigator here to go to the last state. + * + * if (!this.onMainScreen()) { + * this.goBack(); + * return true; + * } + * return false; * }); * ``` */