Skip to content

Commit

Permalink
feat: add compact size for bottom tabs (#8728)
Browse files Browse the repository at this point in the history
This adds a compact height mode for iOS devices that are in a compact vertical class (phones in landscape). This is similar to the size change that happens to the header when in landscape mode. Finding a size reference was challenging since most apps lock phones to portrait, but [this answer](https://stackoverflow.com/a/25550871) on Stack Overflow states that it should be 32 pts.

I asked yesterday in the Discord chat if there would be interest in this and some other enhancements here, but no on replied, so I thought I would go ahead and open this to at least start a discussion.
  • Loading branch information
thornbill authored Sep 22, 2020
1 parent 9b03c8e commit a6179b7
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions packages/bottom-tabs/src/views/BottomTabBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Props = BottomTabBarProps & {
};

const DEFAULT_TABBAR_HEIGHT = 49;
const COMPACT_TABBAR_HEIGHT = 32;
const DEFAULT_MAX_TAB_ITEM_WIDTH = 125;

const useNativeDriver = Platform.OS !== 'web';
Expand Down Expand Up @@ -119,6 +120,8 @@ export default function BottomTabBar({
width: dimensions.width,
});

const isLandscape = () => dimensions.width > dimensions.height;

const handleLayout = (e: LayoutChangeEvent) => {
const { height, width } = e.nativeEvent.layout;

Expand Down Expand Up @@ -160,9 +163,7 @@ export default function BottomTabBar({

return routes.length * maxTabItemWidth <= layout.width;
} else {
const isLandscape = dimensions.width > dimensions.height;

return isLandscape;
return isLandscape();
}
};

Expand All @@ -180,6 +181,18 @@ export default function BottomTabBar({
0
);

const getDefaultTabBarHeight = () => {
if (
Platform.OS === 'ios' &&
!Platform.isPad &&
isLandscape() &&
shouldUseHorizontalLabels()
) {
return COMPACT_TABBAR_HEIGHT;
}
return DEFAULT_TABBAR_HEIGHT;
};

return (
<Animated.View
style={[
Expand All @@ -205,7 +218,7 @@ export default function BottomTabBar({
position: isTabBarHidden ? 'absolute' : (null as any),
},
{
height: DEFAULT_TABBAR_HEIGHT + paddingBottom,
height: getDefaultTabBarHeight() + paddingBottom,
paddingBottom,
paddingHorizontal: Math.max(insets.left, insets.right),
},
Expand Down

0 comments on commit a6179b7

Please sign in to comment.