Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: indicator display for single tab #395

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/MaterialTabBar/Indicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@ const Indicator: React.FC<IndicatorProps> = ({
const opacity = useSharedValue(fadeIn ? 0 : 1)

const stylez = useAnimatedStyle(() => {
const transform =
itemsLayout.length > 1
? [
{
translateX: interpolate(
const transform = [
{
translateX:
itemsLayout.length > 1
? 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))
),
},
]
: undefined
)
: isRTL

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
: isRTL
: isRTL && itemsLayout[0]?.x

Because on the line below you are doing -1 * itemsLayout[0]?.x, which can result nan so check also if it exists

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This suggestion doesn't seem correct. What if x is 0?

May need to check for typeof itemsLayout[0]?.x === 'number' instead

? -1 * itemsLayout[0]?.x
andreialecu marked this conversation as resolved.
Show resolved Hide resolved
: itemsLayout[0]?.x,
},
]

const width =
itemsLayout.length > 1
Expand Down