react-native-navigation icon indicating copy to clipboard operation
react-native-navigation copied to clipboard

Top bar not showing

Open chrise86 opened this issue 8 years ago • 8 comments

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

chrise86 avatar Jul 19 '18 18:07 chrise86

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' }
                  },
                },
              },

mths0x5f avatar Jul 19 '18 18:07 mths0x5f

Top bar only shows on a stack layout

hisothreed avatar Jul 19 '18 20:07 hisothreed

Thanks guys I’ll give it a try, still trying to get used to v2.

chrise86 avatar Jul 19 '18 20:07 chrise86

That works great, thanks!

chrise86 avatar Jul 20 '18 00:07 chrise86

@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 avatar Nov 22 '18 11:11 bdavid68

@bdavid68 I think that the options should be inside component rather than stack

paul-paliychuk avatar May 20 '19 11:05 paul-paliychuk

Setting options inside component works for me. If I set options as a stack propertie the TopBar doesn't show.

jerodb avatar Oct 30 '19 20:10 jerodb

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', }, }, ], }, }, ], }, }, });

fadinasr avatar Jul 18 '20 15:07 fadinasr