flexbox-layout icon indicating copy to clipboard operation
flexbox-layout copied to clipboard

Allow to stylise flexboxLayoutManager from XML

Open vyguera opened this issue 1 year ago • 1 comments

It is possible to use layoutmanager attribute in layout xmls to use FlexboxLayoutManager as following:

<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
    app:layoutManager="com.google.android.flexbox.FlexboxLayoutManager">

The same way you can set that attribute in a style this way

<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
    android:style="@styles/MyFlexListStyle">

<resources>
    <style name="MyFlexListStyle">
        <item name="layoutManager">com.google.android.flexbox.FlexboxLayoutManager</item>
    </style>
</resources>

These PR allows you to develop a library that provides with a view/fragment/screen with a recyclerView that is styleable from the app the same way as the regular FlexboxLayout does, except for any already handled attributes (flexDirection) or unsupported ones (alignContent), so you can do the following:

<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
    android:style="@styles/MyFlexListStyle">

<resources>
    <style name="MyFlexListStyle">
        <item name="layoutManager">com.google.android.flexbox.FlexboxLayoutManager</item>
        <item name="flexWrap">wrap</item>
        <item name="justifyContent">center</item>
        <item name="alignItems">baseline</item>
        <item name="maxLine">3</item>
    </style>
</resources>

vyguera avatar Mar 06 '23 15:03 vyguera

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

google-cla[bot] avatar Mar 06 '23 15:03 google-cla[bot]