google / flexbox-layout

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

Count of FlexboxLayout changes in Recycler view After NotifyDataChange Call #563

Open parmarravi opened 3 years ago

parmarravi commented 3 years ago

Issues and steps to reproduce

I have a recycler view with flex layout, when the Notify data change is called the flex layout changes the row count to 3 from 4 and the text gets a break.

In an adapter, I am updating the item row with background color and font to bold when the user taps any item.

Is there a way to update or recall the flexBox layout as I think the size of the font changes thus making the layout buggy when an item is selected?

Expected behavior

the layout should get wrapped as per item in recycler view even after Ui change when notify data change is called.

Version of the flexbox library

2.0.1

Link to code

layoutManager = new FlexboxLayoutManager(context);
layoutManager.setFlexDirection(FlexDirection.ROW);
layoutManager.setJustifyContent(JustifyContent.SPACE_EVENLY);
layoutManager.setAlignItems(AlignItems.CENTER);
layoutManager.setFlexWrap(FlexWrap.WRAP);
recyclerViewMoods.setLayoutManager(layoutManager);

Adapter Code

 ViewGroup.LayoutParams lp = moodButtonTag.getLayoutParams();
            if (lp instanceof FlexboxLayoutManager.LayoutParams) {
                FlexboxLayoutManager.LayoutParams flexboxLp = (FlexboxLayoutManager.LayoutParams)  moodButtonTag.getLayoutParams();
                // flexboxLp.setFlexGrow(1.0f);
                //flexboxLp.setFlexShrink(1.0f);
                //  flexboxLp.setAlignSelf(AlignItems.STRETCH);
                // flexboxLp.set(JustifyContent.SPACE_EVENLY);
                flexboxLp.setAlignSelf(AlignItems.FLEX_START);
            }