Support nested navigation context.

Reviewed By: fkgozali

Differential Revision: D2525434

fb-gh-sync-id: 18e7d672b2cbadc318a207c8812f38d8669bad30
This commit is contained in:
Hedger Wang
2015-10-17 04:23:35 -07:00
committed by facebook-github-bot-0
parent dcd82a2450
commit a2524bac33
2 changed files with 26 additions and 12 deletions

View File

@@ -27,6 +27,7 @@
'use strict';
var NavigationEventEmitter = require('NavigationEventEmitter');
var NavigationTreeNode = require('NavigationTreeNode');
var emptyFunction = require('emptyFunction');
var invariant = require('invariant');
@@ -38,22 +39,36 @@ import type * as EventSubscription from 'EventSubscription';
* Class that contains the info and methods for app navigation.
*/
class NavigationContext {
__node: NavigationTreeNode;
_eventEmitter: ?NavigationEventEmitter;
_currentRoute: any;
constructor() {
this._eventEmitter = new NavigationEventEmitter(this);
this._currentRoute = null;
// Sets the protected property `__node`.
this.__node = new NavigationTreeNode(this);
this.addListener('willfocus', this._onFocus, this);
this.addListener('didfocus', this._onFocus, this);
}
// TODO: @flow does not like this getter. Will add @flow check back once
// getter/setter is supported.
/* $FlowFixMe - get/set properties not yet supported */
get parent(): ?NavigationContext {
var parent = this.__node.getParent();
return parent ? parent.getValue() : null;
}
/* $FlowFixMe - get/set properties not yet supported */
get currentRoute(): any {
return this._currentRoute;
}
appendChild(childContext: NavigationContext): void {
this.__node.appendChild(childContext.__node);
}
addListener(
eventType: string,
listener: Function,