How to find height of status bar in Android through React Native?

前端 未结 4 1676
刺人心
刺人心 2021-01-30 20:31

How can I find the height of the status bar on Android through React Native?

If I check the React.Dimensions height the value seems to include the status ba

4条回答
  •  遥遥无期
    2021-01-30 21:02

    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 as follows:

       
    

提交回复
热议问题