React Native获取视图

迈纳克

我有滚动视图作为标题,列表视图作为Body.So,所以我必须在列表swipe.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返回id。但是实际上我需要视图。实际上我正在寻找类似于android中的findViewById()的东西。我是android开发人员。.我是React-Native的新手。.请建议。谢谢提前给你

亚历山大·维塔诺夫(Alexander Vitanov)

为了访问任何视图,通常需要执行以下操作:

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

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

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

请记住,this.viewOne它将在其中为null componentWillMount(),而应在其中使用componentDidMount()

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章