Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move BackAndroid -> BackHandler, add Apple TV support for back nav #12571

Closed
wants to merge 20 commits into from

Conversation

douglowder
Copy link
Contributor

Enable back navigation on Apple TV (with the remote's menu button) in code making use of BackAndroid. The module is renamed to BackHandler. BackAndroid is still exported to ReactNative for now, until external projects switch to using the new name for the module. The navigation in https://github.com/react-community/react-navigation makes use of this module.

Test plan: Manual testing with an example app (https://github.com/dlowder-salesforce/react-nav-example).

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Feb 24, 2017
@douglowder
Copy link
Contributor Author

@satya164 @ericvicenti This is a better implementation of back navigation for Apple TV. One feature still missing: when the user is on the bottom of the nav stack, and presses the menu button, Apple TV guidelines require the app to go to background and the tvOS home screen to show. That will require some native changes and a separate PR.

@ericvicenti
Copy link
Contributor

Overall, this seems like a great direction to move in. This is a platform-agnostic concept.

The test plan doesn't mention testing on non-tv platforms, so we'd need to see that tested.

Can we warn people when they use BackAndroid, telling them about the breaking change?

Also the documentation doesn't seem to be affected, but we need to document this change very carefully.

@douglowder
Copy link
Contributor Author

The module is just a stub on iOS - the new functionality is only on tvOS. The Android module is unchanged.

I'd have to think about how we would detect and generate a warning when an application imports BackAndroid instead of BackHandler.

Agreed on the documentation.

@ericvicenti
Copy link
Contributor

For the warning, we can have a BackAndroid as a wrapper module around BackHandler, that warns whenever anything on it is called.

@@ -34,20 +34,29 @@ RCTDeviceEventEmitter.addListener(DEVICE_BACK_EVENT, function() {
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no-trailing-spaces: Trailing spaces not allowed.

* of patent rights can be found in the PATENTS file in the same directory.
*
* On Apple TV, this implements back navigation using the TV remote's menu button.
* On iOS, this just implements a stub.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no-trailing-spaces: Trailing spaces not allowed.


'use strict';

var Platform = require('Platform');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: const

'use strict';

var Platform = require('Platform');
var TVEventHandler = require('TVEventHandler');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: const

var Platform = require('Platform');
var TVEventHandler = require('TVEventHandler');

type BackPressEventName = $Enum<{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering why it's not type BackPressEventName = 'backPress' instead

Also seems all examples say that the event name is hardwareBackPress, while the type says backPress

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's copied from the Android version.

* });
* ```
*/
var BackHandler;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let

* return false;
* });
* ```
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: new line after comment

remove: () => BackHandler.removeEventListener(eventName, handler),
};
},

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unnecessary new line

): void {
_backPressSubscriptions.delete(handler);
},

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unnecessary new line

},

};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unnecessary new lines



} else {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unnecessary new lines

},
removeEventListener: emptyFunction,
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unnecessary new lines

@douglowder
Copy link
Contributor Author

douglowder commented Mar 4, 2017

@sahrens Correct, RefreshControl doesn't have native support on tvOS. Looks like the least intrusive solution is to do the platform check in ScrollView (which has a lot of platform-specific code already). This automatically takes care of all the other components like VirtualizedList that make use of scroll views.

@rozele
Copy link
Contributor

rozele commented Mar 6, 2017

FYI, this will also be a great thing for react-native-windows, since we also use the BackAndroid API.

Copy link
Contributor

@ericvicenti ericvicenti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should probably consolidate the platform-forked files.

I'm excited to land this soon and move away from platform-specific conventions!

'../Libraries/Utilities/BackAndroid.android.js',
'../Libraries/Utilities/BackAndroid.js',
'../Libraries/Utilities/BackHandler.ios.js',
'../Libraries/Utilities/BackHandler.android.js',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this cause there to be 3 separate pages? Lets consolidate it so that all the BackHandler docs are on one page.

Copy link
Contributor Author

@douglowder douglowder Mar 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were only two pages when I tested this, one for BackHandler, and one for BackAndroid to let users know that it is deprecated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, fair enough

@ericvicenti
Copy link
Contributor

Also I think the RefreshControl change should be done separately

@douglowder
Copy link
Contributor Author

Ok I'll back out the RefreshControl change and submit as a separate PR

@facebook-github-bot facebook-github-bot added GH Review: accepted Import Started This pull request has been imported. This does not imply the PR has been approved. and removed GH Review: review-needed labels Mar 7, 2017
@facebook-github-bot
Copy link
Contributor

@ericvicenti has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@douglowder douglowder deleted the tvos-backhandler branch March 9, 2017 15:53
rozele pushed a commit to microsoft/react-native-windows that referenced this pull request May 25, 2017
Summary:
Enable back navigation on Apple TV (with the remote's menu button) in code making use of BackAndroid.  The module is renamed to BackHandler.  BackAndroid is still exported to ReactNative for now, until external projects switch to using the new name for the module.  The navigation in https://github.com/react-community/react-navigation makes use of this module.

**Test plan**: Manual testing with an example app (https://github.com/dlowder-salesforce/react-nav-example).
Closes facebook/react-native#12571

Differential Revision: D4665152

Pulled By: ericvicenti

fbshipit-source-id: 925400ce216379267e014457be6f5eedbe4453ec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Import Started This pull request has been imported. This does not imply the PR has been approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants