11/* eslint complexity: ["error", {"max": 50}] */
22/* eslint-disable indent */
3- let SHOW_SCREENS = 4
4- let MAX_SHOW_SCREENS = 5 // 5和3刚好合适?
5- const DEFAULT_SHOW_SCREENS = SHOW_SCREENS
6- const DEFAULT_MAX_SHOW_SCREENS = MAX_SHOW_SCREENS
3+ const DEFAULT_SHOW_SCREENS = 4
74const RECT_SIZE = 200
85const systemInfo = wx . getSystemInfoSync ( )
96const DEBUG = false
10- const BOUNDARY_INTERVAL = 400 // 到达边界多少距离的时候, 直接改为边界位置
11- const SETDATA_INTERVAL_BOUNDARY = 300 // 大于300ms则减少MAX_SHOW_SCREEN的值
12- const SETDATA_INTERVAL_BOUNDARY_1 = 500
137const transformRpx = require ( './utils/transformRpx.js' ) . transformRpx
148
159Component ( {
@@ -57,6 +51,17 @@ Component({
5751 type : Boolean ,
5852 value : true ,
5953 } ,
54+ batch : {
55+ type : Boolean ,
56+ value : false ,
57+ public : true ,
58+ observer : '_recycleInnerBatchDataChanged'
59+ } ,
60+ batchKey : {
61+ type : String ,
62+ value : 'batchSetRecycleData' ,
63+ public : true ,
64+ } ,
6065 scrollTop : {
6166 type : Number ,
6267 value : 0 ,
@@ -115,6 +120,11 @@ Component({
115120 type : String ,
116121 public : true ,
117122 value : ''
123+ } ,
124+ screen : { // 默认渲染多少屏的数据
125+ type : Number ,
126+ public : true ,
127+ value : DEFAULT_SHOW_SCREENS
118128 }
119129 } ,
120130
@@ -156,7 +166,6 @@ Component({
156166 }
157167 } , true )
158168 } )
159- this . _totalTime = this . _totalCount = 0
160169 } ,
161170 detached ( ) {
162171 this . page = null
@@ -165,7 +174,6 @@ Component({
165174 this . context . destroy ( )
166175 this . context = null
167176 }
168- if ( this . timerId ) clearTimeout ( this . timerId )
169177 } ,
170178 /**
171179 * 组件的方法列表
@@ -186,7 +194,6 @@ Component({
186194 this . triggerEvent ( 'scrolltolower' , e . detail )
187195 } ,
188196 _beginToScroll ( ) {
189- this . _lastRenderTime = Date . now ( )
190197 if ( ! this . _lastScrollTop ) {
191198 this . _lastScrollTop = this . _pos && ( this . _pos . top || 0 )
192199 }
@@ -235,39 +242,14 @@ Component({
235242 const that = this
236243 const scrollLeft = e . detail . scrollLeft
237244 const scrollTop = e . detail . scrollTop
238- let isMatchBoundary = false
239- if ( scrollTop - BOUNDARY_INTERVAL < 0 ) {
240- // scrollTop = 0
241- isMatchBoundary = true
242- }
243- if ( this . totalHeight - scrollTop - BOUNDARY_INTERVAL < this . data . height ) {
244- // scrollTop = this.totalHeight - this.data.height
245- // isMatchBoundary = true
246- }
247- const usetime = Date . now ( ) - this . _lastRenderTime
248245 const scrollDistance = Math . abs ( scrollTop - this . _lastScrollTop )
249246
250247 this . _lastScrollTop = scrollTop
251- this . _lastRenderTime = Date . now ( )
252- // 当scroll触发时间大于200ms且大于滚动距离,下一个滚动距离会极高,容易出现白屏,因此需要马上渲染
253- const isNextScrollExpose = false
254- // const mustRender = force || isMatchBoundary || isNextScrollExpose
255- const mustRender = force || isNextScrollExpose
256- this . _log ( 'scrollTop' , e . detail . scrollTop , isMatchBoundary , mustRender )
257- if ( ! mustRender ) {
258- if ( ( Math . abs ( scrollTop - pos . top ) < pos . height * 1.5 ) ) {
259- this . _log ( '【not exceed height' )
260- return
261- }
262- }
263- if ( force && this . timerId ) {
264- clearTimeout ( this . timerId )
265- }
266- SHOW_SCREENS = DEFAULT_SHOW_SCREENS // 固定4屏幕
267- this . _log ( 'SHOW_SCREENS' , SHOW_SCREENS , scrollTop , isNextScrollExpose )
248+ const SHOW_SCREENS = this . data . screen // 固定4屏幕
249+ this . _log ( 'SHOW_SCREENS' , SHOW_SCREENS , scrollTop )
268250 this . _calcViewportIndexes ( scrollLeft , scrollTop ,
269251 ( beginIndex , endIndex , minTop , afterHeight , maxTop ) => {
270- that . _log ( 'scrollDistance' , scrollDistance , 'usetime' , usetime , ' indexes', beginIndex , endIndex )
252+ that . _log ( 'scrollDistance' , scrollDistance , 'indexes' , beginIndex , endIndex )
271253 // 渲染的数据不变
272254 if ( ! force && pos . beginIndex === beginIndex && pos . endIndex === endIndex &&
273255 pos . minTop === minTop && pos . afterHeight === afterHeight ) {
@@ -286,32 +268,12 @@ Component({
286268 pos . maxTop = maxTop
287269 pos . afterHeight = afterHeight
288270 pos . ignoreBeginIndex = pos . ignoreEndIndex = - 1
289- pos . lastSetDataTime = Date . now ( ) // 用于节流时间判断
290- that . _isScrollRendering = true
291- const st = Date . now ( )
292271 that . page . _recycleViewportChange ( {
293272 detail : {
294273 data : that . _pos ,
295274 id : that . id
296275 }
297276 } , ( ) => {
298- that . _isScrollRendering = false
299- if ( that . _totalCount < 5 ) {
300- that . _totalCount ++
301- that . _totalTime += ( Date . now ( ) - st )
302- } else {
303- that . _totalCount = 1
304- that . _totalTime = ( Date . now ( ) - st )
305- }
306- pos . lastSetDataTime = 0 // 用于节流时间判断
307- // if (that._totalCount / that._totalTime <= SETDATA_INTERVAL_BOUNDARY) {
308- // MAX_SHOW_SCREENS = DEFAULT_MAX_SHOW_SCREENS + 1 // 多渲染2个屏幕的内容
309- if ( that . _totalTime / that . _totalCount > SETDATA_INTERVAL_BOUNDARY ) {
310- that . _log ( '【【SHOW_SCREENS 调整' , that . _totalCount / that . _totalTime )
311- MAX_SHOW_SCREENS = DEFAULT_MAX_SHOW_SCREENS - 1
312- } else if ( that . _totalTime / that . _totalCount > SETDATA_INTERVAL_BOUNDARY_1 ) {
313- MAX_SHOW_SCREENS = DEFAULT_MAX_SHOW_SCREENS - 2
314- }
315277 if ( e . detail . cb ) {
316278 e . detail . cb ( )
317279 }
@@ -405,6 +367,7 @@ Component({
405367 // top = Math.max(top, this.data.beforeSlotHeight)
406368 const beforeSlotHeight = this . data . beforeSlotHeight || 0
407369 // 和direction无关了
370+ const SHOW_SCREENS = this . data . screen
408371 let minTop = top - pos . height * SHOW_SCREENS - beforeSlotHeight
409372 let maxTop = top + pos . height * SHOW_SCREENS - beforeSlotHeight
410373 // maxTop或者是minTop超出了范围
0 commit comments