Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions src/components/BottomNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,22 @@ type Props = {
* On Android, this works best when [`windowSoftInputMode`](https://developer.android.com/guide/topics/manifest/activity-element#wsoft) is set to `adjustResize`.
*/
keyboardHidesNavigationBar?: boolean;
/**
* Safe area insets for the tab bar. This can be used to avoid elements like the navigation bar on Android and bottom safe area on iOS.
* The bottom insets for iOS is added by default. You can override the behavior with this option.
*/
safeAreaInsets?: {
top?: number;
right?: number;
bottom?: number;
left?: number;
};
/**
* Style for the bottom navigation bar. You can pass a custom background color here:
*
* ```js
* barStyle={{ backgroundColor: '#694fad' }}
* ```
*
* If you have a translucent navigation bar on Android, you can also set a bottom padding here:
*
* ```js
* barStyle={{ paddingBottom: 48 }}
* ```
*/
barStyle?: StyleProp<ViewStyle>;
style?: StyleProp<ViewStyle>;
Expand Down Expand Up @@ -338,6 +342,7 @@ const BottomNavigation = ({
onTabPress,
onIndexChange,
shifting = navigationState.routes.length > 3,
safeAreaInsets,
}: Props) => {
const { scale } = theme.animation;

Expand Down Expand Up @@ -593,6 +598,12 @@ const BottomNavigation = ({

const rippleSize = layout.width / 4;

const insets = {
left: safeAreaInsets?.left ?? 0,
right: safeAreaInsets?.right ?? 0,
bottom: safeAreaInsets?.bottom ?? BOTTOM_INSET,
};

return (
<View style={[styles.container, style]}>
<View style={[styles.content, { backgroundColor: colors.background }]}>
Expand Down Expand Up @@ -678,7 +689,11 @@ const BottomNavigation = ({
<View
style={[
styles.items,
{ marginBottom: BOTTOM_INSET, maxWidth: maxTabBarWidth },
{
marginBottom: insets.bottom,
marginHorizontal: Math.max(insets.left, insets.right),
maxWidth: maxTabBarWidth,
},
]}
>
{shifting ? (
Expand Down Expand Up @@ -948,7 +963,6 @@ const styles = StyleSheet.create({
},
items: {
flexDirection: 'row',
width: '100%',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change breaks tabs on the web.

Before:
image

After:
image

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SleeplessByte can you send a PR conditionally adding this style on Web?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yesh, sure.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},
item: {
flex: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ exports[`hides labels in non-shifting bottom navigation 1`] = `
Array [
Object {
"flexDirection": "row",
"width": "100%",
},
Object {
"marginBottom": 0,
"marginHorizontal": 0,
"maxWidth": 504,
},
]
Expand Down Expand Up @@ -771,10 +771,10 @@ exports[`hides labels in shifting bottom navigation 1`] = `
Array [
Object {
"flexDirection": "row",
"width": "100%",
},
Object {
"marginBottom": 0,
"marginHorizontal": 0,
"maxWidth": 504,
},
]
Expand Down Expand Up @@ -1469,10 +1469,10 @@ exports[`renders custom icon and label in non-shifting bottom navigation 1`] = `
Array [
Object {
"flexDirection": "row",
"width": "100%",
},
Object {
"marginBottom": 0,
"marginHorizontal": 0,
"maxWidth": 504,
},
]
Expand Down Expand Up @@ -2075,10 +2075,10 @@ exports[`renders custom icon and label in shifting bottom navigation 1`] = `
Array [
Object {
"flexDirection": "row",
"width": "100%",
},
Object {
"marginBottom": 0,
"marginHorizontal": 0,
"maxWidth": 480,
},
]
Expand Down Expand Up @@ -2953,10 +2953,10 @@ exports[`renders custom icon and label with custom colors in non-shifting bottom
Array [
Object {
"flexDirection": "row",
"width": "100%",
},
Object {
"marginBottom": 0,
"marginHorizontal": 0,
"maxWidth": 504,
},
]
Expand Down Expand Up @@ -3886,10 +3886,10 @@ exports[`renders custom icon and label with custom colors in shifting bottom nav
Array [
Object {
"flexDirection": "row",
"width": "100%",
},
Object {
"marginBottom": 0,
"marginHorizontal": 0,
"maxWidth": 504,
},
]
Expand Down Expand Up @@ -4719,10 +4719,10 @@ exports[`renders non-shifting bottom navigation 1`] = `
Array [
Object {
"flexDirection": "row",
"width": "100%",
},
Object {
"marginBottom": 0,
"marginHorizontal": 0,
"maxWidth": 504,
},
]
Expand Down Expand Up @@ -5652,10 +5652,10 @@ exports[`renders shifting bottom navigation 1`] = `
Array [
Object {
"flexDirection": "row",
"width": "100%",
},
Object {
"marginBottom": 0,
"marginHorizontal": 0,
"maxWidth": 480,
},
]
Expand Down