feat: add a tabBarBackground option to bottom tabs

This commit is contained in:
Satyajit Sahoo
2021-05-14 08:59:46 +02:00
parent 5165eb76aa
commit 2f282f1070
3 changed files with 42 additions and 3 deletions

View File

@@ -229,6 +229,15 @@ export type BottomTabNavigationOptions = HeaderOptions & {
*/
tabBarStyle?: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
/**
* Component to use as background for the tab bar.
* You could render an image, a gradient, blur view etc.
*
* When using `BlurView`, make sure to set `position: 'absolute'` in `tabBarStyle` as well.
* You'd also need to use `useBottomTabBarHeight()` to add a bottom padding to your content.
*/
tabBarBackground?: () => React.ReactNode;
/**
* Whether this screen should be unmounted when navigating away from it.
* Defaults to `false`.

View File

@@ -144,6 +144,7 @@ export default function BottomTabBar({
tabBarHideOnKeyboard = false,
tabBarVisibilityAnimationConfig,
tabBarStyle,
tabBarBackground,
} = focusedOptions;
const dimensions = useSafeAreaFrame();
@@ -244,12 +245,15 @@ export default function BottomTabBar({
layout,
});
const tabBarBackgroundElement = tabBarBackground?.();
return (
<Animated.View
style={[
styles.tabBar,
{
backgroundColor: colors.card,
backgroundColor:
tabBarBackgroundElement != null ? 'transparent' : colors.card,
borderTopColor: colors.border,
},
{
@@ -278,6 +282,9 @@ export default function BottomTabBar({
pointerEvents={isTabBarHidden ? 'none' : 'auto'}
onLayout={handleLayout}
>
<View pointerEvents="none" style={StyleSheet.absoluteFill}>
{tabBarBackgroundElement}
</View>
<View accessibilityRole="tablist" style={styles.content}>
{routes.map((route, index) => {
const focused = index === state.index;