我的反应本机应用程序中有此类别过滤器组件。第一次加载该组件时,它不会滚动到给定的索引项(即 3)。我检查了一下,该函数scrollToIndex正在调用。但是加载屏幕后,当组件重新渲染时它就可以工作了。
为什么它在第一次加载屏幕时不向下滚动?
import React, { useCallback, useRef } from 'react'
import { StyleSheet, TouchableOpacity, FlatList, View } from 'react-native'
import { Badge, Text } from 'native-base'
import { connect } from 'react-redux'
import * as categoryActions from '../../Redux/Actions/categoryActions'
import { useFocusEffect } from '@react-navigation/native'
const CategoryFilter = (props) => {
const flatlistRef = useRef()
const handleSetSelectedCategoryId = (categoryId) => {
props.setSelectedCategoryId(categoryId)
}
const getItemLayout = (data, index) => ({
length: 50,
offset: 50 * index,
index,
}) …Run Code Online (Sandbox Code Playgroud)