Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Taro RN模板开发,页面根元素无法获取宽高 #11420

Open
WhiteSean opened this issue Mar 8, 2022 · 4 comments
Open

Taro RN模板开发,页面根元素无法获取宽高 #11420

WhiteSean opened this issue Mar 8, 2022 · 4 comments
Assignees
Labels
F-react Framework - React T-rn Target - 编译到 React Native V-3 Version - 3.x

Comments

@WhiteSean
Copy link
Contributor

相关平台

React Native

使用框架: React

复现步骤

随便写一个demo页,根元素width:100%,height:100%,然后模拟器运行,审查元素,找到根元素,查看元素无法获取到屏幕的宽高.
另外一个问题,审查元素根元素的名字是怎么来的,似乎是文件的名字,不是根元素的class名字

期望结果

正确获取宽高

实际结果

宽高为0

环境信息

👽 Taro v3.3.19


  Taro CLI 3.3.19 environment info:
    System:
      OS: macOS 10.15.6
      Shell: 5.7.1 - /bin/zsh
    Binaries:
      Node: 12.18.3 - /usr/local/bin/node
      Yarn: 1.22.10 - /usr/local/bin/yarn
      npm: 7.15.1 - /usr/local/bin/npm
    npmPackages:
      @tarojs/cli: 3.3.19 => 3.3.19 
      @tarojs/components: 3.3.19 => 3.3.19 
      @tarojs/mini-runner: 3.3.19 => 3.3.19 
      @tarojs/react: 3.3.19 => 3.3.19 
      @tarojs/runtime: 3.3.19 => 3.3.19 
      @tarojs/taro: 3.3.19 => 3.3.19 
      @tarojs/webpack-runner: 3.3.19 => 3.3.19 
      babel-preset-taro: 3.3.19 => 3.3.19 
      eslint-config-taro: 3.3.19 => 3.3.19 
      react: ^17.0.2 => 17.0.2 
      react-native: ^0.66.0 => 0.66.4 
    npmGlobalPackages:
      typescript: 4.1.3

补充信息

image

@taro-bot2 taro-bot2 bot added F-react Framework - React T-rn Target - 编译到 React Native V-3 Version - 3.x labels Mar 8, 2022
@zhiqingchen
Copy link
Member

获取后的用途是?

@zhiqingchen zhiqingchen self-assigned this Mar 8, 2022
@WhiteSean
Copy link
Contributor Author

获取后的用途是?

在页面根元素的下一级使用绝对定位,并且此级元素需要宽高都为100%,此时因为根元素宽高100% 获取不到,所以此级元素宽高就为0

@shinken008
Copy link
Collaborator

试试 layout?https://reactnative.dev/docs/layoutevent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-rn Target - 编译到 React Native V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

3 participants