反应本机获取视图

React native get View

我有 header 的滚动视图和 Body.So 的列表视图 我必须在我当前的代码中滑动列表 swipe.so 上的滚动视图 pro-grammatically我需要实际使用我可以调用的组件的滚动视图的 ID,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 returns id..但我需要视图 actually.Actually 我正在寻找类似于 android.I 中的 findViewById() 的东西 android 开发者..我是新手React-Native..请suggest.Thank你提前

我建议考虑在您的组件上使用 ref 属性。您可以找到更多信息 here.

为了访问任何视图,您通常会这样做:

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

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

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

请记住,this.viewOnecomponentWillMount() 中将为空,您应该在 componentDidMount()

中使用它