-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: split
useStatusBarHeightDetector
hook into web and native flav…
…ors (#266) fix: split useStatusBarHeightDetector hook into web and native flavours
- Loading branch information
1 parent
08f9b95
commit 08b640e
Showing
2 changed files
with
29 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { useEffect, useState } from 'react' | ||
import { NativeModules, Platform, StatusBar } from 'react-native' | ||
|
||
type Props = { | ||
isPortraitMode: boolean | ||
} | ||
|
||
const NativeStatusBarManager = require('react-native/Libraries/Components/StatusBar/NativeStatusBarManagerIOS') | ||
|
||
export const useStatusBarHeightDetector = ({ isPortraitMode }: Props) => { | ||
const { StatusBarManager } = NativeModules | ||
const [barHeight, setBarHeight] = useState(0) | ||
|
||
useEffect(() => { | ||
if (Platform.OS !== 'ios') return setBarHeight(StatusBar.currentHeight ?? 0) | ||
// handling edge case when app is opened in landscape mode and barHeight = 0 | ||
const StatusBarManagerModule = NativeStatusBarManager?.default || StatusBarManager | ||
|
||
StatusBarManagerModule?.getHeight(({ height }: { height: number }) => | ||
setBarHeight(isPortraitMode && height !== 0 ? height : 50) | ||
) | ||
}, [StatusBarManager, isPortraitMode]) | ||
|
||
return { | ||
statusBarHeight: barHeight, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,9 @@ | ||
import { useEffect, useState } from 'react' | ||
import { NativeModules, Platform, StatusBar } from 'react-native' | ||
|
||
type Props = { | ||
isPortraitMode: boolean | ||
} | ||
|
||
const NativeStatusBarManager = require('react-native/Libraries/Components/StatusBar/NativeStatusBarManagerIOS') | ||
|
||
export const useStatusBarHeightDetector = ({ isPortraitMode }: Props) => { | ||
const { StatusBarManager } = NativeModules | ||
const [barHeight, setBarHeight] = useState(0) | ||
|
||
useEffect(() => { | ||
if (Platform.OS !== 'ios') return setBarHeight(StatusBar.currentHeight ?? 0) | ||
// handling edge case when app is opened in landscape mode and barHeight = 0 | ||
const StatusBarManagerModule = NativeStatusBarManager?.default || StatusBarManager | ||
|
||
StatusBarManagerModule?.getHeight(({ height }: { height: number }) => | ||
setBarHeight(isPortraitMode && height !== 0 ? height : 50) | ||
) | ||
}, [StatusBarManager, isPortraitMode]) | ||
|
||
export const useStatusBarHeightDetector = ({ isPortraitMode: _ }: Props) => { | ||
return { | ||
statusBarHeight: barHeight, | ||
statusBarHeight: 0, | ||
} | ||
} |