-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[ChipGroup] Allow the option to set max rows of chips to display for a chip group #1071
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
base: master
Are you sure you want to change the base?
[ChipGroup] Allow the option to set max rows of chips to display for a chip group #1071
Conversation
It's great to see that you have a chip showing how many more chips are available, however, I think it would make sense if it was on the 2nd row instead of an additional row. |
I think having it on the 2nd or new row can depend on the design requirements. This possibly could be a choice as opposed to a rule ? |
Could you please add an overflowChipSingularResource as well? |
👍 . Is this so we can have view text that just displays |
@wcshi updated so that the attribute |
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 is not a comprehensive set of comments, there are still problems, we are considering opening up the api so this could be an extension instead.
@@ -144,6 +180,12 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | |||
// not confined to a single line, move this child to the next line and reset its left bound to | |||
// flowlayout's left bound. | |||
if (childRight > maxRight && !isSingleLine()) { | |||
rowCount++; | |||
|
|||
if (this.maxRowCount > 1 && this.maxRowCount <= rowCount) { |
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.
Why is this > 1 instead of 0? While a bit silly, a user could set maxRowCount to 1 and not want them to scroll off the screen.
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.
yeah, good point this was an oversight
<attr name="maxRowCount" format="integer"/> | ||
<attr name="overflowChipEnabled" format="boolean"/> | ||
<attr name="overflowChipPluralResource" format="reference"/> |
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.
Please add these attributes to public.xml
} | ||
|
||
maxChildRight += getPaddingRight(); | ||
childBottom += getPaddingBottom(); | ||
|
||
// if we have remaining child views, adjust height to enable showing the `X more child` view on |
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.
s/we have remaining/there are more
@@ -0,0 +1,89 @@ | |||
/* | |||
* Copyright 2017 The Android Open Source Project |
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.
2020
/** A fragment that displays the ChipGroup Max row demos for the Catalog app. */ | ||
public class ChipGroupMaxRowsDemoFragment extends DemoFragment { |
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 demo is a bit confusing
- doesn't explicitly state the max row count
- none of the chips are checkable but they are not disabled
- there's FAB but it doesn't do anything
- Clicking on the 7 more cities chip doesn't expand to show the rest of the chips
It would be great if the demo displayed and let the user adjust the maxRowCount.
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.
- Max row count is defined in the chipgroup demo layout.
- Chips are displayed using a layout that makes the chips not selectable i.e. cat_chip_group_item_entry.xml
- Yep, fab shouldn't be there
- I didn't want to force the behaviour on what clicking on the 7 more cities chip to do. This i think should be a decision of the implementer. Possibly define a onClick listener for the overflow chip ?
@@ -135,6 +137,9 @@ public ChipGroup(Context context, AttributeSet attrs, int defStyleAttr) { | |||
setChipSpacingVertical( | |||
a.getDimensionPixelOffset(R.styleable.ChipGroup_chipSpacingVertical, chipSpacing)); | |||
setSingleLine(a.getBoolean(R.styleable.ChipGroup_singleLine, false)); | |||
setMaxRowCount(a.getInt(R.styleable.ChipGroup_maxRowCount, 0)); | |||
setOverflowChipEnabled(a.getBoolean(R.styleable.ChipGroup_overflowChipEnabled, false)); |
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.
Under what circumstances do we want this to be false?
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.
If it's decided that you never can have a maxRowCount defined and not show a overflow chip then, no, it could never be false. Is this something that should be a standard or not optional ?
View child = this.getChildAt(this.getChildCount() - 1); | ||
|
||
if (child.getVisibility() != View.GONE) { | ||
// need to assign TextView text here, otherwise measurement of view width will be wrong |
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.
What does this mean?
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.
Reasoning behind this is, if the overflow chip is to be displayed on the same row as other chips, and fits, we need to know what the width is, hence adding the resource text to the chip. Which then we can have a correct measure of the overflow chip. And whether reflow is required.
} else if (getResourceNameTypeName(this.overflowChildTextResource).equals("string")) { | ||
((TextView) child).setText(getContext().getResources().getString(this.overflowChildTextResource)); | ||
} else { | ||
throw new InvalidParameterException("overflowChildTextResource can only be a plural or string resource"); |
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.
Validation during on measure is expensive and unnecessary, please move this into the setter.
this.overflowChildTextResource, remainingItems, remainingItems | ||
) | ||
); | ||
} else if (getResourceNameTypeName(this.overflowChildTextResource).equals("string")) { |
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.
On second thought, the api should require/only support a PluralRes so that the user supplies the appropriate unit for singular or plural left over child views.
// if we have remaining child views, adjust height to enable showing the `X more child` view on | ||
// next line | ||
if (this.overflowChildEnabled && remainingItems > 0) { | ||
View child = this.getChildAt(this.getChildCount() - 1); |
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 alters the text of the last child view so that the user cannot display the original context, this is not okay.
This is a starting point on what direction we want to take it. As i see it, i don't see a usecase where we would want to limit the display rows and have any chips selectable when you don't show all the chips available. Hence ideally the only reason you would have a max row count is in a read only state. And the implementer can choose to decide how they want to proceed to a editable/selectable like display. This can be a new screen or the re-render of the chipgroup without a max row defined. Will take your lead on this on how to proceed on this feature. Happy to help where i can. |
Any chance this will be resolved and merged soon? Super excited for the option to set a max number of rows and have the ChipGroup know how to scroll from there. I'd like to display a bunch of actionable chips that a user can click, but want more than just one row of chips. I'd rather have a scrollable grid with a customizable number of rows of chips. |
…h accepts a stringres or pluralres)
…rce which accepts a stringres or pluralres)" This reverts commit 999d5bb.
f7812b0
to
ca1f179
Compare
any progress on that? |
1 similar comment
any progress on that? |
Hi all, sorry for such a delay on my side on responding to the interest of this feature. As it seems, there doesn't seem to be an appetite from their end to have this feature as a feature on the materials component. This has been open for a long time and not sure if google are willing to revisit. There is also what looks like similar issue/request #696 which has a long timeline. |
I'm sad that Google does not merge this pr. Many times setting the max line is very useful. You did a good job! 👍 |
Partially solves #953
Add ChipGroup option to set
maxRowCount
. If set, will display chips up tomaxRowCount
.Add ChipGroup option
overflowChipEnabled
andoverflowChipTextResource
. If enabled withmaxRowCount
will display a chip usingoverflowChipTextResource
(can be a PluralRes or StringRes) to set the text to display when reflow exceedsmaxRowCount
.Added a new catalog for chipgroup showing example of usage.
The use case for enabling
overflowChipEnabled
or even settingmaxRowCount
works well for display ofread only
(no interactions) chips. The implementation of this could include binding aonClick
event on the overflow chip to navigate to an edit/selection type page of chips[Buttons] Updated documentation
Partially solves https://github.com/material-components/material-components-android/issues/953