React Native 获得status bar的高度

  • Post author:
  • Post category:其他



https://stackoverflow.com/questions/35436643/how-to-find-height-of-status-bar-in-android-through-react-native

Unfortunately, as of v0.34, the API to do this is still inconsistent across platforms.

StatusBarManager.HEIGHT

will give you the

current height

of the Status Bar on Android.

import { Platform, NativeModules } from 'react-native';
const { StatusBarManager } = NativeModules;

const STATUSBAR_HEIGHT = Platform.OS === 'ios' ? 20 : StatusBarManager.HEIGHT;

On iOS, you can use

getHeight()

StatusBarManager.getHeight((statusBarHeight)=>{
  console.log(statusBarHeight)
})

As a side note, if you want your app to draw under the status bar on Android similar to the default iOS behavior, you can do so by setting a couple props on

<StatusBar>

as follows:

<StatusBar translucent={true} backgroundColor={'transparent'} {...props} />  



版权声明:本文为chinalwb原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。