Skip to content

scrollToIndex causes blank screen when used with maintainVisibleContentPosition #266

@tannguyen05

Description

@tannguyen05

Description

When using the maintainVisibleContentPosition prop together with the scrollToIndex method, the list turns blank and does not scroll to the specified index.
If I remove the maintainVisibleContentPosition prop, then scrollToIndex works as expected.


Environment

  • react-native: 0.79.2
  • @legendapp/list: 1.0.17

Reproduction

I'll attach a code snippet and a screen recording video demonstrating the issue.

<Button
  title="scroll to index 40"
  onPress={() => {
    listRef.current?.scrollToIndex({
      index: 40,
      animated: true,
    });
  }}
/>
<LegendList
  ref={listRef}
  data={messages}
  keyExtractor={item => `msg-${item.id}`}
  renderItem={renderItem}
  recycleItems={true}
  maintainScrollAtEnd
  alignItemsAtEnd
  maintainVisibleContentPosition
  onStartReachedThreshold={0.1}
  onStartReached={onStartReached}
  onEndReached={({distanceFromEnd}) => {
    if (distanceFromEnd > 0) {
      onEndReached();
    }
  }}
/>

with maintainVisibleContentPosition
https://github.com/user-attachments/assets/0c720fba-3d1f-4efc-9605-ee57c73f797e

without maintainVisibleContentPosition
https://github.com/user-attachments/assets/4ea1c18b-6ef8-440e-8101-b34af9102796

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions