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

taro3.5.4版本h5平台,Taro.pxTransform转换方法底层实现基准值还是640而不是750,导致转换异常,请尽快修复 #12475

Closed
tan2009216028 opened this issue Sep 11, 2022 · 10 comments · Fixed by #12479
Labels
A-api Area - H5 API 相关 F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x

Comments

@tan2009216028
Copy link

tan2009216028 commented Sep 11, 2022

相关平台

h5平台

复现仓库

https://github.com/tan2009216028/node12312.git
使用框架: React

复现步骤

taro-h5中的api源码转换方法

const pxTransform = function (size) {
// @ts-ignore
const { designWidth } = taro.config;
return Math.ceil((((parseInt(size, 10) / 40) * 640) / designWidth) * 10000) / 10000 'rem';
};

需要修改基准值640为750

期望结果

期望Taro.pxTransform转换结果正常

实际结果

不正常,基准值还是上一个打版本的640

环境信息

  Taro CLI 3.5.4 environment info:
    System:
      OS: macOS 11.6
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 14.17.6 - ~/.nvm/versions/node/v14.17.6/bin/node
      Yarn: 1.22.11 - /usr/local/bin/yarn
      npm: 7.22.0 - ~/.nvm/versions/node/v14.17.6/bin/npm
    npmPackages:
      @tarojs/cli: 3.5.4 => 3.5.4 
      @tarojs/components: 3.5.4 => 3.5.4 
      @tarojs/helper: 3.5.4 => 3.5.4 
      @tarojs/plugin-framework-react: 3.5.4 => 3.5.4 
      @tarojs/plugin-platform-alipay: 3.5.4 => 3.5.4 
      @tarojs/plugin-platform-jd: 3.5.4 => 3.5.4 
      @tarojs/plugin-platform-qq: 3.5.4 => 3.5.4 
      @tarojs/plugin-platform-swan: 3.5.4 => 3.5.4 
      @tarojs/plugin-platform-tt: 3.5.4 => 3.5.4 
      @tarojs/plugin-platform-weapp: 3.5.4 => 3.5.4 
      @tarojs/react: 3.5.4 => 3.5.4 
      @tarojs/router: 3.5.4 => 3.5.4 
      @tarojs/runtime: 3.5.4 => 3.5.4 
      @tarojs/shared: 3.5.4 => 3.5.4 
      @tarojs/taro: 3.5.4 => 3.5.4 
      @tarojs/taro-h5: 3.5.4 => 3.5.4 
      @tarojs/taro-loader: 3.5.4 => 3.5.4 
      babel-preset-taro: 3.5.4 => 3.5.4 
      eslint-config-taro: 3.5.4 => 3.5.4 
      react: ^18.2.0 => 18.2.0 

@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Sep 11, 2022
@tan2009216028 tan2009216028 changed the title taro3.5.4版本下Taro.pxTransform转换方法底层实现基准值还是640而不是750,导致转换异常,请尽快修复 taro3.5.4版本h5平台,Taro.pxTransform转换方法底层实现基准值还是640而不是750,导致转换异常,请尽快修复 Sep 11, 2022
@ZakaryCode ZakaryCode added T-h5 Target - 编译到 H5 and removed T-weapp Target - 编译到微信小程序 labels Sep 13, 2022
@ZakaryCode ZakaryCode added the A-api Area - H5 API 相关 label Sep 13, 2022
@yclnycl
Copy link

yclnycl commented Sep 14, 2022

3.5.5还没修复

@yclnycl
Copy link

yclnycl commented Sep 14, 2022

3.5.5还没修复

回滚到3.4.14

@yclnycl
Copy link

yclnycl commented Sep 14, 2022

3.5.5还没修复

回滚到3.4.14

就解决了

@sumaolin
Copy link

我也发现 3.5.4 H5开发的适配有问题,小于375的屏幕下 rootFontSize 都是20px ,造成 360 | 320 屏幕适配不了出现横向滚动条

@TheKonka
Copy link
Member

我也发现 3.5.4 H5开发的适配有问题,小于375的屏幕下 rootFontSize 都是20px ,造成 360 | 320 屏幕适配不了出现横向滚动条

这个可以配置的,默认最小20px
https://docs.taro.zone/docs/config-detail#h5postcsspxtransform
image

@sumaolin
Copy link

sumaolin commented Oct 8, 2022

我也发现 3.5.4 H5开发的适配有问题,小于375的屏幕下 rootFontSize 都是20px ,造成 360 | 320 屏幕适配不了出现横向滚动条

这个可以配置的,默认最小20px https://docs.taro.zone/docs/config-detail#h5postcsspxtransform image

按你说的配置后配置确实生效了 HTML标签下字体可以小于20px了,不过转换的尺寸还是有问题,我设计稿是以750px为基准的,在iPhone4 模拟器下320宽的 750宽度的页面还是出现了滚动条

 designWidth: 750,
  deviceRatio: {
    640: 2.34 / 2,
    750: 1,
    828: 1.81 / 2,
  },
      pxtransform: {
        enable: true,
        config: {
          minRootSize: 10,
          maxRootSize: 100,
        },
      },

Taro CLI 版本 3.5.6

@Howie126313
Copy link

看看把 index.html 里的脚本替换成 <script><%= htmlWebpackPlugin.options.script %></script>

@sumaolin
Copy link

sumaolin commented Oct 8, 2022

看看把 index.html 里的脚本替换成 <script><%= htmlWebpackPlugin.options.script %></script>

有这个配置的,但是不起作用

受这个想法的启示,直接把该 代码替换了

<script>
!(function(n) {
  function f() {
    var e = n.document.documentElement,
      w = e.getBoundingClientRect().width,
      x = (40 * w) / 750

    e.style.fontSize = x + 'px'
  }
  n.addEventListener('resize', function() {
    f()
  }),
    f()
})(window)
</script>

不用设置 postcss 的 minRootSize 就可以了

KkZsc pushed a commit to KkZsc/taro that referenced this issue Dec 5, 2022
@ZakaryCode ZakaryCode moved this to Done in H5 Apr 10, 2023
@ZakaryCode ZakaryCode added this to H5 Apr 10, 2023
@Yalhu
Copy link

Yalhu commented Jun 15, 2023

看看把 index.html 里的脚本替换成 <script><%= htmlWebpackPlugin.options.script %></script>

在html加了这段,没有效用。请问您知道怎么回事吗?
Taro 版本3.5.8

@shenyu1019
Copy link

实测4.0.6还存在这个bug。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-api Area - H5 API 相关 F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

8 participants