facebook / facebook/litho

ItemDecoration for recycler not correct

Open
#571 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
7.8k
Forks
768
PR merge metrics
No merged PRs in 30d

Description

- [x] I have searched [existing issues](https://github.com/facebook/litho/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
![WeWork Helper20190726030201](https://user-images.githubusercontent.com/5860185/61932595-5ebf1300-afb6-11e9-8624-d797ef4aa075.png)

## 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);
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.