我正在使用顶部带有动画FlatList的React Native地图,当我按下地图标记时,我希望列表滚动到该特定索引。但是当我尝试这样做时,我得到了这个错误_this.flatListRef.scrollToIndex is not a function. '_this.flatListRef.scrollToIndex' is undefined
我的代码基础看起来像这样...
const AnimatedFlatList = Animated.createAnimatedComponent(FlatList);
export default Map extends component {
scrollToCard = index => {
this.flatListRef.scrollToIndex({index})
}
render() {
const { allProperties } = this.props;
<MapView
ref={map => this.map = map}
style={styles.map}
initialRegion={{
latitude: 35.2271,
longitude: -80.8431,
latitudeDelta: 0.0922,
longitudeDelta: 0.421
}}
>
{allProperties && allProperties.map((property, index) => (
<Marker
coordinate={property.coordinates}
title={property.propertyName}
pinColor={theme.COLOR_GREEN}
key={property.id}
onPress={() => this.scrollToCard(index)}
/>
))}
</MapView>
{allProperties &&
<AnimatedFlatList
ref={ref => {this.flatListRef = ref }} …Run Code Online (Sandbox Code Playgroud) javascript react-native react-native-maps react-native-flatlist