react-native-navigation的迁移库

style-constants.mdx 1.2KB

1234567891011121314151617181920212223242526272829
  1. ---
  2. id: style-constants
  3. title: Constants
  4. sidebar_label: Constants
  5. ---
  6. React Native Navigation exposes a set of constants which can be used to get the dimensions of various navigation elements on the screen: StatusBar, TopBar and BottomTabs.
  7. ## When are constants evaluated
  8. Some of the values exposed through the constants API are actually evaluated only after the UI is created (`setRoot` has been called) and therefore are not accessible through static getters.
  9. For example, if you need to get the height of the BottomTabs, you'll first need to have BottomTabs visible on the screen and only then retrieve their height via the constants API.
  10. :::important
  11. We recommend you don't cache the actual constants object returned by `await Navigation.constants()` as it might not be accurate later on when, for example, a new root is set or orientation changes.
  12. :::
  13. ## API
  14. As explained above, constants are evaluated in native each time the API is invoked. That's why `Navigation.constants()` returns a promise and the use is as follows:
  15. ```js
  16. const { Navigation } = require('react-native-navigation');
  17. const {
  18. statusBarHeight,
  19. TopBarHeight,
  20. BottomTabsHeight
  21. } = await Navigation.constants();
  22. ```