|
1 | 1 | # @logicwind/react-native-status-bar-height |
2 | 2 |
|
3 | | -A simple and lightweight React Native package to get the height of the status bar on both Android and iOS. |
| 3 | +A simple and lightweight React Native package to get the **status bar height** and **bottom safe area inset** on both Android and iOS. |
4 | 4 |
|
5 | 5 | ### Installation |
6 | 6 |
|
@@ -30,18 +30,43 @@ No additional setup is required. |
30 | 30 |
|
31 | 31 | ## Usage |
32 | 32 |
|
33 | | -Import and use the `fetchStatusBarHeight` function to get the status bar height. |
| 33 | +Import and use the utility functions to fetch values: |
34 | 34 |
|
35 | 35 | ```tsx md title="App.tsx" |
36 | | -import { fetchStatusBarHeight } from '@logicwind/react-native-status-bar-height'; |
| 36 | +import { |
| 37 | + fetchStatusBarHeight, |
| 38 | + fetchBottonInset, |
| 39 | +} from '@logicwind/react-native-status-bar-height'; |
37 | 40 |
|
38 | 41 | const statusBarHeight = fetchStatusBarHeight(); |
| 42 | +const bottomInset = fetchBottonInset(); |
39 | 43 | ``` |
40 | 44 |
|
| 45 | +## Example |
| 46 | +```tsx md title="App.tsx" |
| 47 | +<View style={{ flex: 1 }}> |
| 48 | + <Text style={{ marginTop: fetchStatusBarHeight() }}> |
| 49 | + Status Bar Height |
| 50 | + </Text> |
| 51 | + <View style={{ flex: 1 }} /> |
| 52 | + <Text style={{ marginBottom: fetchBottonInset() }}> |
| 53 | + Bottom Safe Area |
| 54 | + </Text> |
| 55 | +</View> |
| 56 | +``` |
| 57 | + |
| 58 | +## API |
| 59 | +`fetchStatusBarHeight(): number` - Returns the status bar height in pixels. |
| 60 | + |
| 61 | +`fetchBottomInset(): number` - Returns the bottom safe area inset in pixels, helpful for avoiding overlap with gesture/navigation bars. |
| 62 | + |
41 | 63 | ## How It Works |
42 | 64 |
|
43 | | -- On **iOS**, it attempts to fetch the status bar height using native modules. If unavailable, it falls back to predefined values based on screen dimensions. |
44 | | -- On **Android**, it retrieves `StatusBar.currentHeight`. |
| 65 | +- On iOS, it retrieves values using native APIs or falls back to common values. |
| 66 | + |
| 67 | +- On Android, it uses StatusBar.currentHeight for the status bar height, and WindowInsets for the bottom inset when available. |
| 68 | + |
| 69 | +- A fallback mechanism is in place to provide reasonable defaults. |
45 | 70 |
|
46 | 71 | ## react-native-status-bar-height is crafted mindfully at [Logicwind](https://www.logicwind.com?utm_source=github&utm_medium=github.com-logicwind&utm_campaign=react-native-status-bar-height) |
47 | 72 |
|
|
0 commit comments