Skip to content

Commit 81e1e3c

Browse files
committed
feat: is focus
1 parent 48bb880 commit 81e1e3c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/hooks/useIsFocus.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as React from 'react'
2+
import { StatusBar, StatusBarProps } from 'react-native'
3+
import { useIsFocused } from '@react-navigation/native'
4+
5+
/*
6+
If using a tab or drawer navigator, it's a bit more complex because all of the screens in the navigator might be rendered at once and kept rendered - that means that the last StatusBar config you set will be used (likely on the final tab of your tab navigator, not what the user is seeing).
7+
8+
Usage: <FocusAwareStatusBar barStyle="light-content" backgroundColor="#6a51ae" />
9+
*/
10+
export const FocusAwareStatusBar = (props: StatusBarProps) => {
11+
const isFocused = useIsFocused()
12+
13+
return isFocused ? <StatusBar {...props} /> : null
14+
}

0 commit comments

Comments
 (0)