Skip to content

Commit 34b02a5

Browse files
committed
fix: indicators in RTL
1 parent 88000cc commit 34b02a5

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/MaterialTabBar/Indicator.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const Indicator: React.FC<IndicatorProps> = ({
1818
}) => {
1919
const opacity = useSharedValue(fadeIn ? 0 : 1)
2020

21+
const layoutForDirection = isRTL ? itemsLayout.slice().reverse() : itemsLayout
22+
2123
const stylez = useAnimatedStyle(() => {
2224
const firstItemX = itemsLayout[0]?.x ?? 0
2325

@@ -28,21 +30,18 @@ const Indicator: React.FC<IndicatorProps> = ({
2830
? interpolate(
2931
indexDecimal.value,
3032
itemsLayout.map((_, i) => i),
31-
// when in RTL mode, the X value should be inverted
32-
itemsLayout.map((v) => (isRTL ? -1 * v.x : v.x))
33+
layoutForDirection.map((v) => v.x)
3334
)
34-
: isRTL
35-
? -1 * firstItemX
36-
: firstItemX,
35+
: firstItemX,
3736
},
3837
]
3938

4039
const width =
4140
itemsLayout.length > 1
4241
? interpolate(
4342
indexDecimal.value,
44-
itemsLayout.map((_, i) => i),
45-
itemsLayout.map((v) => v.width)
43+
layoutForDirection.map((_, i) => i),
44+
layoutForDirection.map((v) => v.width)
4645
)
4746
: itemsLayout[0]?.width
4847

@@ -69,6 +68,8 @@ const styles = StyleSheet.create({
6968
backgroundColor: '#2196f3',
7069
position: 'absolute',
7170
bottom: 0,
71+
left: isRTL ? undefined : 0,
72+
right: isRTL ? 0 : undefined,
7273
},
7374
})
7475

0 commit comments

Comments
 (0)