首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >反应本机获取视图

反应本机获取视图
EN

Stack Overflow用户
提问于 2017-09-25 13:55:39
回答 2查看 3.4K关注 0票数 2

我将滚动视图作为标题,列表视图作为Body.So,我必须在当前代码中以语法的方式在List swipe.so上滑动滚动视图,我正在获取滚动视图的id,在其中我需要实际使用的组件,可以调用该组件的scrollview.scrollTo();方法。

代码语言:javascript
运行
复制
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中的findViewById()这样的东西,我是一个android开发人员,我是一个新的反应-原生的…请提前suggest.Thank你

EN

Stack Overflow用户

回答已采纳

发布于 2017-09-25 19:16:38

为了访问任何视图,您通常会执行如下操作:

代码语言:javascript
运行
复制
class MyComponent extends React.Component {
   viewOne = null
   //state = {...}

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

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

请记住,this.viewOnecomponentWillMount()中是空的,您应该在componentDidMount()中使用它。

票数 2
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46406966

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档