facebook/litho

LithoView couldn't be shown when scrolled up inside a ScrollView

ihenk opened this issue · 2 comments

ihenk commented

Version

0.39.0

Issues and Steps to Reproduce

Hi, there. There is a SrollView that includes a LinearLayout as its root view. The LinearLayout contains a top view and a LithoView. The height of the top view is beyond screen height. The LithoView couldn't be shown when I scrolled up the screen, but I can see it occupies the height I set. Is there something wrong? I'm looking forward to hearing from you. Thank you.
image

Expected Behavior

The LithoView should be shown when scrolled up the screen. If I set the height of the top view less than screen height, LithoView shows immediately.
image

Link to Code

activity_main.xml
`

<LinearLayout
    android:id="@+id/containView"
    android:layout_width="match_parent"
    android:layout_height="1000dp"
    android:orientation="vertical"
    >

    <View
        android:id="@+id/topView"
        android:layout_width="match_parent"
        android:layout_height="1000dp"
        android:background="@android:color/holo_blue_light"
        />

</LinearLayout>

`

MainActivity.java
`public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SoLoader.init(this, false);

    setContentView(R.layout.activity_main);

    LinearLayout container = findViewById(R.id.containView);

    ComponentContext context = new ComponentContext(this);
    container.addView(LithoView.create(this,
            Text.create(context).widthPercent(100).backgroundColor(Color.GREEN).alignment(TextAlignment.CENTER).text("This is a Litho Text").heightDip(50)
                    .build()));
}

}`

Demo

QDynamicLib.zip

You have to perform a manual incremental mount for the LithoView. This part of the docs explains it.

When the visible bounds of the ScrollView change, you have to let Litho know. This snippet of code should solve your issue. Let me know if you have any more questions.

scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
            
           @Override
            public void onScrollChanged() {
                lithoView.notifyVisibleBoundsChanged();
            }
 });
ihenk commented

My bad. I didn't notice that. I set 'incrementalMount(false)' as a solution before. Thanks @akotra1999