-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
提供与 setData 同时触发的回调 #17284
Comments
This was referenced Feb 8, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
这个特性解决了什么问题?
TaroRootElement 的performUpdate 函数中调用 setData 是通过 setTimeout(0)调用的,但canvasCtx.fillText 却不会 setTimeout,因此在某些情况下这两个接口触发更新时机不一致,会造成闪烁的问题。
具体地,考虑阅读器翻页项目中有这样一种情况:
自定义的 ReactComponent 中有多个Canvas 组件,它们会绘制不同的文字内容,并且会根据手势调整 Canvas 的偏移,当滑动动画结束之后 Canvas 组件偏移恢复为 0, 但它们所对应的文字内容需要更新为下一页的内容。
因此存在一个翻页结束的时间点,同时恢复 Canvas 偏移(移除动画 class)和绘制文字,但是恢复 Canvas 偏移是通过 React 组件来实现,因此最终是交给 runtime 里TaroRootElement 里的 setData来实现,但绘制文字是通过canvas.ctx.fillText 接口直接实现,最终这两个接口触发更新的时间不一致,造成页面闪烁。
这个 API 长什么样?
添加一个 API,例如Taro.addSetDataCallback(callback),允许添加一个callback,在下次 setData 执行时进行调用。
具体地,
The text was updated successfully, but these errors were encountered: