Skip to content

Commit 5692b06

Browse files
committed
fix: use safe area insets instead of guestimating height
1 parent 4d19372 commit 5692b06

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

src/components/Tabbar/CustomTabBar.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ import type { BottomTabBarProps } from '@react-navigation/bottom-tabs';
2222
import { Animated, StyleSheet } from 'react-native';
2323
import TabIcon from './TabIcon';
2424
import { useTheme } from 'react-native-paper';
25+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
2526

26-
export const TAB_BAR_HEIGHT = 60;
27+
export const TAB_BAR_HEIGHT = 55;
2728

2829
function CustomTabBar(
2930
props: BottomTabBarProps & {
@@ -40,12 +41,15 @@ function CustomTabBar(
4041
) {
4142
const state = props.state;
4243
const theme = useTheme();
44+
const safeAreaInsets = useSafeAreaInsets();
4345

4446
return (
4547
<Animated.View
4648
style={{
4749
...styles.bar,
4850
backgroundColor: theme.colors.surface,
51+
paddingBottom: safeAreaInsets.bottom,
52+
height: TAB_BAR_HEIGHT + safeAreaInsets.bottom,
4953
}}
5054
>
5155
{state.routes.map(
@@ -79,7 +83,6 @@ const styles = StyleSheet.create({
7983
bar: {
8084
flexDirection: 'row',
8185
width: '100%',
82-
height: TAB_BAR_HEIGHT,
8386
position: 'absolute',
8487
bottom: 0,
8588
left: 0,

src/navigation/TabNavigator.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
GeneralPreferenceKeys,
4040
} from '../utils/asyncStorage';
4141
import { ParsedUrlDataType } from '../utils/URLHandler';
42+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
4243

4344
const styles = StyleSheet.create({
4445
header: {
@@ -103,6 +104,7 @@ const ICONS: {
103104
};
104105

105106
function TabNavigator(props: PropsType) {
107+
const safeAreaInsets = useSafeAreaInsets();
106108
const { preferences } = usePreferences();
107109
let defaultRoute = getPreferenceString(
108110
GeneralPreferenceKeys.defaultStartScreen,
@@ -133,7 +135,7 @@ function TabNavigator(props: PropsType) {
133135
backBehavior={'initialRoute'}
134136
screenOptions={{
135137
sceneStyle: {
136-
paddingBottom: TAB_BAR_HEIGHT,
138+
paddingBottom: TAB_BAR_HEIGHT + safeAreaInsets.bottom,
137139
},
138140
}}
139141
>

0 commit comments

Comments
 (0)