File tree Expand file tree Collapse file tree 2 files changed +29
-20
lines changed Expand file tree Collapse file tree 2 files changed +29
-20
lines changed Original file line number Diff line number Diff line change
1
+ import { useEffect , useState } from 'react'
2
+ import { NativeModules , Platform , StatusBar } from 'react-native'
3
+
4
+ type Props = {
5
+ isPortraitMode : boolean
6
+ }
7
+
8
+ const NativeStatusBarManager = require ( 'react-native/Libraries/Components/StatusBar/NativeStatusBarManagerIOS' )
9
+
10
+ export const useStatusBarHeightDetector = ( { isPortraitMode } : Props ) => {
11
+ const { StatusBarManager } = NativeModules
12
+ const [ barHeight , setBarHeight ] = useState ( 0 )
13
+
14
+ useEffect ( ( ) => {
15
+ if ( Platform . OS !== 'ios' ) return setBarHeight ( StatusBar . currentHeight ?? 0 )
16
+ // handling edge case when app is opened in landscape mode and barHeight = 0
17
+ const StatusBarManagerModule = NativeStatusBarManager ?. default || StatusBarManager
18
+
19
+ StatusBarManagerModule ?. getHeight ( ( { height } : { height : number } ) =>
20
+ setBarHeight ( isPortraitMode && height !== 0 ? height : 50 )
21
+ )
22
+ } , [ StatusBarManager , isPortraitMode ] )
23
+
24
+ return {
25
+ statusBarHeight : barHeight ,
26
+ }
27
+ }
Original file line number Diff line number Diff line change 1
- import { useEffect , useState } from 'react'
2
- import { NativeModules , Platform , StatusBar } from 'react-native'
3
-
4
1
type Props = {
5
2
isPortraitMode : boolean
6
3
}
7
4
8
- const NativeStatusBarManager = require ( 'react-native/Libraries/Components/StatusBar/NativeStatusBarManagerIOS' )
9
-
10
- export const useStatusBarHeightDetector = ( { isPortraitMode } : Props ) => {
11
- const { StatusBarManager } = NativeModules
12
- const [ barHeight , setBarHeight ] = useState ( 0 )
13
-
14
- useEffect ( ( ) => {
15
- if ( Platform . OS !== 'ios' ) return setBarHeight ( StatusBar . currentHeight ?? 0 )
16
- // handling edge case when app is opened in landscape mode and barHeight = 0
17
- const StatusBarManagerModule = NativeStatusBarManager ?. default || StatusBarManager
18
-
19
- StatusBarManagerModule ?. getHeight ( ( { height } : { height : number } ) =>
20
- setBarHeight ( isPortraitMode && height !== 0 ? height : 50 )
21
- )
22
- } , [ StatusBarManager , isPortraitMode ] )
23
-
5
+ export const useStatusBarHeightDetector = ( { isPortraitMode : _ } : Props ) => {
24
6
return {
25
- statusBarHeight : barHeight ,
7
+ statusBarHeight : 0 ,
26
8
}
27
9
}
You can’t perform that action at this time.
0 commit comments