文章系列
深入Flutter(一) 积极推进“组合”方式
深入Flutter(二) 线性时间复杂度的 build 和 layout
深入Flutter(三) Element树和RenderObject树
深入Flutter(五) 专业化API

原文:Inside Flutter

文章目录

  • Infinite scrolling -- 无限滚动
    • Viewport-aware layout -- 视口感知(Viewport-aware) layout
    • Building widgets on demand --按需build widget

译者额外添加flutter的渲染流程图,有助于理解本文:
图一、

图二、

Infinite scrolling – 无限滚动

Infinite scrolling lists are notoriously difficult for toolkits. Flutter supports infinite scrolling lists with a simple interface based on the builder pattern, in which a ListView uses a callback to build widgets on demand as they become visible to the user during scrolling. Supporting this feature requires viewport-aware layout and building widgets on demand.
众所周知,无限滚动列表对于工具包来说非常困难。 Flutter通过基于builder设计模式的简单interface支持无限滚动列表,其中** ListView **使用callback按需build widget,因为在滚动过程中用户可以看到它们。 支持此功能需要视口感知的layout和按需build widget。

Viewport-aware layout – 视口感知(Viewport-aware) layout

Like most things in Flutter, scrollable widgets are built using composition. The outside of a scrollable widget is a Viewport, which is a box that is “bigger on the inside,” meaning its children can extend beyond the bounds of the viewport and can be scrolled into view. However, rather than having RenderBox children, a viewport has RenderSliver children, known as slivers, which have a viewport-aware layout protocol.
像Flutter中的大多数东西一样,可滚动widget是使用组合进行build的。 可滚动widget的外部是“Viewport”(可见区域),这是一个“内部较大”的框,这意味着其子项可以扩展到“Viewport”(可见区域)的范围之外并可以滚动到视图中。 但是,Viewport并非是持有RenderBox的实现子类,而是具有RenderSliver子类(称为Sliver),它们具有视口感知(viewport-aware)的layout协议。

The sliver layout protocol matches the structure of the box layout protocol in that parents pass constraints down to their children and receive geometry in return. However, the constraint and geometry data differs between the two protocols. In the sliver protocol, children are given information about the viewport, including the amount of visible space remaining. The geometry data they return enables a variety of scroll-linked effects, including collapsible headers and parallax.
sliver layout 协议与box layout协议的结构相对比,因为父级将constraint下传给子级,并接收几何信息(大小等)作为return。 但是,两种协议之间的constraint和几何数据不同。 在sliver协议中,将为子级提供有关viewport(可见区域)的信息,包括剩余的可见空间量。 它们return的几何数据可实现各种滚动链接效果,包括可折叠的标题和视差(parallax)

Different slivers fill the space available in the viewport in different ways. For example, a sliver that produces a linear list of children lays out each child in order until the sliver either runs out of children or runs out of space. Similarly, a sliver that produces a two-dimensional grid of children fills only the portion of its grid that is visible. Because they are aware of how much space is visible, slivers can produce a finite number of children even if they have the potential to produce an unbounded number of children.
不同的sliver以不同的方式填充viewport中的可用空间。 例如,一条产生线性(linear)子项列表的sliver按顺序排列每个子项,直到sliver用完子项或空间用完为止。 类似地,产生二维子网格(grid)的sliver仅填充网格(grid)的可见部分。 因为他们知道有多少空间可见,所以sliver可以仅产生有限数量的子代,即使它们有可能需要产生无限的子代(译者:意思是仅仅生成需要展示的部分)。

Slivers can be composed to create bespoke scrollable layouts and effects. For example, a single viewport can have a collapsible header followed by a linear list and then a grid. All three slivers will cooperate through the sliver layout protocol to produce only those children that are actually visible through the viewport, regardless of whether those children belong to the header, the list, or the grid.
Slivers 可以通过组合的方式实现定制的滚动layout和效果。 例如,单个viewport可以同时具有可折叠的标题(header),然后是线性(linear)列表,再然后是网格(grid)。 总共三个sliver将通过sliver layout 协议(protocol)进行协作,以此,仅仅生成那些在viewport中实际可见的子项,而不管这些子项是属于标题(header),列表(linear)还是网格(grid)。

Building widgets on demand --按需build widget

If Flutter had a strict build-then-layout-then-paint pipeline, the foregoing would be insufficient to implement an infinite scrolling list because the information about how much space is visible through the viewport is available only during the layout phase. Without additional machinery, the layout phase is too late to build the widgets necessary to fill the space. Flutter solves this problem by interleaving the build and layout phases of the pipeline. At any point in the layout phase, the framework can start building new widgets on demand as long as those widgets are descendants of the render object currently performing layout.
如果Flutter具有严格的 build -> layout -> paint 管道(pipeline),则前述内容将不足以实现无限滚动列表,因为有关通过viewport可见的空间量的信息仅在layout段才可用。 如果没有其他机制,layout阶段就太晚了,无法build填充空间所需的widgets。 Flutter通过交错管道pipelinebuild和layout阶段来解决此问题。 在layout阶段的任何时候,只要这些widget是当前正在执行layout的渲染对象的子类,framework都可以根据需要开始构建新的widget。

Interleaving build and layout is possible only because of the strict controls on information propagation in the build and layout algorithms. Specifically, during the build phase, information can propagate only down the tree. When a render object is performing layout, the layout walk has not visited the subtree below that render object, which means writes generated by building in that subtree cannot invalidate any information that has entered the layout calculation thus far. Similarly, once layout has returned from a render object, that render object will never be visited again during this layout, which means any writes generated by subsequent layout calculations cannot invalidate the information used to build the render object’s subtree.
就是因为对build和layout算法中的信息传播进行了严格控制,才有可能使build和layout交错。 具体来说,在build阶段,信息只能沿树传播。 当renderObject执行layout时,layout的遍历还尚未访问该渲染对象下的子树,这意味着在该子树中通过build生成的写入操作不会使到目前为止已进入layout计算的任何信息无效。 同样,一旦渲染对象return了layout,该渲染对象就不会在该layout期间再次被访问,这意味着后续layout计算生成的任何写入都不会无效化用于构建渲染对象的子树信息。

Additionally, linear reconciliation and tree surgery are essential for efficiently updating elements during scrolling and for modifying the render tree when elements are scrolled into and out of view at the edge of the viewport.
此外,“线性reconciliation(算法)”“树surgery” 对于在滚动过程中有效地更新element以及在viewport边缘将element滚动进出视图时修改渲染树至关重要。

深入Flutter(四) Infinite scrolling -- 无限滚动相关推荐

  1. Infinite Scroll - jQuery WP 无限滚动插件

    无限滚动(Infinite Scroll)也称为自动分页.滚动分页和无限分页.常用在图片.文章或其它列表形式的网页中,用来在滚动网页的时候自动加载下一页的内容.Infinite Scroll  这款  ...

  2. 无限滚动插件Infinite Scroll

    最近一个项目需要用到无限滚动,调查了很多最后用了Infinite Scroll这个插件. 优点 ①ajax的函数是内部已经封装好,所有不需要单独的调用. ②后台返回的形式既可以是静态html形式也可以 ...

  3. 使用 GraphQL 无限滚动

    在构建为用户提供一长串信息的应用程序时,例如新闻提要.论坛中的帖子或聊天应用程序中的消息,我们的目标是向用户显示合理数量的信息. 用户开始滚动浏览初始列表后,Web 客户端应立即加载更多内容以继续向用 ...

  4. 15个非常棒的jQuery无限滚动插件【瀑布流效果】

    现在,最热门的网站分页趋势之一是jQuery的无限滚动(也即瀑布流).如果你碰巧观察Pinterest的网站,如Facebook,Twitter和deviantART的,你会发现无限滚动的动作,当旧的 ...

  5. 【译】无限滚动加载最佳实践

    本文转载自:众成翻译 译者:文蔺 链接:http://www.zcfy.cc/article/673 原文:https://uxplanet.org/infinite-scrolling-best-p ...

  6. c# ui 滚动 分页_UI备忘单:分页,无限滚动和“加载更多”按钮

    c# ui 滚动 分页 重点 (Top highlight) When you have a lot of content, you have to rely on one of these thre ...

  7. Xamarin.Forms: 无限滚动的ListView(懒加载方式)

    说明 在本博客中,学习如何在Xamarin.Forms应用程序中设计一个可扩展的无限滚动的ListView.这个无限滚动函数在默认的Xamarin.Forms不存在,因此我们需要为此添加插件.在这里我 ...

  8. 无限滚动加载最佳实践

    无限滚动加载最佳实践 无限滚动(Infinite scrolling),有时候被称为无尽滚动(endless scrolling),这种技术允许用户在大量内容上滚动,眼中看不到结束的地方.这种技术很简 ...

  9. vue2.0无限滚动加载数据插件

      做vue项目用到下拉滚动加载数据功能,由于选的UI库(element)没有这个组件,就用Vue-infinite-loading 这个插件代替,使用中遇到的一些问题及使用方法,总结作记录! 安装: ...

最新文章

  1. 业界丨一文看懂AI人才百万美元年薪因何而来?
  2. 46 岁美国华裔“鞋王”意外去世,25 岁创业成亿万富翁
  3. P3195 [HNOI2008]玩具装箱TOY(斜率优化)
  4. 405 Method Not Allowed
  5. 关于开源中国手机App的说明
  6. python中的对象列表_Python内建的对象列表
  7. hadoop2.2单节点集群的搭建
  8. java的随机数生成原理
  9. HDU-1863-畅通工程
  10. linux 历史记录索引_使用Google桌面索引FireFox浏览器历史记录
  11. 2020计算机网络练习题记录(1)
  12. MATLAB-插值算法汇总
  13. spring Aop中切入点和连接点什么关系?
  14. http请求417错误
  15. onclick事件诡异事件 一
  16. android qq 功能,Android-类qq功能(一)
  17. 机器学习_深度学习毕设题目汇总——图像分割
  18. 无情剑之了却红尘java,《无情剑-了却红尘》攻略
  19. Linux部署k8s集群
  20. 离散度计算公式 python_Python分析离散心率信号(中)

热门文章

  1. 基于sinc的音频重采样(二):实现
  2. 移动应用程序设计基础——安卓动画与视音频播放器的实现
  3. 计算机视觉论文-2021-07-15
  4. 水果忍者VR原型 二
  5. python中的newline_python open函数newline用法
  6. 西南民族大学第十届校赛 题解
  7. 仿网易云PC端项目-vue
  8. 运维简历怎么写项目描述_职场小白怎么写简历?一份好简历=成功一半
  9. linux防火墙关了连不上,SecrueCRT连接linux需要关闭linux防火墙_Centos 6.4 iptables防火墙关闭启动详解...
  10. java hevc和heif_关于 iOS 和 macOS 的 HEVC 和 HEIF