mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-25 21:15:26 +08:00
feat: add a tabBarBackground option to bottom tabs
This commit is contained in:
@@ -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`.
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user