Give minWidth to tab indicator only (#7095)
This commit is contained in:
@@ -237,12 +237,25 @@ export function TabBar({
|
|||||||
opacity: 0,
|
opacity: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getScaleX(index: number) {
|
||||||
|
const textWidth = textLayoutsValue[index].width
|
||||||
|
const itemWidth = layoutsValue[index].width
|
||||||
|
const minIndicatorWidth = 45
|
||||||
|
const maxIndicatorWidth = itemWidth - 2 * CONTENT_PADDING
|
||||||
|
const indicatorWidth = Math.min(
|
||||||
|
Math.max(minIndicatorWidth, textWidth),
|
||||||
|
maxIndicatorWidth,
|
||||||
|
)
|
||||||
|
return indicatorWidth / contentSize.get()
|
||||||
|
}
|
||||||
|
|
||||||
if (textLayoutsValue.length === 1) {
|
if (textLayoutsValue.length === 1) {
|
||||||
return {
|
return {
|
||||||
opacity: 1,
|
opacity: 1,
|
||||||
transform: [
|
transform: [
|
||||||
{
|
{
|
||||||
scaleX: textLayoutsValue[0].width / contentSize.get(),
|
scaleX: getScaleX(0),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
@@ -261,7 +274,7 @@ export function TabBar({
|
|||||||
scaleX: interpolate(
|
scaleX: interpolate(
|
||||||
dragProgress.get(),
|
dragProgress.get(),
|
||||||
textLayoutsValue.map((l, i) => i),
|
textLayoutsValue.map((l, i) => i),
|
||||||
textLayoutsValue.map(l => l.width / contentSize.get()),
|
textLayoutsValue.map((l, i) => getScaleX(i)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -429,7 +442,6 @@ const styles = StyleSheet.create({
|
|||||||
},
|
},
|
||||||
itemText: {
|
itemText: {
|
||||||
lineHeight: 20,
|
lineHeight: 20,
|
||||||
minWidth: 45,
|
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
},
|
},
|
||||||
outerBottomBorder: {
|
outerBottomBorder: {
|
||||||
|
|||||||
@@ -25,16 +25,12 @@ export function TabBar({
|
|||||||
testID,
|
testID,
|
||||||
selectedPage,
|
selectedPage,
|
||||||
items,
|
items,
|
||||||
indicatorColor,
|
|
||||||
onSelect,
|
onSelect,
|
||||||
onPressSelected,
|
onPressSelected,
|
||||||
}: TabBarProps) {
|
}: TabBarProps) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const scrollElRef = useRef<ScrollView>(null)
|
const scrollElRef = useRef<ScrollView>(null)
|
||||||
const itemRefs = useRef<Array<Element>>([])
|
const itemRefs = useRef<Array<Element>>([])
|
||||||
const indicatorStyle = {
|
|
||||||
borderBottomColor: indicatorColor || t.palette.primary_500,
|
|
||||||
}
|
|
||||||
const {gtMobile} = useBreakpoints()
|
const {gtMobile} = useBreakpoints()
|
||||||
const styles = gtMobile ? desktopStyles : mobileStyles
|
const styles = gtMobile ? desktopStyles : mobileStyles
|
||||||
|
|
||||||
@@ -122,12 +118,19 @@ export function TabBar({
|
|||||||
style={[
|
style={[
|
||||||
styles.itemText,
|
styles.itemText,
|
||||||
selected ? t.atoms.text : t.atoms.text_contrast_medium,
|
selected ? t.atoms.text : t.atoms.text_contrast_medium,
|
||||||
selected && indicatorStyle,
|
|
||||||
a.text_md,
|
a.text_md,
|
||||||
a.font_bold,
|
a.font_bold,
|
||||||
{lineHeight: 20},
|
{lineHeight: 20},
|
||||||
]}>
|
]}>
|
||||||
{item}
|
{item}
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
styles.itemIndicator,
|
||||||
|
selected && {
|
||||||
|
backgroundColor: t.palette.primary_500,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
</PressableWithHover>
|
</PressableWithHover>
|
||||||
@@ -158,13 +161,20 @@ const desktopStyles = StyleSheet.create({
|
|||||||
},
|
},
|
||||||
itemInner: {
|
itemInner: {
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
|
overflowX: 'hidden',
|
||||||
},
|
},
|
||||||
itemText: {
|
itemText: {
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
|
paddingBottom: 10 + 3,
|
||||||
|
},
|
||||||
|
itemIndicator: {
|
||||||
|
position: 'absolute',
|
||||||
|
bottom: 0,
|
||||||
|
height: 3,
|
||||||
|
left: '50%',
|
||||||
|
transform: 'translateX(-50%)',
|
||||||
minWidth: 45,
|
minWidth: 45,
|
||||||
paddingBottom: 12,
|
width: '100%',
|
||||||
borderBottomWidth: 3,
|
|
||||||
borderBottomColor: 'transparent',
|
|
||||||
},
|
},
|
||||||
outerBottomBorder: {
|
outerBottomBorder: {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
@@ -194,13 +204,20 @@ const mobileStyles = StyleSheet.create({
|
|||||||
itemInner: {
|
itemInner: {
|
||||||
flexGrow: 1,
|
flexGrow: 1,
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
|
overflowX: 'hidden',
|
||||||
},
|
},
|
||||||
itemText: {
|
itemText: {
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
|
paddingBottom: 10 + 3,
|
||||||
|
},
|
||||||
|
itemIndicator: {
|
||||||
|
position: 'absolute',
|
||||||
|
bottom: 0,
|
||||||
|
height: 3,
|
||||||
|
left: '50%',
|
||||||
|
transform: 'translateX(-50%)',
|
||||||
minWidth: 45,
|
minWidth: 45,
|
||||||
paddingBottom: 10,
|
width: '100%',
|
||||||
borderBottomWidth: 3,
|
|
||||||
borderBottomColor: 'transparent',
|
|
||||||
},
|
},
|
||||||
outerBottomBorder: {
|
outerBottomBorder: {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
|
|||||||
Reference in New Issue
Block a user