Skip to content

Commit 8867677

Browse files
committed
feat(content): add properties for img request/render buffers
1 parent 7c70bdf commit 8867677

File tree

1 file changed

+16
-27
lines changed

1 file changed

+16
-27
lines changed

src/components/content/content.ts

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,19 @@ export class Content extends Ion implements OnDestroy, OnInit {
158158
/** @internal */
159159
_fullscreen: boolean;
160160
/** @internal */
161-
_imgs: Img[] = [];
162-
/** @internal */
163161
_footerEle: HTMLElement;
164162
/** @internal */
165163
_dirty: boolean;
166164
/** @internal */
167165
_scrollEle: HTMLElement;
168166
/** @internal */
169167
_fixedEle: HTMLElement;
168+
/** @internal */
169+
_imgs: Img[] = [];
170+
171+
private _imgReqBfr: number;
172+
private _imgRndBfr: number;
173+
private _imgVelMax: number;
170174

171175
/** @private */
172176
statusbarPadding: boolean;
@@ -263,24 +267,6 @@ export class Content extends Ion implements OnDestroy, OnInit {
263267
return this._scroll.isScrolling;
264268
}
265269

266-
/**
267-
* The current vertical scroll velocity.
268-
*
269-
* @return {number}
270-
*/
271-
get velocityY(): number {
272-
return this._scroll.ev.velocityY;
273-
}
274-
275-
/**
276-
* The current horizontal scroll velocity.
277-
*
278-
* @return {number}
279-
*/
280-
get velocityX(): number {
281-
return this._scroll.ev.velocityX;
282-
}
283-
284270
/**
285271
* The current, or last known, vertical scroll direction. Possible
286272
* string values include `down` and `up`.
@@ -341,6 +327,9 @@ export class Content extends Ion implements OnDestroy, OnInit {
341327
super(config, elementRef, renderer, 'content');
342328

343329
this.statusbarPadding = config.getBoolean('statusbarPadding', false);
330+
this._imgReqBfr = config.getNumber('imgRequestBuffer', 1400);
331+
this._imgRndBfr = config.getNumber('imgRenderBuffer', 400);
332+
this._imgVelMax = config.getNumber('imgVelocityMax', 3);
344333

345334
if (viewCtrl) {
346335
viewCtrl._setIONContent(this);
@@ -818,17 +807,20 @@ export class Content extends Ion implements OnDestroy, OnInit {
818807
*/
819808
imgsUpdate() {
820809
if (this._scroll.initialized && this._imgs.length && this.isImgsUpdatable()) {
821-
updateImgs(this._imgs, this.scrollTop, this.contentHeight, this.directionY, IMG_REQUESTABLE_BUFFER, IMG_RENDERABLE_BUFFER);
810+
updateImgs(this._imgs, this.scrollTop, this.contentHeight, this.directionY, this._imgReqBfr, this._imgRndBfr);
822811
}
823812
}
824813

825814
/**
826815
* @private
827816
*/
828817
isImgsUpdatable() {
829-
// an image is only "updatable" if the content
830-
// isn't scrolling too fast
831-
return Math.abs(this.velocityY) < 3;
818+
// an image is only "updatable" if the content isn't scrolling too fast
819+
// if scroll speed is above the maximum velocity, then let current
820+
// requests finish, but do not start new requets or render anything
821+
// if scroll speed is below the maximum velocity, then it's ok
822+
// to start new requests and render images
823+
return Math.abs(this._scroll.ev.velocityY) < this._imgVelMax;
832824
}
833825

834826
}
@@ -920,9 +912,6 @@ export function updateImgs(imgs: Img[], viewableTop: number, contentHeight: numb
920912
}
921913
}
922914

923-
const IMG_REQUESTABLE_BUFFER = 1200;
924-
const IMG_RENDERABLE_BUFFER = 300;
925-
926915

927916
function sortTopToBottom(a: Img, b: Img) {
928917
if (a.top < b.top) {

0 commit comments

Comments
 (0)