2017-09-25 115 views
2

我有滚动查看头和列表视图Body.So我要刷卡滚动视图亲语法上的列表swipe.so在我当前的代码我得到滚动视图的ID,其中i需要使用我可以调用的组件,scrollview.scrollTo();方法。阵营本地获取视图

render() { 
     return (
      <View style={styles.container}> 
       <View style={styles.scrollContainer}> 

        <ScrollView 
           ref={'abc'} 
           directionalLockEnabled={false} 
           horizontal={true}> 

         <View style={styles.scrollItemStyle}> 
         <Image source={shield} style={homescreenstyle.imagestyle}/> 
         </View> 
         <View style={styles.scrollItemStyle}> 
          <Image source={shield} style={homescreenstyle.imagestyle}/> 
         </View> 
         <View style={styles.scrollItemStyle}> 
          <Image source={shield} style={homescreenstyle.imagestyle}/> 
         </View> 
         <View style={styles.scrollItemStyle}> 
          <Image source={shield} style={homescreenstyle.imagestyle}/> 
         </View> 
         <View style={styles.scrollItemStyle}> 
          <Image source={shield} style={homescreenstyle.imagestyle}/> 
         </View> 
         <View style={styles.scrollItemStyle}> 
          <Image source={shield} style={homescreenstyle.imagestyle}/> 
         </View> 
         <View style={styles.scrollItemStyle}> 
          <Image source={shield} style={homescreenstyle.imagestyle}/> 
         </View> 

        </ScrollView> 

       </View> 
       <View style={styles.listcontainer}> 

        <ListView 
         dataSource={this.state.todaysData} 
         renderRow={this.renderRow} 
         onScroll={this.handleScroll} 
         style={styles.container} 
        /> 


       </View> 

      </View> 
     ); 
    } 



    renderRow(rowData){ 

     return (
      <CustomListRowCards 
       title={rowData.title}/> 
     ); 
    } 

    handleScroll(event: Object) { 
     // var input = this.refs.scrollview; 

     customViewNativeID.scrollTo(500, 0, true) 

     // alert(event.nativeEvent.contentOffset.y); 
    } 

// CutomViewNativeId返回id..But我需要的视图actually.Actually我期待在android.I一些东西,就像findViewById()是一款Android developer..I是新来React- Native..Please suggest.Thank你提前

回答

1

为了访问你通常会做这样的事情的任何观点:

class MyComponent extends React.Component { 
    viewOne = null 
    //state = {...} 

    useViewOne =() => {  
     this.viewOne.doSomething() 
    }  

    render() { 
     return (
     <View ref={(viewRef) => this.viewOne = viewRef}> 
     </View> 
    ) 
    } 
} 

记住this.viewOne将在componentWillMount()空,而是你应该使用它在componentDidMount()

+0

this.viewOne越来越未定义 – Mainak

+0

它在哪里发生 –

+0

里面this.viewOne.dosomething(); – Mainak

0

我建议寻找到使用您的组件裁判道具。你可以找到更多信息here