weidian-inc / hera

A framework for running WeChat applet. (小程序 SDK,小程序转 H5,小程序转安卓、iOS 原生应用、小程序渲染引擎)
https://weidian-inc.github.io/hera
Other
1.48k stars 315 forks source link

setTimeOut 偶现不执行 #19

Open iShawnWang opened 6 years ago

iShawnWang commented 6 years ago

发现的问题

我的猜想和推理

  1. 有事件发生后, setTimeOut 的函数才执行.
  2. 平时执行 js 的线程的 runloop 是停止的 ? 这个和 WKWebView 背后调度执行 js 的 engine 的实现有很大关系

相关的情况

  1. 首先 : Safari 真机调试js
  2. 运行转换后的小程序 app 在 iOS 真机 上, 按如下图 inspect 小程序的页面,

4171513321661_ pic_hd

Inspect 界面出来后, 菊花会一直转, 此时你手动点击按钮或者 push 新界面, 这个菊花就停止转了, 一切正常了, (我的情况是 : 主页面有轮播图, 轮播图自动轮播事件触发后, 一切正常了)

4241513321759_ pic_hd

具体情况可以联系 @me & @IOriens

Update

找到了暂时的 polyfill : native 注入 setTimeOut 方法, 用 dispatch_after 实现

wwwyiqiao commented 6 years ago

我之前也猜想过是runloop的原因 还没找到解决方案 下面的代码暂时解决setTimeOut的问题

           var now = new Date();
            var exitTime = now.getTime() + number;
            while (true) {
                now = new Date();
                if (now.getTime() > exitTime)
                    break;
            }

我试试上面native注入setTimeOut的方式

iShawnWang commented 6 years ago

我自己尝试 Google 过, 全是讲 WKWebView 的 API 相关的东西, 暂时还没什么头绪...

gordanyang commented 5 years ago

提交了一个PR,https://github.com/weidian-inc/hera/pull/40 不知有没有帮助。

IOriens commented 5 years ago

谢谢大佬,这个很有帮助,ios下setTimeout 失灵的问题之前一直没解决。

On Fri, Aug 24, 2018 at 19:06 gordanyang notifications@github.com wrote:

提交了一个PR,#40 https://github.com/weidian-inc/hera/pull/40 不知有没有帮助。

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/weidian-inc/hera/issues/19#issuecomment-415727494, or mute the thread https://github.com/notifications/unsubscribe-auth/AHwpsH8OoqZfWDOjN5xZ4Xp2UiyMnn3oks5uT946gaJpZM4RH3aa .