Reputation: 643
I'm trying to use react navigator with react native but I get only a blank screen, no errors. What is wrong here ?
import React, { Component } from 'react';
import { Button } from 'react-native';
import { StackNavigator } from 'react-navigation';
class MainScreen extends Component {
render() {
return (
<Button
title="Success"
/>
);
}
}
const AppNavigator = StackNavigator(
{
Index: {
screen: MainScreen
}
},
{
initialRouteName: 'Index',
headerMode: 'none'
}
);
export default AppNavigator;
Upvotes: 1
Views: 1729
Reputation: 59
Using
import React, { Component } from 'react';
import { StackNavigator } from 'react-navigation';
class MainScreen extends Component {
render() {
return (
<AppNavigator/> //this is for starting routing
);
}
}
const AppNavigator = StackNavigator(
{
Index: {
screen: MainScreen
}
},
{
initialRouteName: 'Index',
headerMode: 'none'
}
);
export default MainScreen;
U can use this for destination Documentation
static navigationOptions = {
title: 'Home',
}
Upvotes: 0
Reputation: 643
Seems like I forgot to register the main app component. I added AppRegistry.registerComponent('MyApp', () => AppNavigator);
and it worked.
Upvotes: 0
Reputation: 7471
Try adding a height to your MainScreen.
Do something like :
return (
<View style={{ flex: 1 }}>
<Button
title="Success"
/>
</View>
);
Upvotes: 1