[TIMOB-25522] iOS: Expose navigation-window instance property to Ti.UI.Window
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2018-05-21T12:14:00.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 7.3.0 |
Components | iOS |
Labels | demo_app |
Reporter | Hans Knöchel |
Assignee | Hans Knöchel |
Created | 2017-11-16T13:05:24.000+0000 |
Updated | 2018-06-12T17:28:10.000+0000 |
Description
In a production app, there are many cases where the developer would like to know the navigation-window context he/she is currently in. For example, when going through a set of windows to select a configuration, the developer calls "openWindow(nextWindow)) to open the next window ("push it") into the current context.
Right now, developers either store a global reference, e.g.
Alloy.Globals.navWindow = nav;
-> [BAD]
or pass the navigation-window to each new window being created, e.g.
Alloy.createController('nextWindow', {
navigationWindow: nav
});
-> [BAD]
I am proposing a solution where the developer can reference the current navigation-window using the "navigationWindow" instance property. See the following test-case for an example:
var win = Ti.UI.createWindow({
backgroundColor: '#fff'
});
var nav = Ti.UI.iOS.createNavigationWindow({
window: win
});
var btn = Ti.UI.createButton({
title: 'Open next window'
});
btn.addEventListener('click', function() {
win.navigationWindow.openWindow(Ti.UI.createWindow({
title: 'Next Window!',
backgroundColor: 'green'
}));
});
win.add(btn);
nav.open();
While the developer could still just use the "nav" property, it will get more complex when using a multi-level application which scope changes during the navigation-flow. Ideally, once we move the navigation-window to the universal Ti.UI.NavigationWindow
namespace, we could expose the same for Android (cc [~jquick]) and Windows (cc [~kiguchi]).
Requirements of this API:
* Return existing references only, no copies
* Make the property read-only
* Only return a navigation-window if one exists, error else
I would think we could leverage
Ti.UI.iOS
namespace orTi.UI.iOS.NavigationWindow
namespace for now when considering it is iOS specific component and there's no equivalent on Android/Windows. MaybeTi.UI.iOS.currentNavigationWindow
orTi.UI.iOS.NavigationWindow.current
property sounds better for me. Or in case we want to make it cross-platformTi.UI.currentNavigationWindow
property like we are doing inTi.UI.currentWindow
andTi.UI.currentTab
in this case?Actually, [Ti.UI.currentWindow](http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI-property-currentWindow) should be removed from the docs, since it requires the "url" property of the window to be set, which was deprecated in 2.x and removed in 6. For [Ti.UI.currentTab](http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI-property-currentTab), it's different, because there can only be one TabGroup opened at the same time, so the value is consistent. For the navigation-window, there can be more navigation-windows that hold different window instances in different contexts (e.g. home-screen und settings that are presented modally, like in my sample-app [studentenfutter-app](https://github.com/hansemannn/studentenfutter-app)). That's why I choose "navigationWindow" to be consistent with the native naming-conventions (self.navigationController) and it could easily be adapted to other platforms as well once we support navigation-flows on those. If Windows does not support that natively (I'd wonder why these days), we could do Android first to have a (partial 2/3) parity. That effort is tracked in TIMOB-24582.
PR (master): https://github.com/appcelerator/titanium_mobile/pull/9608 PR (7_1_X): https://github.com/appcelerator/titanium_mobile/pull/9848 To be reviewed after we have some more time post 7.0.0.
FR Passed: Waiting For Jenkins build to pass.
Closing ticket. Fix can be seen in SDK Version: 7.3.0.v20180607210411 Test and other information can be found at: https://github.com/appcelerator/titanium_mobile/pull/9608