react / react/react-native

SectionList - maintainVisibleContentPosition not working as expected.

Đang mở
#30,775 10 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Bug Component: SectionList Never gets stale Platform: Android
Ngôn ngữ chính
C++
Star
127k
Fork
25.3k
Merge trung bình
1 ngày 23 giờ
Pull request đã merge (30 ngày)
4

Mô tả

Description

I am implementing a bidirectional chat. When prepending bubble messages to my sectionlist, the look-and-feel is not smoothy, the scroll position is auto-scrolled to the top. In other words, the new content inserted at the top is moving down the current visible content.

Testing on iPhone 11 pro, iOS 14.3

React Native version:

System:
OS: Windows 10 10.0.19041
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Memory: 8.07 GB / 15.85 GB
Binaries:
Node: 12.18.1 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.14.5 - C:\Program Files\nodejs\npm.CMD
Watchman: Not Found
SDKs:
Android SDK: Not Found
Windows SDK: Not Found
IDEs:
Android Studio: Version 3.6.0.0 AI-192.7142.36.36.6241897
Visual Studio: Not Found
Languages:
Java: 1.8.0_221
Python: 3.7.4
npmPackages:
@react-native-community/cli: Not Found
react: ^16.13.1 => 16.14.0
react-native: ^0.63.4 => 0.63.4
react-native-windows: ^0.63.16 => 0.63.16

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. Create a bidirectional SectionList with pagination.
  2. Prepend 20 items to it when top reached.

const keyExtractor = useCallback(({ id }) => id, []);

const renderItem = useCallback(({ item, index }) => {
  const { content, date, mine } = item;

  const { onBubbleLongPress } = props;

  return (
    <View
      onLayout={(event) => {
        itemHeights.current[index] = event.nativeEvent.layout.height;
      }}
    >
      <Bubble
        content={content}
        date={date}
        mine={mine}
        onLongPress={() => onBubbleLongPress?.(item)}
      />
    </View>
  );
}, []);


const handleOnScroll = ({ nativeEvent }) => {
  if (isScrollCloseToTop(nativeEvent)) {
    props.onStartReached?.();
  }
};

const isScrollCloseToTop = ({ contentOffset, contentSize }) => {
   const currentYOffset = contentOffset.y;
   const diff = currentYOffset - lastYOffset.current;
   lastYOffset.current = contentOffset.y;
   // Close to top when scrolling to the top and distance is <= 30% content's height
   return diff < 0 && contentOffset.y <= 0.3 * contentSize.height;
};

return (
   <SectionList
      sections={sections}
      keyExtractor={keyExtractor}
      renderItem={renderItem}
      renderSectionHeader={renderSectionHeader}
      onScroll={handleOnScroll}
      maintainVisibleContentPosition={{
        minIndexForVisible: 0,
      }}
  />
);

      

Expected Results

New content not moving down the current visible content.

Snack, code example, screenshot, or link to a repository:

I am getting the same behaviour of this snack https://snack.expo.io/@rainliu123/flatlisttest

Note: not only for the first prepend. For all of them.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với bản tái hiện SectionList được mô tả trong issue và chạy Expo Snack được liên kết. Tái hiện danh sách hai chiều bằng cách thêm 20 mục vào đầu danh sách với maintainVisibleContentPosition được đặt thành minIndexForVisible: 0, sau đó so sánh chuyển động cuộn quan sát được với kết quả mong đợi là nội dung hiển thị không di chuyển. Issue không xác định tệp nguồn hoặc bài kiểm thử.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, react-native
Lĩnh vực
mobile
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.