[TIMOB-19919] Android: add ability to listen to androidback without overriding
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2016-06-27T08:00:59.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 6.0.0 |
Components | Android |
Labels | Community, breaking-change |
Reporter | Manuel Lehner |
Assignee | Ashraf Abu |
Created | 2015-04-23T11:48:37.000+0000 |
Updated | 2017-07-31T18:58:08.000+0000 |
Description
Currently it is possible to override the default behavior for the back button. But you can't really use this for enhancing this functionality or just listen to the back button event without overriding it.
There is no way to call super.onBackPressed() from on the windows activity from JavaScript side.
I think it would make sense to add another property to the Ti.UI.Window that lets you explicitly override this behavior. I'd prefer this:
var win = Ti.UI.createWindow();
win.onBack = function(){
// explicitly override back button behavior
};
win.addEventListener('androidback', function(){
// just listen for the event without influencing the default behavior
});
Does that make sense?
The reason why I need this is that I'm trying to create a proper navigation history. As there are no more lightweight windows, I want to implement a kind of backstack for Views or Fragments.
PR: https://github.com/appcelerator/titanium_mobile/pull/6859
PR merged.
Please note: *this is a breaking change!*
win.addEventListener('androidback', onBack);
will behave different than before. Apps using this to override the back-button need to update their code.[~manuellehner] Thanks for the heads up. Will get this out of 5.4.0 (aka current Master) and get it merged back when we do 6.0.0. Will be reverting it right now and leave this ticket as opened.
PR to revert this for 5.4.0 https://github.com/appcelerator/titanium_mobile/pull/7780 (Merged)
Note for when adding this back into 6.0.0: Add docs.
I'm not sure I see the use case for this. You can already accomplish custom back button behavior while supporting the stock handling of windows (activities) using code like the following.
PR to get this in https://github.com/appcelerator/titanium_mobile/pull/8087
Pr merged
Test case is as described in original description.
Verified the improvement. Closing. Environment: Appc Studio : 4.7.0.201607250649 Ti SDK : 6.0.0.v20160811221444 Ti CLI : 5.0.9 Alloy : 1.9.1 MAC El Capitan : 10.11.6 Appc NPM : 4.2.7 Appc CLI : 6.0.0-24 Node: 4.4.4 Nexus 5 - Android 6.0.1
This does not work for Tabgroup.