React-native-navigation: Constants support

Created on 25 Jun 2018  路  9Comments  路  Source: wix/react-native-navigation

iOS

  • [x] statusBarHeight
  • [x] topBarHeight
  • [x] bottomTabsHeight

Android

  • [x] statusBarHeight
  • [x] topBarHeight
  • [x] bottomTabsHeight
  • [x] backButtonId
  • [x] document
Android iOS v2

Most helpful comment

Hi, I am also getting a value of 0 for topBarHeight.

My top bar config:

topBar: { animate: true, hideOnScroll: false, buttonColor: "black", drawBehind: true, backButton: { color: "black" }

All 9 comments

Constants returns a promise but is documented as synchronous function. Also the returned value is wrong on my phone LG G4 returns 96 224.5 which apparently is way too high values for status and topbar.

Navigation.constants().then(({ statusBarHeight, topBarHeight }) => {
      console.log(statusBarHeight, topBarHeight)
    })

I'm getting '0' for my topBarHeight and bottomTabsHeight. statusBarHeight appears to be reported correctly ('44').

Environment

  • React Native Navigation version: 2.0.2418
  • React Native version: 0.51.0
  • Platform(s) (iOS, Android, or both?): iOS (only tested in iOS)
  • Device info (Simulator/Device? OS version? Debug/Release?): Simulator, iPhone X, 11.4

drawUnder by any chance?

@thame

The code of below works fine.

Navigation.events().registerAppLaunchedListener(async () => {
  await Navigation.setRoot({
    root: {
      stack: {
      children: [
        {
          component: {
            name: "screen"
          }
        }
      ],
    });
  const c = await Navigation.constants();
  console.log(c.topBarHeight);
});

https://github.com/wix/react-native-navigation/blob/v2/lib/ios/Constants.m#L10

Looking at the current implementation, it returns the height of the navigationBar of navigationController of rootViewController. So, in the current implementation, it seems that the height can be taken only after displaying the screen with stack layout.

I am getting wrong value
Constants聽{statusBarHeight: 63, topBarHeight: 147.5, backButtonId: "RNN.back", bottomTabsHeight: undefined}

Hi, I am also getting a value of 0 for topBarHeight.

My top bar config:

topBar: { animate: true, hideOnScroll: false, buttonColor: "black", drawBehind: true, backButton: { color: "black" }

In researching why the registerNavigationButtonPressedListener doesn't report events on iOS, I'm seeing that backButtonId is undefined on iOS. Is this intentional? I'm starting to think that is the reason why it's not working. Can we set this anywhere?

Same issue, very odd documentation, sjhowing that we can to use something but it requires more code, but even that it doesnt work with ios?

Was this page helpful?
0 / 5 - 0 ratings