我正在尝试使用react-native-snap-carousel实现垂直轮播,我想要的是一个垂直轮播,根据react-native-snap- carousel itemHeight文档的content.As,它具有不同的轮播高度,而当涉及到垂直轮播时,sliderHeight是必需的。有没有可以根据内容大小来实现itemHeight的??
发布于 2020-05-28 15:13:56
据我所知,您希望获取内容的视图高度并将其提供给carousel项。您可以使用项目的引用来获取项目的位置和大小属性。
首先,从react导入useRef。
import { useRef } from 'react';之后,创建一个ref值。
const contentRef = useRef(null);
<View ref={contentRef}> .... </View>在此之后,您可以通过以下方式获取其属性
contentRef.nativeEvent.measureInWindow((x, y, width, height) => {
// You can do whatever you want with this data
})https://stackoverflow.com/questions/62058059
复制相似问题