Skip to content

[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

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

bennycao
Copy link

@bennycao bennycao commented Feb 29, 2020

Partially solves #953

Add ChipGroup option to set maxRowCount. If set, will display chips up to maxRowCount.

Screen Shot 2020-02-29 at 6 27 43 pm

Add ChipGroup option overflowChipEnabled and overflowChipTextResource. If enabled with maxRowCount will display a chip using overflowChipTextResource (can be a PluralRes or StringRes) to set the text to display when reflow exceeds maxRowCount.

Screen Shot 2020-02-29 at 6 28 03 pm

Added a new catalog for chipgroup showing example of usage.

The use case for enabling overflowChipEnabled or even setting maxRowCount works well for display of read only (no interactions) chips. The implementation of this could include binding a onClick event on the overflow chip to navigate to an edit/selection type page of chips

  • Identify the component the PR relates to in brackets in the title.
    [Buttons] Updated documentation
  • Link to GitHub issues it solves. Partially solves https://github.com/material-components/material-components-android/issues/953
  • Sign the CLA bot. You can do this once the pull request is opened.

@wcshi
Copy link
Contributor

wcshi commented Mar 3, 2020

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.

@bennycao
Copy link
Author

bennycao commented Mar 3, 2020

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 ?

@wcshi
Copy link
Contributor

wcshi commented Mar 5, 2020

Could you please add an overflowChipSingularResource as well?

@bennycao
Copy link
Author

bennycao commented Mar 5, 2020

Could you please add an overflowChipSingularResource as well?

👍 . Is this so we can have view text that just displays more... or the like ?

@bennycao
Copy link
Author

bennycao commented Mar 6, 2020

Could you please add an overflowChipSingularResource as well?

@wcshi updated so that the attribute overflowChipPluralResource is now overflowChipTextResource and can accept a PluralRes or StringRes

Copy link
Contributor

@wcshi wcshi left a 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) {
Copy link
Contributor

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.

Copy link
Author

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

Comment on lines +152 to +158
<attr name="maxRowCount" format="integer"/>
<attr name="overflowChipEnabled" format="boolean"/>
<attr name="overflowChipPluralResource" format="reference"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

}

maxChildRight += getPaddingRight();
childBottom += getPaddingBottom();

// if we have remaining child views, adjust height to enable showing the `X more child` view on
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

2020

Comment on lines +35 to +36
/** A fragment that displays the ChipGroup Max row demos for the Catalog app. */
public class ChipGroupMaxRowsDemoFragment extends DemoFragment {
Copy link
Contributor

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

  1. doesn't explicitly state the max row count
  2. none of the chips are checkable but they are not disabled
  3. there's FAB but it doesn't do anything
  4. 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.

Copy link
Author

@bennycao bennycao Mar 7, 2020

Choose a reason for hiding this comment

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

  1. Max row count is defined in the chipgroup demo layout.
  2. Chips are displayed using a layout that makes the chips not selectable i.e. cat_chip_group_item_entry.xml
  3. Yep, fab shouldn't be there
  4. 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));
Copy link
Contributor

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?

Copy link
Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this mean?

Copy link
Author

@bennycao bennycao Mar 7, 2020

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");
Copy link
Contributor

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")) {
Copy link
Contributor

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);
Copy link
Contributor

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.

@bennycao
Copy link
Author

bennycao commented Mar 7, 2020

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.

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.

@madCode
Copy link

madCode commented Sep 30, 2020

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.

@bennycao bennycao force-pushed the feature/chip-multi-line branch from f7812b0 to ca1f179 Compare December 11, 2020 04:35
@ahulyk
Copy link

ahulyk commented Apr 26, 2021

any progress on that?

1 similar comment
@luangs7
Copy link

luangs7 commented Aug 4, 2022

any progress on that?

@bennycao
Copy link
Author

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.

@michaellee123
Copy link

I'm sad that Google does not merge this pr. Many times setting the max line is very useful. You did a good job! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants