Skip to content

Commit f6aecf5

Browse files
authored
Give minWidth to tab indicator only (bluesky-social#7095)
1 parent 41228dc commit f6aecf5

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed

src/view/com/pager/TabBar.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,25 @@ export function TabBar({
237237
opacity: 0,
238238
}
239239
}
240+
241+
function getScaleX(index: number) {
242+
const textWidth = textLayoutsValue[index].width
243+
const itemWidth = layoutsValue[index].width
244+
const minIndicatorWidth = 45
245+
const maxIndicatorWidth = itemWidth - 2 * CONTENT_PADDING
246+
const indicatorWidth = Math.min(
247+
Math.max(minIndicatorWidth, textWidth),
248+
maxIndicatorWidth,
249+
)
250+
return indicatorWidth / contentSize.get()
251+
}
252+
240253
if (textLayoutsValue.length === 1) {
241254
return {
242255
opacity: 1,
243256
transform: [
244257
{
245-
scaleX: textLayoutsValue[0].width / contentSize.get(),
258+
scaleX: getScaleX(0),
246259
},
247260
],
248261
}
@@ -261,7 +274,7 @@ export function TabBar({
261274
scaleX: interpolate(
262275
dragProgress.get(),
263276
textLayoutsValue.map((l, i) => i),
264-
textLayoutsValue.map(l => l.width / contentSize.get()),
277+
textLayoutsValue.map((l, i) => getScaleX(i)),
265278
),
266279
},
267280
],
@@ -429,7 +442,6 @@ const styles = StyleSheet.create({
429442
},
430443
itemText: {
431444
lineHeight: 20,
432-
minWidth: 45,
433445
textAlign: 'center',
434446
},
435447
outerBottomBorder: {

src/view/com/pager/TabBar.web.tsx

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,12 @@ export function TabBar({
2525
testID,
2626
selectedPage,
2727
items,
28-
indicatorColor,
2928
onSelect,
3029
onPressSelected,
3130
}: TabBarProps) {
3231
const t = useTheme()
3332
const scrollElRef = useRef<ScrollView>(null)
3433
const itemRefs = useRef<Array<Element>>([])
35-
const indicatorStyle = {
36-
borderBottomColor: indicatorColor || t.palette.primary_500,
37-
}
3834
const {gtMobile} = useBreakpoints()
3935
const styles = gtMobile ? desktopStyles : mobileStyles
4036

@@ -122,12 +118,19 @@ export function TabBar({
122118
style={[
123119
styles.itemText,
124120
selected ? t.atoms.text : t.atoms.text_contrast_medium,
125-
selected && indicatorStyle,
126121
a.text_md,
127122
a.font_bold,
128123
{lineHeight: 20},
129124
]}>
130125
{item}
126+
<View
127+
style={[
128+
styles.itemIndicator,
129+
selected && {
130+
backgroundColor: t.palette.primary_500,
131+
},
132+
]}
133+
/>
131134
</Text>
132135
</View>
133136
</PressableWithHover>
@@ -158,13 +161,20 @@ const desktopStyles = StyleSheet.create({
158161
},
159162
itemInner: {
160163
alignItems: 'center',
164+
overflowX: 'hidden',
161165
},
162166
itemText: {
163167
textAlign: 'center',
168+
paddingBottom: 10 + 3,
169+
},
170+
itemIndicator: {
171+
position: 'absolute',
172+
bottom: 0,
173+
height: 3,
174+
left: '50%',
175+
transform: 'translateX(-50%)',
164176
minWidth: 45,
165-
paddingBottom: 12,
166-
borderBottomWidth: 3,
167-
borderBottomColor: 'transparent',
177+
width: '100%',
168178
},
169179
outerBottomBorder: {
170180
position: 'absolute',
@@ -194,13 +204,20 @@ const mobileStyles = StyleSheet.create({
194204
itemInner: {
195205
flexGrow: 1,
196206
alignItems: 'center',
207+
overflowX: 'hidden',
197208
},
198209
itemText: {
199210
textAlign: 'center',
211+
paddingBottom: 10 + 3,
212+
},
213+
itemIndicator: {
214+
position: 'absolute',
215+
bottom: 0,
216+
height: 3,
217+
left: '50%',
218+
transform: 'translateX(-50%)',
200219
minWidth: 45,
201-
paddingBottom: 10,
202-
borderBottomWidth: 3,
203-
borderBottomColor: 'transparent',
220+
width: '100%',
204221
},
205222
outerBottomBorder: {
206223
position: 'absolute',

0 commit comments

Comments
 (0)