Tweak tabbar sizing on web (#2996)

This commit is contained in:
dan 2024-02-27 03:56:25 +00:00 committed by GitHub
parent 3ec4e034b7
commit 1a34921661
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4,7 +4,6 @@ import {Text} from '../util/text/Text'
import {PressableWithHover} from '../util/PressableWithHover' import {PressableWithHover} from '../util/PressableWithHover'
import {usePalette} from 'lib/hooks/usePalette' import {usePalette} from 'lib/hooks/usePalette'
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries' import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
import {isWeb} from 'platform/detection'
import {DraggableScrollView} from './DraggableScrollView' import {DraggableScrollView} from './DraggableScrollView'
export interface TabBarProps { export interface TabBarProps {
@ -32,13 +31,15 @@ export function TabBar({
[indicatorColor, pal], [indicatorColor, pal],
) )
const {isDesktop, isTablet} = useWebMediaQueries() const {isDesktop, isTablet} = useWebMediaQueries()
const styles = isDesktop || isTablet ? desktopStyles : mobileStyles
// scrolls to the selected item when the page changes // scrolls to the selected item when the page changes
useEffect(() => { useEffect(() => {
scrollElRef.current?.scrollTo({ scrollElRef.current?.scrollTo({
x: itemXs[selectedPage] || 0, x:
(itemXs[selectedPage] || 0) - styles.contentContainer.paddingHorizontal,
}) })
}, [scrollElRef, itemXs, selectedPage]) }, [scrollElRef, itemXs, selectedPage, styles])
const onPressItem = useCallback( const onPressItem = useCallback(
(index: number) => { (index: number) => {
@ -63,8 +64,6 @@ export function TabBar({
[], [],
) )
const styles = isDesktop || isTablet ? desktopStyles : mobileStyles
return ( return (
<View testID={testID} style={[pal.view, styles.outer]}> <View testID={testID} style={[pal.view, styles.outer]}>
<DraggableScrollView <DraggableScrollView
@ -80,15 +79,17 @@ export function TabBar({
testID={`${testID}-selector-${i}`} testID={`${testID}-selector-${i}`}
key={`${item}-${i}`} key={`${item}-${i}`}
onLayout={e => onItemLayout(e, i)} onLayout={e => onItemLayout(e, i)}
style={[styles.item, selected && indicatorStyle]} style={styles.item}
hoverStyle={pal.viewLight} hoverStyle={pal.viewLight}
onPress={() => onPressItem(i)}> onPress={() => onPressItem(i)}>
<View style={[styles.itemInner, selected && indicatorStyle]}>
<Text <Text
type={isDesktop || isTablet ? 'xl-bold' : 'lg-bold'} type={isDesktop || isTablet ? 'xl-bold' : 'lg-bold'}
testID={testID ? `${testID}-${item}` : undefined} testID={testID ? `${testID}-${item}` : undefined}
style={selected ? pal.text : pal.textLight}> style={selected ? pal.text : pal.textLight}>
{item} {item}
</Text> </Text>
</View>
</PressableWithHover> </PressableWithHover>
) )
})} })}
@ -103,18 +104,18 @@ const desktopStyles = StyleSheet.create({
width: 598, width: 598,
}, },
contentContainer: { contentContainer: {
columnGap: 8, paddingHorizontal: 0,
marginLeft: 14,
paddingRight: 14,
backgroundColor: 'transparent', backgroundColor: 'transparent',
}, },
item: { item: {
paddingTop: 14, paddingTop: 14,
paddingHorizontal: 14,
justifyContent: 'center',
},
itemInner: {
paddingBottom: 12, paddingBottom: 12,
paddingHorizontal: 10,
borderBottomWidth: 3, borderBottomWidth: 3,
borderBottomColor: 'transparent', borderBottomColor: 'transparent',
justifyContent: 'center',
}, },
}) })
@ -123,17 +124,17 @@ const mobileStyles = StyleSheet.create({
flexDirection: 'row', flexDirection: 'row',
}, },
contentContainer: { contentContainer: {
columnGap: isWeb ? 0 : 20,
marginLeft: isWeb ? 0 : 18,
paddingRight: isWeb ? 0 : 36,
backgroundColor: 'transparent', backgroundColor: 'transparent',
paddingHorizontal: 8,
}, },
item: { item: {
paddingTop: 10, paddingTop: 10,
paddingBottom: 10, paddingHorizontal: 10,
paddingHorizontal: isWeb ? 8 : 0,
borderBottomWidth: 3,
borderBottomColor: 'transparent',
justifyContent: 'center', justifyContent: 'center',
}, },
itemInner: {
paddingBottom: 10,
borderBottomWidth: 3,
borderBottomColor: 'transparent',
},
}) })