Reputation: 13141
I've seen a few examples online using Navigator.NavigationBar
. It looks handy but I don't know how to use it. Are there docs anywhere?
Upvotes: 7
Views: 9408
Reputation: 968
I would also add to checkout the UI Explorer in the examples that show how to use it. UIExplorer Navigator -
EDIT: React native has done a good job updating their docs. Here is the documentation to the navigator: navigator docs
UPDATE: Do your self a favor and use something like react-navigation. Those links will be broken because of MANY updates to RN.
Upvotes: 0
Reputation: 54260
Updates on 2017: Official documentation of React Native recommend using react-navigation
library.
Setup variable:
import {
StackNavigator,
} from 'react-navigation';
const App = StackNavigator({
Home: { screen: HomeScreen },
Profile: { screen: ProfileScreen },
});
Example:
class HomeScreen extends React.Component {
static navigationOptions = {
title: 'Welcome',
};
render() {
const { navigate } = this.props.navigation;
return (
<Button
title="Go to Jane's profile"
onPress={() =>
navigate('Profile', { name: 'Jane' })
}
/>
);
}
}
Read the official documentation for detailed information.
Upvotes: 0
Reputation: 151
Officially there is no guide Navigator.Navigation Bar. But looking on the internet you can find examples of how it works. Below is an example that I used for one of my projects.
var PageOne = require('./pageone'),
PageTwo = require('./pagetwo');
var NavigationBarRouteMapper = {
LeftButton: function( route, navigator, index, navState ){
return(
<Text>{ route.leftButton }</Text>
)
},
Title: function( route, navigator, index, navState ){
return(
<Text>{ route.title }</Text>
)
},
RightButton: function( route, navigator, index, navState ){
return(
<Text>{ route.rightButton }</Text>
)
}
}
var App = React.createClass({
renderScene: function( route, nav ) {
switch (route.id) {
case 'PageOne':
return <PageOne navigator={ nav } title={ "PageOne" } />
case 'PageTwo':
return <PageTwo navigator={ nav } leftButton={ "Back" } title={ "PageTwo" } />;
}
},
render: function() {
return (
<Navigator
initialRoute={{ id: 'PageOne', title: 'PageOne' }}
renderScene={ this.renderScene }
configureScene={( route ) => {
if ( route.sceneConfig ) {
return route.sceneConfig;
}
return Navigator.SceneConfigs.FloatFromRight;
}}
navigationBar={
<Navigator.NavigationBar
routeMapper={ NavigationBarRouteMapper }
/>
}
/>
);
},
});
Upvotes: 15