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

[Tabs] Fix tab indicator size #3336

Closed

Conversation

pubiqq
Copy link
Contributor

@pubiqq pubiqq commented Apr 4, 2023

Fixes #3335

@drchen
Copy link
Contributor

drchen commented Apr 6, 2023

Thanks for the PR! Can you explain what's the root cause of the issue and how the PR fixes it?

@pubiqq
Copy link
Contributor Author

pubiqq commented Apr 6, 2023

textView and iconView are not direct children of TabView on API 17 and below (see inflateAndAddDefaultTextView() and inflateAndAddDefaultIconView()), so getLeft()/getRight()/getTop()/getBottom() methods cannot be used to determine the position of these views relative to TabView. This PR fixes the issue by replacing incorrect views with direct TabView children.

Also, in the PR, view.getVisibility() == View.VISIBLE is replaced with view.getVisibility() != View.GONE, because invisible elements also take up space, and therefore should be taken into account when determining the content size.

@pubiqq pubiqq force-pushed the tabs/correct-indicator-size branch from 6bf139b to 431b7a3 Compare April 6, 2023 23:42
@drchen
Copy link
Contributor

drchen commented Apr 10, 2023

The original implementation is kind of error-prone, therefore I'm a bit worried about just checking all children can introduce different unexpected bugs.

Instead of that, for now can we fix this in a more conservative way? Like checking BadgeUtils.USE_COMPAT_PARENT to decide if we should use textView.getLeft() or textViewParent.getLeft()? (Same for iconView)

And if customView is not null, maybe we should just skip checking iconView and textView.

Let me know what you think.

@pubiqq
Copy link
Contributor Author

pubiqq commented Apr 14, 2023

I don't think it's worth doing.

TabView can have only one of the three view hierarchy configurations:

// #1 For custom view
TabView { CustomView() }

// #2 For icon and/or text (API 18+)
TabView { Icon(), Text() }

// #3 For icon and/or text (API 17-)
TabView { 
    FrameLayout(wrap_content, wrap_content) { Icon() }, 
    FrameLayout(wrap_content, wrap_content) { Text() } 
}

The "PR" way and the "conservative" way will work the same in these cases, but the "PR" way will have a simpler implementation, it's more logically correct, and it's consistent with the behavior of a tab with a custom view set.

@drchen
Copy link
Contributor

drchen commented Apr 19, 2023

The behavior is the same in the current happy flow, yes. : )

However clients can actually add any random view to a tab view, and the implementation of tab view might also changed in the future as well.

If you insist, I can bring this to the internal review and see how the team thinks.

@drchen drchen self-assigned this Apr 24, 2023
@pubiqq
Copy link
Contributor Author

pubiqq commented Apr 24, 2023

However clients can actually add any random view to a tab view, and the implementation of tab view might also changed in the future as well.

This is unlikely, but even if so, the added views will become part of the TabView content and logically should be accounted for in the getContentWidth() and getContentHeight() methods (just as it happens with the custom view). So changing behavior in such an unlikely case is more of a fix than a breakdown.

@pubiqq pubiqq force-pushed the tabs/correct-indicator-size branch from 431b7a3 to 9d2d6cc Compare August 24, 2023 02:07
@pubiqq pubiqq mentioned this pull request Oct 2, 2023
@drchen drchen assigned dsn5ft and unassigned drchen Dec 11, 2023
@drchen
Copy link
Contributor

drchen commented Dec 11, 2023

Dan, can you provide your thoughts here?

@dsn5ft
Copy link
Contributor

dsn5ft commented Dec 15, 2023

The fix seems reasonable to me, but I think we don't need it anymore now that the minSdkVersion is 19 for our library (and all androidx libraries).

Closing the PR but feel free to comment or reopen if you feel it is still necessary.

@dsn5ft dsn5ft closed this Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Tabs] Incorrect tab indicator size
3 participants