Top bar not showing
Given the following App.js (entry point file):
import { Navigation } from 'react-native-navigation'
import { HomeScreen, TopBarLogo } from './app/screens'
Navigation.registerComponent('Home', () => HomeScreen)
Navigation.registerComponent('TopBarLogo', () => TopBarLogo)
Navigation.events().registerAppLaunchedListener(() => {
Navigation.setRoot({
root: {
component: {
name: 'Home',
options: {
topBar: {
title: {
text: 'Home',
color: '#fff'
// component: {
// name: 'TopBarLogo',
// alignment: 'center'
// }
},
drawBehind: true,
visible: true,
// animate: false
}
}
}
}
})
})
Neither setting the topBar there nor setting it using the static get options() method seems to make the top bar show.
Environment
- React Native Navigation version:
2.0.2415 - React Native version:
0.56.0 - Platform(s):
iOS - Device info: Simulator, debug
If I'm not mistaken, "component" layout does not show TopBar because it's not meant to be have any navigation control - makes no sense to provide one in a single component app (give a try, open the stock Calculator app of your phone and you'll understand).
If you put your "component" inside a "stack" it will work little you expect.
stack: {
children: [
{
component: {
name: 'Home',
},
},
],
options: {
topBar: {
title: { text: 'Home' }
},
},
},
Top bar only shows on a stack layout
Thanks guys I’ll give it a try, still trying to get used to v2.
That works great, thanks!
@mths0x5f This doesn't work for me.
Navigation.setRoot({
root: {
stack: {
children: [{
component: {
name: DASHBOARD_SCENE,
}
}],
options: {
topBar: {
title: {
text: 'Dashboard'
}
}
}
}
}
});
react-native-navigation: 2.0.2641
I can't see top bar. Can you please help me?
@bdavid68 I think that the options should be inside component rather than stack
Setting options inside component works for me. If I set options as a stack propertie the TopBar doesn't show.
I was able to show topBar by adding the screens that need to be connected together in one stack inside the bottomBar root.
Example:
Navigation.setRoot({
root: {
bottomTabs: {
id: 'stack-with-bottom',
children: [
{
stack: {
children: [
{
component: {
name: 'Home',
},
},
{
component: {
name: 'Logger',
},
},
],
},
},
],
},
},
});