Eric Vicenti a91466f84a Rename NavigationState module to NavigationStateUtils
Summary: There is a NavigationState type within this module so the name cannot be shared

Reviewed By: hedgerwang

Differential Revision: D2938311

fb-gh-sync-id: c5208755c9dfa5bf0e67666957c01e203ddd4218
shipit-source-id: c5208755c9dfa5bf0e67666957c01e203ddd4218
2016-02-19 01:24:54 -08:00

52 lines
1.3 KiB
JavaScript

/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule NavigationContainer
* @flow
*/
'use strict';
var React = require('React');
var NavigationRootContainer = require('NavigationRootContainer');
function createNavigationContainer(Component: React.Component): React.Component {
class NavigationComponent extends React.Component {
render() {
return (
<Component
onNavigate={this.getNavigationHandler()}
{...this.props}
/>
);
}
getNavigationHandler() {
return this.props.onNavigate || this.context.onNavigate;
}
getChildContext() {
return {
onNavigate: this.getNavigationHandler(),
};
}
}
NavigationComponent.contextTypes = {
onNavigate: React.PropTypes.func,
};
NavigationComponent.childContextTypes = {
onNavigate: React.PropTypes.func,
};
return NavigationComponent;
}
var NavigationContainer = {
create: createNavigationContainer,
RootContainer: NavigationRootContainer,
};
module.exports = NavigationContainer;