Skip to content

Commit

Permalink
fix(virtualScroll): first node should use clientTop/clientLeft
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Jun 23, 2016
1 parent 6a52a4a commit 2197d49
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/components/virtual-scroll/test/image-gallery/main.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ion-header>
<ion-header style="opacity: 0.9">
<ion-navbar>
<ion-title>Virtual Scroll: Image Gallery</ion-title>
<ion-buttons end>
Expand All @@ -10,7 +10,11 @@
</ion-header>


<ion-content>
<ion-content fullscreen>

<h4 padding>
Name these cars:
</h4>

<ion-list [virtualScroll]="items"
[headerFn]="headerFn"
Expand All @@ -37,6 +41,10 @@

</ion-list>

<h4 padding>
How many did you get right?
</h4>

</ion-content>

<style>
Expand Down
2 changes: 2 additions & 0 deletions src/components/virtual-scroll/test/virtual-scroll.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,8 @@ describe('VirtualScroll', () => {
offsetHeight: height,
offsetTop: top,
offsetLeft: left,
clientTop: top,
clientLeft: left,
style: {
top: '',
left: ''
Expand Down
7 changes: 5 additions & 2 deletions src/components/virtual-scroll/virtual-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,9 @@ export function initReadNodes(nodes: VirtualNode[], cells: VirtualCell[], data:
if (nodes.length && cells.length) {
// first node
// ******** DOM READ ****************
cells[0].top = getElement(nodes[0]).offsetTop;
let firstEle = getElement(nodes[0]);
cells[0].top = firstEle.clientTop;
cells[0].left = firstEle.clientLeft;
cells[0].row = 0;

// ******** DOM READ ****************
Expand Down Expand Up @@ -606,13 +608,14 @@ function calcHeight(viewportHeight: number, approxHeight: string): number {
/**
* NO DOM
*/
function getElement(node: VirtualNode) {
function getElement(node: VirtualNode): HTMLElement {
let rootNodes = node.view.rootNodes;
for (var i = 0; i < rootNodes.length; i++) {
if (rootNodes[i].nodeType === 1) {
return rootNodes[i];
}
}
return null;
}


Expand Down

1 comment on commit 2197d49

@danbucholtz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad this was a simple fix :)

Please sign in to comment.