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

关于Picker组件DPR适配之后的BUG修改 #2051

Closed
petersmu opened this issue Sep 27, 2017 · 3 comments
Closed

关于Picker组件DPR适配之后的BUG修改 #2051

petersmu opened this issue Sep 27, 2017 · 3 comments

Comments

@petersmu
Copy link
Contributor

petersmu commented Sep 27, 2017

我之前提过一次Picker的组件修改自适应,已经在2.6.2版本更新了,#1979

目前项目中出现了问题,在给一个初始值的时候会发生选择不准确的情况,比如截图中显示的时间选择,当天时间是2017年9月27日,但picker选择的是26日:
image

经排查是scroller.js里面的问题,我在scrollTo方法这里打印出数值如下:
image
image

其实根本原因不在这里,而是从最开始计算__minScrollTop等数值的时候就出现了这种长浮点数问题,不过最终影响选择的地方在这里,所以我在这里加了一个取一位小数的方法:

top = Math.round((top / self.__itemHeight).toFixed(1)) * self.__itemHeight

这样修改之后就没有出现选择错误的问题了,但这样会出现另一个问题,滚动到最后一个选项的时候不会回弹:
image
看打印结果发现是这样的:
image
最后一个选项本身计算的值就是临界与.5的,所以为了区分最后一个和中间的选项,我将取小数位数改为5位,这样就不会把最后一个选项的计算值四舍五入到.5了。

所以只需要把scroller.js文件中的

top = Math.round(top / self.__itemHeight) * self.__itemHeight

替换成

top = Math.round((top / self.__itemHeight).toFixed(5)) * self.__itemHeight

就可以了,我在不使用dpr的页面中试过,不会产生影响,你可以自己试一下,如果没问题的话希望能在下个版本中修改这个问题,谢谢!

@airyland
Copy link
Owner

可以发个 PR

@petersmu
Copy link
Contributor Author

PR已提交了, @airyland 看一下吧,谢谢!

@petersmu
Copy link
Contributor Author

@airyland 这个PR最后一步检查报错了是什么意思?
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants