mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-26 23:05:00 +08:00
Support nested navigation context.
Reviewed By: fkgozali Differential Revision: D2525434 fb-gh-sync-id: 18e7d672b2cbadc318a207c8812f38d8669bad30
This commit is contained in:
committed by
facebook-github-bot-0
parent
dcd82a2450
commit
a2524bac33
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user