mirror of
https://github.com/status-im/react-native.git
synced 2025-02-06 06:34:01 +00:00
a3085464f6
Summary: A new API to unify internal navigation. Also addresses a highly-rated community 'pain': https://productpains.com/post/react-native/better-navigator-api-and-docs/ Offers the following improvements: - Redux-style navigation logic is easy to reason about - Navigation state can be easily saved and restored through refreshes - Declarative navigation views can be implemented in native or JS - Animations and gestures are isolated and now use the Animated library public Reviewed By: hedgerwang Differential Revision: D2798048 fb-gh-sync-id: 88027ef9ead8a80afa38354252bc377455cc6dbb
52 lines
1.3 KiB
JavaScript
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-native');
|
|
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;
|