facebook / facebook/litho

Swipe-to-refresh behaviour breaks if RecyclerView's first item's height is set to 0

Open
#788 0 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
```groovy
def litho_version = "0.41.1"
implementation "com.facebook.litho:litho-core:$litho_version"
implementation "com.facebook.litho:litho-widget:$litho_version"
implementation "com.facebook.litho:litho-sections-core:$litho_version"
implementation "com.facebook.litho:litho-sections-widget:$litho_version"

implementation 'com.facebook.soloader:soloader:0.10.3'
````

## Issues and Steps to Reproduce
Create a RecyclerCollectionComponent with children, set the first item to EmptyComponent, or set its height to 0F, then try pulling down to refresh. it won't work.

## Expected Behavior
Pulling down should work fine and a refresh indicator should appear.

## Link to Code
CardGroupSpec.java:
```java
@GroupSectionSpec
class CardGroupSpec {

@OnCreateChildren
static Children OnCreateChildren(SectionContext c) {
Children.Builder builder = Children.create();

for (int i = 0; i < 8; i++) {
Component component = CardItem.create(c).build();

//Uncomment this line to reproduce the bug
// if (i == 0) {
// component = EmptyComponent.create(c).build(); //Also works with Text.create(c).heightDip(0f).build();
// }

builder.child(
SingleComponentSection
.create(c)
.component(component)
);
}
return builder.build();
}
}
```
CardItemSpec.java:
```java
@LayoutSpec
class CardItemSpec {

@OnCreateLayout
static Component OnCreateLayout(ComponentContext c) {
return Card
.create(c)
.marginDip(YogaEdge.ALL, 16F)
.cardBackgroundColor(Color.GRAY)
.cornerRadiusDip(16F)
.content(
Column
.create(c)
.heightDip(160f)
.build()
)
.build();
}
}
```
LithoActivity.java:
```java
public class LithoActivity extends AppCompatActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

ComponentContext componentContext = new ComponentContext(this);

RecyclerCollectionComponent recycler = RecyclerCollectionComponent
.create(componentContext)
.marginDip(YogaEdge.ALL, 16F)
.section(CardGroup.create(new SectionContext(componentContext)).build())
.build();

setContentView(LithoView.create(this, recycler));
}
}
```

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.