在React-Native中滚动到页面顶部

时间:2018-01-06 11:56:03

标签: list react-native scrolltop

在原生页面中,如果我触摸第二个列表中的任何项目(Header之后),我必须显示页面的顶部(第一个列表 - 顶部)。我尝试了this.refs.listRef.scrollTo({x: 0, y: 0, animated: true}),但它没有解决我的问题

<Content>
          <ScrollView ref="listRef">
            <View style={{backgroundColor:'#e0e0e0'}}>
              {InvoiceStore.invoice_response2==2?<View>
              {InvoiceStore.invoice.length>0?
                <View style={{width:deviceWidth-(deviceWidth/50),
            padding:deviceWidth/70,alignSelf:'center',backgroundColor:'white',elevation:5,marginTop:deviceHeight/60,marginBottom:deviceHeight/60}}>
                  <List dataArray={InvoiceStore.invoice.slice()}
                    renderRow={(data) =>((data.length!=0)?<ListItem>................................................................................................................................................................... </ListItem>
                    :<View></View>)}>
                  </List>
                </View>
              :<View></View>}
              </View>:<Spinner/>}
            </View>



<Header style={{backgroundColor:'#d0964b',height:30}}>.......</Header>
{InvoiceStore.invoice_response2==2?<View>
              {InvoiceStore.invoice.length>0?
                <View style={{width:deviceWidth-(deviceWidth/50),
            padding:deviceWidth/70,alignSelf:'center',backgroundColor:'white',elevation:5,marginTop:deviceHeight/60,marginBottom:deviceHeight/60}}>
                  <List dataArray={InvoiceStore.invoice.slice()}
                    renderRow={(data) =>((data.length!=0)?<ListItem>................................................................................................................................................................... </ListItem>
                    :<View></View>)}>
                  </List>
                </View>
              :<View></View>}
              </View>:<Spinner/>}

</ScrollView>

在secon列表中,我已滚动到底部,上面的列表和标题隐藏显示。如果我单击第二个列表中的任何项目,数据在页面开始(第一个列表)中可见,为此我已将项目点击滚动到屏幕顶部。

还有其他方式......

1 个答案:

答案 0 :(得分:0)

删除ContainerContent组件

后,它才有效