Skip to content

Commit 19aa633

Browse files
committed
feat(content): content dimension properties w/out dom read
1 parent d3780b3 commit 19aa633

File tree

2 files changed

+69
-32
lines changed

2 files changed

+69
-32
lines changed

src/components/content/content.ts

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -171,45 +171,72 @@ export class Content extends Ion implements OnDestroy, OnInit {
171171
/** @private */
172172
statusbarPadding: boolean;
173173

174+
/**
175+
* Content height of the viewable area. This does not include content
176+
* which is outside the overflow area, or content area which is under
177+
* headers and footers. Read-only.
178+
*
179+
* @return {number}
180+
*/
181+
get contentHeight(): number {
182+
return this._scroll.ev.contentHeight;
183+
}
184+
185+
/**
186+
* Content width including content which is not visible on the screen
187+
* due to overflow. Read-only.
188+
*
189+
* @return {number}
190+
*/
191+
get contentWidth(): number {
192+
return this._scroll.ev.contentWidth;
193+
}
194+
174195
/**
175196
* A number representing how many pixels the top of the content has been
176-
* adjusted, which could be by either padding or margin.
197+
* adjusted, which could be by either padding or margin. This adjustment
198+
* is to account for the space needed for the header.
177199
*
178200
* @return {number}
179201
*/
180202
contentTop: number;
181203

182204
/**
183205
* A number representing how many pixels the bottom of the content has been
184-
* adjusted, which could be by either padding or margin.
206+
* adjusted, which could be by either padding or margin. This adjustment
207+
* is to account for the space needed for the footer.
185208
*
186209
* @return {number}
187210
*/
188211
contentBottom: number;
189212

190213
/**
191-
* The height the content, including content not visible
192-
* on the screen due to overflow.
214+
* Content height including content which is not visible on the screen
215+
* due to overflow. Read-only.
193216
*
194217
* @return {number}
195218
*/
196-
scrollHeight: number = 0;
219+
get scrollHeight(): number {
220+
return this._scroll.ev.scrollHeight;
221+
}
197222

198223
/**
199-
* The width the content, including content not visible
200-
* on the screen due to overflow.
224+
* Content width including content which is not visible due to
225+
* overflow. Read-only.
201226
*
202227
* @return {number}
203228
*/
204-
scrollWidth: number = 0;
229+
get scrollWidth(): number {
230+
return this._scroll.ev.scrollWidth;
231+
}
205232

206233
/**
207234
* The distance of the content's top to its topmost visible content.
208235
*
209236
* @return {number}
210237
*/
211238
get scrollTop(): number {
212-
return this._scroll.getTop();
239+
return this._scroll.ev.scrollTop;
213240
}
214241
set scrollTop(top: number) {
215242
this._scroll.setTop(top);
@@ -221,14 +248,14 @@ export class Content extends Ion implements OnDestroy, OnInit {
221248
* @return {number}
222249
*/
223250
get scrollLeft(): number {
224-
return this._scroll.getLeft();
251+
return this._scroll.ev.scrollLeft;
225252
}
226253
set scrollLeft(top: number) {
227254
this._scroll.setLeft(top);
228255
}
229256

230257
/**
231-
* If the scrollable area is actively scrolling or not.
258+
* If the content is actively scrolling or not.
232259
*
233260
* @return {boolean}
234261
*/
@@ -255,7 +282,8 @@ export class Content extends Ion implements OnDestroy, OnInit {
255282
}
256283

257284
/**
258-
* The current, or last known, vertical scroll direction.
285+
* The current, or last known, vertical scroll direction. Possible
286+
* string values include `down` and `up`.
259287
*
260288
* @return {string}
261289
*/
@@ -264,7 +292,8 @@ export class Content extends Ion implements OnDestroy, OnInit {
264292
}
265293

266294
/**
267-
* The current, or last known, horizontal scroll direction.
295+
* The current, or last known, horizontal scroll direction. Possible
296+
* string values include `right` and `left`.
268297
*
269298
* @return {string}
270299
*/
@@ -564,9 +593,6 @@ export class Content extends Ion implements OnDestroy, OnInit {
564593
let cacheFooterHeight = this._ftrHeight;
565594
let cacheTabsPlacement = this._tabsPlacement;
566595
let tabsTop = 0;
567-
568-
this.scrollWidth = 0;
569-
this.scrollHeight = 0;
570596
this._pTop = 0;
571597
this._pRight = 0;
572598
this._pBottom = 0;
@@ -596,11 +622,6 @@ export class Content extends Ion implements OnDestroy, OnInit {
596622
if (tagName === 'ION-CONTENT') {
597623
scrollEvent.contentElement = ele;
598624

599-
// ******** DOM READ ****************
600-
this.scrollWidth = ele.scrollWidth;
601-
// ******** DOM READ ****************
602-
this.scrollHeight = ele.scrollHeight;
603-
604625
if (this._fullscreen) {
605626
// ******** DOM READ ****************
606627
computedStyle = getComputedStyle(ele);
@@ -672,6 +693,15 @@ export class Content extends Ion implements OnDestroy, OnInit {
672693
this._cBottom += this._pBottom;
673694
}
674695

696+
// ******** DOM READ ****************
697+
const contentDimensions = this.getContentDimensions();
698+
scrollEvent.scrollHeight = contentDimensions.scrollHeight;
699+
scrollEvent.scrollWidth = contentDimensions.scrollWidth;
700+
scrollEvent.contentHeight = contentDimensions.contentHeight;
701+
scrollEvent.contentWidth = contentDimensions.contentWidth;
702+
scrollEvent.contentTop = contentDimensions.contentTop;
703+
scrollEvent.contentBottom = contentDimensions.contentBottom;
704+
675705
this._dirty = (
676706
cachePaddingTop !== this._pTop ||
677707
cachePaddingBottom !== this._pBottom ||

src/util/scroll-view.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ export class ScrollView {
2727
timeStamp: 0,
2828
scrollTop: 0,
2929
scrollLeft: 0,
30+
scrollHeight: 0,
31+
scrollWidth: 0,
32+
contentHeight: 0,
33+
contentWidth: 0,
34+
contentTop: 0,
35+
contentBottom: 0,
3036
startY: 0,
3137
startX: 0,
3238
deltaY: 0,
@@ -37,12 +43,7 @@ export class ScrollView {
3743
directionX: null,
3844
domWrite: function(fn: DomCallback, ctx?: any) {
3945
_dom.write(fn, ctx);
40-
},
41-
contentElement: null,
42-
fixedElement: null,
43-
scrollElement: null,
44-
headerElement: null,
45-
footerElement: null
46+
}
4647
};
4748
}
4849

@@ -522,6 +523,12 @@ export interface ScrollEvent {
522523
timeStamp: number;
523524
scrollTop: number;
524525
scrollLeft: number;
526+
scrollHeight: number;
527+
scrollWidth: number;
528+
contentHeight: number;
529+
contentWidth: number;
530+
contentTop: number;
531+
contentBottom: number;
525532
startY: number;
526533
startX: number;
527534
deltaY: number;
@@ -531,11 +538,11 @@ export interface ScrollEvent {
531538
directionY: string;
532539
directionX: string;
533540
domWrite: {(fn: DomCallback, ctx?: any)};
534-
contentElement: HTMLElement;
535-
fixedElement: HTMLElement;
536-
scrollElement: HTMLElement;
537-
headerElement: HTMLElement;
538-
footerElement: HTMLElement;
541+
contentElement?: HTMLElement;
542+
fixedElement?: HTMLElement;
543+
scrollElement?: HTMLElement;
544+
headerElement?: HTMLElement;
545+
footerElement?: HTMLElement;
539546
}
540547

541548

0 commit comments

Comments
 (0)