I’m utilizing a SectionList in React Native to show a number of sections with a number of objects in every part. I’m programmatically scrolling to particular sections and objects utilizing the scrollToLocation methodology.
The problem I’m dealing with is that if I try and scroll to an merchandise with an itemIndex of 0, the SectionList all the time scrolls to the primary merchandise of the primary part, whatever the sectionIndex I present. If the itemIndex is larger than 0, the scrolling works as anticipated and goes to the proper part and merchandise. The problem is going on in iOS. Here is a simplified code to breed the problem:
import React, { useRef } from "react";
import { SectionList, View, Textual content, Button, StyleSheet, StatusBar } from "react-native";
const App = () => {
const sectionListRef = useRef(null);
const sections = Array.from({ size: 10 }, (_, sectionIndex) => ({
title: `Part ${sectionIndex + 1}`,
knowledge: Array.from({ size: 30 }, (_, itemIndex) => `Merchandise ${sectionIndex + 1}.${itemIndex + 1}`),
}));
// Scroll to the primary merchandise of the primary part
const scrollToFirstSection = () => {
sectionListRef.present?.scrollToLocation({
sectionIndex: 0,
itemIndex: 0,
viewPosition: 0.5, // Heart the merchandise within the view
});
};
// Scroll to the primary merchandise of the 4th part
const scrollToSecondSection = () => {
sectionListRef.present?.scrollToLocation({
sectionIndex: 3,
itemIndex: 0,
viewPosition: 0.5, // Heart the merchandise within the view
});
};
return (
It may very well be examined in expo-snack as nicely.