连FlatList本身也滚动不了
import {StyleSheet, Text, View, FlatList} from 'react-native';
import React, {useEffect, useRef} from 'react';
const data = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23,
];
export default () => {
const flatListRef = useRef();
useEffect(() => {
setTimeout(() => {
flatListRef.current?.scrollToIndex({
index: 5,
viewPosition: 0.5,
animated: true,
});
// flatListRef.current.scrollToItem({item:5, viewPosition: 0.5, animated: true});
// flatListRef.current.scrollToOffset({ offset:200, });
// flatListRef.current.scrollToEnd({animated: true});
}, 2000);
}, []);
const renderItem = ({item, index}) => {
return <Text style={styles.txt}>{`List item ${item}`}</Text>;
};
const renderItem2 = ({item, index}) => {
return <Text style={styles.txt2}>{`List item ${item}`}</Text>;
};