After FlexboxLayoutManager is restored from saved state, i.e. fragment is re added via ViewPager all items are shifted up or down.
When FlexboxLayoutManager saves state, it saves getDecoratedLeft() to mAnchorOffset and after restore it eventually applies left to childTop so all children is shifted up or down
Re add fragment to force FlexboxLayoutManager to be restored from saved instance
Demo
When items are added the first time top is 0:
MyTextView@3d17f07 layout: l = [123], t = [0], r = [237], b = [75]
MyTextView@ba1665d layout: l = [483], t = [0], r = [597], b = [75]
MyTextView@17d04a3 layout: l = [843], t = [0], r = [957], b = [75]
MyTextView@3d17f07 layout: l = [123], t = [0], r = [237], b = [75]
MyTextView@ba1665d layout: l = [483], t = [0], r = [597], b = [75]
MyTextView@17d04a3 layout: l = [843], t = [0], r = [957], b = [75]
MyTextView@3d17f07 layout: l = [123], t = [0], r = [237], b = [75]
MyTextView@ba1665d layout: l = [483], t = [0], r = [597], b = [75]
MyTextView@17d04a3 layout: l = [843], t = [0], r = [957], b = [75]
When flex box is restored from saved instance top is now equals fist item left value, i.e. 123:
MyTextView@824fdfc layout: l = [123], t = [123], r = [237], b = [198]
MyTextView@d49dada layout: l = [483], t = [123], r = [597], b = [198]
MyTextView@6c1fde8 layout: l = [843], t = [123], r = [957], b = [198]
MyTextView@824fdfc layout: l = [123], t = [48], r = [237], b = [123]
MyTextView@d49dada layout: l = [483], t = [48], r = [597], b = [123]
MyTextView@6c1fde8 layout: l = [843], t = [48], r = [957], b = [123]
MyTextView@824fdfc layout: l = [123], t = [123], r = [237], b = [198]
MyTextView@d49dada layout: l = [483], t = [123], r = [597], b = [198]
MyTextView@6c1fde8 layout: l = [843], t = [123], r = [957], b = [198]
MyTextView@824fdfc layout: l = [123], t = [48], r = [237], b = [123]
MyTextView@d49dada layout: l = [483], t = [48], r = [597], b = [123]
MyTextView@6c1fde8 layout: l = [843], t = [48], r = [957], b = [123]
Affected JustifyContent:
SPACE_AROUND
CENTER
SPACE_EVENLY
FLEX_END
Note: the only one that is working fine is FLEX_START and SPACE_BETWEEN
Expected behavior
All items should be shown
Version of the flexbox library
1.1.0
2.0.1
Workaround
There is a temporary workaround that may not work for everyone - disable save state:
Description
After
FlexboxLayoutManager
is restored from saved state, i.e. fragment is re added viaViewPager
all items are shifted up or down.When
FlexboxLayoutManager
saves state, it savesgetDecoratedLeft()
tomAnchorOffset
and after restore it eventually appliesleft
tochildTop
so all children is shifted up or downIssues and steps to reproduce
Preconditions
RecyclerView
:FlexboxLayoutManager
to be restored from saved instanceDemo
When items are added the first time
top
is0
:When flex box is restored from saved instance top is now equals fist item left value, i.e.
123
:Affected
JustifyContent
:SPACE_AROUND
CENTER
SPACE_EVENLY
FLEX_END
Note: the only one that is working fine is
FLEX_START
andSPACE_BETWEEN
Expected behavior
All items should be shown
Version of the flexbox library
1.1.0
2.0.1
Workaround
There is a temporary workaround that may not work for everyone - disable save state:
Link to code
https://github.com/vovkab/flexbox-space-evenly-bug
Original video:
https://drive.google.com/file/d/1D7MRqiUx2kRfvAHp4AJKJcRI_l73Eobx/view?usp=sharing