我试图在React Native for Android中使用水平ScrollView,其中起始位置位于滚动图像的中间而不是(0,0).
该scrollTo方法似乎在内部正确调用,componentDidMount但在应用程序中没有任何移动,它仍然显示为从左侧开始滚动.
由于这是Android,我没有访问contentOffset道具或我会直接设置,根据文档.这是代码:
'use strict';
var React = require('react-native');
var {
StyleSheet,
View,
Text,
ScrollView,
Component,
} = React;
var precomputeStyle = require('precomputeStyle');
class Carousel extends Component {
constructor(props, context) {
super(props, context);
//this.changeContent = this.changeContent.bind(this);
}
componentDidMount() {
this.myScroll.scrollTo(100);
console.log("called DidMount");
}
render() {
return (
<View style={{flex: 1}}>
<ScrollView ref={(ref) => this.myScroll = ref}
contentContainerStyle={styles.container}
horizontal={true}
pagingEnabled={true}
showsHorizontalScrollIndicator={false}
bounces={true}
onMomentumScrollEnd={this.onAnimationEnd}
>
{this.props.children}
</ScrollView>
</View>
);
}
onAnimationEnd(e) { …Run Code Online (Sandbox Code Playgroud)