Skip to content

Commit

Permalink
fix: indicators in RTL
Browse files Browse the repository at this point in the history
  • Loading branch information
msynowski committed Oct 28, 2024
1 parent 88000cc commit 34b02a5
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/MaterialTabBar/Indicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const Indicator: React.FC<IndicatorProps> = ({
}) => {
const opacity = useSharedValue(fadeIn ? 0 : 1)

const layoutForDirection = isRTL ? itemsLayout.slice().reverse() : itemsLayout

const stylez = useAnimatedStyle(() => {
const firstItemX = itemsLayout[0]?.x ?? 0

Expand All @@ -28,21 +30,18 @@ const Indicator: React.FC<IndicatorProps> = ({
? interpolate(
indexDecimal.value,
itemsLayout.map((_, i) => i),
// when in RTL mode, the X value should be inverted
itemsLayout.map((v) => (isRTL ? -1 * v.x : v.x))
layoutForDirection.map((v) => v.x)
)
: isRTL
? -1 * firstItemX
: firstItemX,
: firstItemX,
},
]

const width =
itemsLayout.length > 1
? interpolate(
indexDecimal.value,
itemsLayout.map((_, i) => i),
itemsLayout.map((v) => v.width)
layoutForDirection.map((_, i) => i),
layoutForDirection.map((v) => v.width)
)
: itemsLayout[0]?.width

Expand All @@ -69,6 +68,8 @@ const styles = StyleSheet.create({
backgroundColor: '#2196f3',
position: 'absolute',
bottom: 0,
left: isRTL ? undefined : 0,
right: isRTL ? 0 : undefined,
},
})

Expand Down

0 comments on commit 34b02a5

Please sign in to comment.