简体   繁体   English

ionic 2滚动性能问题

[英]ionic 2 scroll performance issues

Quite impressed with blogs and reviews about ionic2 and Angular2, I started writing an application in ionic 2, and found that ionic2 scroll performance is not good for large number of records for both iOS, and Android. 我对ionic2和Angular2的博客和评论印象非常深刻,我开始用ionic 2编写应用程序,发现ionic2滚动性能对于iOS和Android的大量记录都不理想。

  1. I have a big list of items with in between images in most of the list items 我有一个很大的项目清单,其中大多数清单项目都在图像之间
  2. The scroll performance is good for 10 to 20 items but its very slow when it comes to 30+ items 滚动性能适合10到20个项目,但涉及30个以上项目时非常慢
  3. After lot of search found Virtual scroll in ionic and used it then performance slightly improved for up to 50 items but again slow after 65+ items 经过大量搜索后,找到了ionic中的虚拟滚动条并使用了它,然后最多50个项目的性能略有改善,但超过65个项目后性能再次缓慢

I tried WKWebview in iOS, have some improvement in performance, but often screen turns to black for large lists so i drop this idea. 我在iOS中尝试了WKWebview,性能有所提高,但是对于大列表,屏幕经常变黑,所以我放弃了这个想法。 I don't want to use crosswalk due to its size increase of application , so never tried. 我不想使用人行横道,因为它增加了应用程序的大小,所以从未尝试过。

Can any one help to suggest any workaround to fix this issue or any pure javascript framework solution to display large lists with out any issues? 任何人都可以帮助建议解决此问题的任何解决方法,也可以提供任何纯JavaScript框架解决方案来显示没有任何问题的大列表? for both Android and ios. 适用于Android和ios。

Scrolling is one of the most common interactions with a mobile application, and it is extremely important that it feels right. 滚动是与移动应用程序最常见的交互之一,感觉正确非常重要。 Native applications have lists that scroll smoothly, they are responsive to touch and changes of directions, they accelerate and decelerate in a way that feels natural. 本机应用程序具有可平滑滚动的列表,它们对触摸和方向变化做出响应,以自然的方式加速和减速。

Try use Virtual Scroll of Ionic2 尝试使用Ionic2的虚拟滚动

Virtual Scrolling addresses this issue. 虚拟滚动解决了此问题。 In Ionic 1 this was called Collection Repeat, in Ionic 2 it is called Virtual Scroll, but it is a concept that is used widely in HTML5 mobile development. 在Ionic 1中,这称为“集合重复”;在Ionic 2中,其称为“虚拟滚动”,但这是在HTML5移动开发中广泛使用的概念。 The basic idea is that we only create enough elements in the DOM to display the list data that is currently on screen, and we recycle those DOM elements to display new data as they scroll off screen. 基本思想是,我们仅在DOM中创建足够的元素来显示当前在屏幕上的列表数据,并且当这些DOM元素从屏幕上滚动时,我们对其进行回收以显示新数据。

More Info: Ionic Framework - Virtual Scroll 更多信息: Ionic框架-虚拟滚动

Scrolling performance is a common problem in most javascript frameworks. 滚动性能是大多数javascript框架中的常见问题。

This is because of touch and wheel events. 这是因为触摸和滚轮事件。 But you can pass {passive:true} to event listener to enable some optimizations. 但是您可以将{passive:true}传递给事件侦听器以启用一些优化。 By doing this up front you say that your handler will never use preventDefault() to disable scrolling. 通过预先进行此操作,您说您的处理程序将永远不会使用preventDefault()来禁用滚动。

addEventListener(document, "touchstart", function(e) {

},{passive: true});

It's not yet implemented in all browsers but hopefully, when it will be, all major js frameworks will adopt this technique. 尚未在所有浏览器中实现,但希望所有主流js框架都将采用此技术。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM