litho
litho copied to clipboard
ItemDecoration for recycler not correct
- [x] I have searched existing issues and this is not a duplicate
Version
litho-* 0.29.0 tools.build.gradle: 3.4.1
Issues and Steps to Reproduce
the result
Expected Behavior
horizontal grid have the same gap;
Link to Code
use recycler:
public static ViewGroup createRecycler(Context context) {
ComponentContext c = new ComponentContext(context);
final RecyclerBinder binder = new RecyclerBinder.Builder()
.layoutInfo(new GridLayoutInfo(context, 4))
.build(c);
Component component = MyRecycler.create(c)
.binder(binder).build();
for (int i = 0; i < 100; i++) {
binder.appendItem(Text.create(c).text("hello:" + i)
.textSizeDip(32)
.paddingDip(YogaEdge.VERTICAL, 4)
.build());
}
return LithoView.create(c, component);
}
MyRecyclerSpec:
@LayoutSpec
public class MyRecyclerSpec {
@OnCreateLayout
static Component onCreateLayout(ComponentContext c, @Prop RecyclerBinder binder) {
return Recycler.create(c)
.binder(binder)
.itemDecoration(new FduiHomeTabDecoration(false))
.build();
}
}
decoration:
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
// super.getItemOffsets(outRect, view, parent, state);
GridLayoutManager.LayoutParams layoutParams = (GridLayoutManager.LayoutParams) view.getLayoutParams();
int spanIndex = layoutParams.getSpanIndex();
switch (spanIndex) {
case 0:
outRect.set(dip8, dip8, dip4, 0);
break;
case 1:
case 2:
outRect.set(dip4, dip8, dip4, 0);
case 3:
outRect.set(dip4, dip8, dip8, 0);
}
Unfortunately I believe our support for item decorations isn't very well tested, especially when it comes to offsets and paddings. If you see a simple fix then we would welcome a PR :) cc @pasqualeanatriello
If I set a width for the grid items, the itemDecoration works well.