google / flexbox-layout

Flexbox for Android
Apache License 2.0
18.24k stars 1.79k forks source link

Children Flexbox XML attributes are not supported with FlexboxLayoutManager #571

Open FabioCZ opened 3 years ago

FabioCZ commented 3 years ago

Issues and steps to reproduce

If any of your RecyclerView Viewholder items are inflated from XML, and those XML layouts use any of the Attributes for the children of a FlexboxLayout, for example app:layout_wrapBefore="true", then those attributes do not actually get applied to that item at runtime. The only way to set those flex attributes is programmatically, which is quite cumbersome.

Expected behavior

It would be great if the XML attributes on Viewholder items were respected.

Code-wise, it'd be a simple change. The FlexboxLayoutManager.LayoutParams constructor LayoutParams(Context c, AttributeSet attrs) (https://github.com/google/flexbox-layout/blob/master/flexbox/src/main/java/com/google/android/flexbox/FlexboxLayoutManager.java#L2754) would have to be modified to extract the XML attributes and apply them (with the exception of layout_order, which is not supported).

I'd be happy to create a PR with this, but wanted to check first if this is a desired functionality.

Version of the flexbox library

2.0.1

Link to code

In this small sample, theapp:layout_wrapBefore="true" attribute on the ViewHolder is not respected and the item would not wrap to a new row when used with FlexboxLayoutManager

marciogranzotto commented 2 years ago

I just spent my whole day trying to figure out why this wasn't working. Then I tried to set the layout params in my ViewHolder class and it did work...

I think we really need this