是否可以<ScrollView>在React Native中获取当前滚动位置或组件的当前页面?
所以类似于:
<ScrollView
horizontal={true}
pagingEnabled={true}
onScrollAnimationEnd={() => {
// get this scrollview's current page or x/y scroll position
}}>
this.state.data.map(function(e, i) {
<ImageCt key={i}></ImageCt>
})
</ScrollView>
Run Code Online (Sandbox Code Playgroud) 我希望有2个div大小到特定宽度(即500px).一个在另一个之上水平对齐.
顶部框应隐藏其滚动条,底部应显示滚动条,当用户滚动时,我希望顶部框的偏移更改为底部框的值.因此,当底部DIV水平滚动时,顶部DIV也会同时滚动.
如果它让这个过程更容易,我很高兴在Jquery中这样做.
我拼凑了Microsoft Excel的工作版本,如"冻结痛苦"视图.列标题水平滚动内容,行标题垂直滚动内容,但当滚动另一个时,每个标题都"卡在"位置.
你可以在这里试试工作版.
它不是最佳的,因为如果你停止一个轻弹的滚动或只是滑动很多东西它会口吃.
该方法使用了几种技术,但导致问题的方法是同步滚动视图.
由于这里列出,我已经试过设置useNativeDriver: true,这需要改变
ScrollView,以Animated.ScrollView和
ref={ref => (this.instance = ref)}到ref={ref => (this.instance = ref._component)}
但随后的同步云完全失控.
我喜欢更优化方法的想法.如何改进?
import React from 'react';
import { ScrollView, Animated, Text, View } from 'react-native';
export default class SyncScrollTest extends React.Component {
constructor() {
super();
this.scrollPosition = new Animated.Value(0);
this.scrollEvent = Animated.event(
[{ nativeEvent: { contentOffset: { y: this.scrollPosition } } }],
{ useNativeDriver: false },
);
}
render() {
return (
<View style={{ flex: …Run Code Online (Sandbox Code Playgroud)