Javascript 对本机ListView滚动进行反应,以确定其不存在';行不通

Javascript 对本机ListView滚动进行反应,以确定其不存在';行不通,javascript,listview,react-native,Javascript,Listview,React Native,我使用了ListView的scrollToEnd,但它不起作用,但它对scrollTo起作用。我该怎么处理呢 有一个解决方法,将其包装在setTimeout中,如下所示: componentDidMount() { setTimeout(() => { this.refs.dateList.scrollToEnd(); }, 50); } 试试这个: <ListView ref={ ( ref ) => this.scrollView = ref }

我使用了ListView的
scrollToEnd
,但它不起作用,但它对
scrollTo
起作用。我该怎么处理呢


有一个解决方法,将其包装在
setTimeout
中,如下所示:

componentDidMount() {
  setTimeout(() => {
    this.refs.dateList.scrollToEnd();
  }, 50);
}
试试这个:

<ListView
    ref={ ( ref ) => this.scrollView = ref }
    onContentSizeChange={ () => {        
        this.scrollView.scrollToEnd( { animated: false } )
    } } >
</ListView>
this.scrollView=ref}
onContentSizeChange={()=>{
this.scrollView.scrollToEnd({animated:false})
} } >

渲染需要时间,因此在滚动到结束之前setTimeout()将起作用。但是,您可以使用onLayout()方法

导出默认MyComponent扩展React.Component{
建造师(道具){
超级(道具)
this.scrollToBottom=this.scrollToBottom.bind(this)
}
scrollToBottom(){
this.refs.myView.scrollToEnd()
}
render(){
返回{
}
}

注意:ListView现在已被弃用。

这对我很有效

<Content ref={c => (this.contentComponent = c)}>
....Any code
</Content >

我不确定这是否可行,因为在装入视图时,ListView不必渲染所有元素。也无法知道ListView何时渲染完所有元素。当然,
scrollToEnd
方法可以与按钮一起使用。您是否遇到错误,或者它只是不做任何事情?还有,Android或iOS?@user1221780不,我没有错误,它是在iOS上运行的simulator@Eldelshell我有一个尝试,它通过一个按钮工作,但我想让ListView在开始时滚动到结尾。这是有效的,但为什么呢,我不记得我从哪里得到了这个解决方法,但我可以说我花了几个小时与这个错误作斗争…使用它是不好的做法SetTimeOut这只是因为渲染需要时间。使用onLayout和一个滚动到结尾的绑定方法:例如scrollToBottom(){this.refs.myView.scrollToEnd()}
<Content ref={c => (this.contentComponent = c)}>
....Any code
</Content >
this.contentComponent._root.scrollToPosition(0);