-
Notifications
You must be signed in to change notification settings - Fork 734
Fix error when passing a signle item to TabController #1578
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
Conversation
const itemsWidthsAnimated = useSharedValue(_.times(Math.max(itemsCount, 2), () => 0)); | ||
const itemsOffsetsAnimated = useSharedValue(_.times(Math.max(itemsCount, 2), () => 0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a simple solution, but it feels technically incorrect since we're returning an array with a length of 2 instead of 1.
However, when testing for another solution it will probably be more code change than this.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I preferred a simple fix.
TBH, I initially thought about not supporting it all and instead throw an appropriate error to the users that they must pass at least two items. WDYT?
I don't see a reason to use TabController for a single page..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like a possible solution.
Is there an option in one of our apps where there can be a single tab? If it is possible, then maybe we should handle it and not force the users to have an if\else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's relevant..
The person who reported the issue, just played with the component and passed a single item, but it wasn't his intention so it wasn't really a problem.
So I think having an appropriate error message in this case will be suffice...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I added a console.error instead of throwing and handled the issue a little better (I think)
Let me know what u think..
… the issue gracefully
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understood where this came from; I'd consider adding something like:
<View style={[styles.selectedIndicator, {left: indicatorInsets, width: itemsWidthsAnimated.value[0] - 2 * indicatorInsets}]}/>
so the indicator is seen, but I know you prefer less code --> merge if I'm right.
Either way (with the indicator or without it) it doesn't look great. |
Description
Fix exception when passing a single item to TabController
Changelog
Fix exception when passing a single item to TabController