google / flexbox-layout

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

Allow to stylise flexboxLayoutManager from XML #621

Open vyguera opened 1 year ago

vyguera commented 1 year ago

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>
google-cla[bot] commented 1 year ago

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.