美文网首页
react-native获取组件位置宽高

react-native获取组件位置宽高

作者: 张大娃创业笔记 | 来源:发表于2018-04-27 17:40 被阅读0次

react-native获取组件在屏幕中相对位置以及视图宽高

  1. 引入模块
import { UIManager } from 'NativeModules';
import {findNodeHandle} from 'react-native';

2.获取写法

 <View style={styles.tabBar} ref={(c) => { this.progressBar = c }} onLayout={() => {
                const handle = findNodeHandle(this.progressBar);
                setTimeout(()=>{UIManager.measure(handle, (x, y, width, height, pageX, pageY) => {
                    console.warn(x, y, width, height, pageX, pageY)
                })},1000)
            }}>

相关文章

网友评论

      本文标题:react-native获取组件位置宽高

      本文链接:https://www.haomeiwen.com/subject/lukilftx.html