From 82af7bed7135e42e24693b48cf7f1c6f9f5a6981 Mon Sep 17 00:00:00 2001 From: Satyajit Sahoo Date: Mon, 9 Mar 2020 22:20:08 +0100 Subject: [PATCH] feat: add safeAreaInsets to bottom tabs --- .gitignore | 1 + packages/bottom-tabs/src/types.tsx | 10 + .../bottom-tabs/src/views/BottomTabBar.tsx | 215 +++++++++--------- 3 files changed, 122 insertions(+), 104 deletions(-) diff --git a/.gitignore b/.gitignore index 960c8148..5e70f7e9 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ .gradle .project .settings +.history local.properties diff --git a/packages/bottom-tabs/src/types.tsx b/packages/bottom-tabs/src/types.tsx index 26b04454..35949878 100644 --- a/packages/bottom-tabs/src/types.tsx +++ b/packages/bottom-tabs/src/types.tsx @@ -184,6 +184,16 @@ export type BottomTabBarOptions = { * Whether the label position should adapt to the orientation. */ adaptive?: boolean; + /** + * Safe area insets for the tab bar. This is used to avoid elements like the navigation bar on Android and bottom safe area on iOS. + * By default, the device's safe area insets are automatically detected. You can override the behavior with this option. + */ + safeAreaInsets?: { + top?: number; + right?: number; + bottom?: number; + left?: number; + }; /** * Style object for the tab bar container. */ diff --git a/packages/bottom-tabs/src/views/BottomTabBar.tsx b/packages/bottom-tabs/src/views/BottomTabBar.tsx index 0766645f..4a2e8211 100644 --- a/packages/bottom-tabs/src/views/BottomTabBar.tsx +++ b/packages/bottom-tabs/src/views/BottomTabBar.tsx @@ -15,7 +15,7 @@ import { CommonActions, useTheme, } from '@react-navigation/native'; -import { SafeAreaConsumer } from 'react-native-safe-area-context'; +import { useSafeArea } from 'react-native-safe-area-context'; import BottomTabItem from './BottomTabItem'; import { BottomTabBarProps } from '../types'; @@ -43,6 +43,7 @@ export default function BottomTabBar({ keyboardHidesTabBar = false, labelPosition, labelStyle, + safeAreaInsets, showIcon, showLabel, style, @@ -158,116 +159,122 @@ export default function BottomTabBar({ } }; + const defaultInsets = useSafeArea(); + + const insets = { + top: safeAreaInsets?.top ?? defaultInsets.top, + right: safeAreaInsets?.right ?? defaultInsets.right, + bottom: safeAreaInsets?.bottom ?? defaultInsets.bottom, + left: safeAreaInsets?.left ?? defaultInsets.left, + }; + return ( - - {insets => ( - + return ( + + + + + + ); + })} + + ); }