-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from dhilt/issue-156-scroll-to-item-via-Adapt…
…er-fix Scroll to item via Adapter.fix
- Loading branch information
Showing
27 changed files
with
307 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
demo/app/samples/experimental/adapter-fix-scrollToItem.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<app-demo [datasource]="datasource" [context]="demoContext" [sources]="sources"> | ||
|
||
<div actions> | ||
<div class="comment">Available since v1.6.2, undocumented</div> | ||
<button (click)="doScrollTo()">Scroll to</button> item # | ||
<input [(ngModel)]="index" size="2"> | ||
<br> | ||
<input type="checkbox" [(ngModel)]="scrollToBottom"> - scroll to bottom | ||
</div> | ||
|
||
<div description> | ||
<p> | ||
What if we want to scroll to a specific item in the viewport? | ||
This can be done via <em>scrollToItem</em> option of the <em>Adapter.fix</em> method. | ||
This option specifies an item predicate function, and the first item in the Buffer, | ||
that satisfies this predicate, will be the item to which the viewport will scroll. | ||
</p> | ||
<p> | ||
Scrolling is performed via <em>element.scrollIntoView()</em> native DOM Element interface's method. | ||
According to its specification, it accepts 1 optional argument which can be a Boolean parameter or | ||
special Object parameter (details can be found on | ||
<a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView">MDN</a>). | ||
To provide this option, the <em>Adapter.fix</em> method handles another property of its argument object: | ||
<em>scrollToItemOpt</em>. The demo shows how to use it. | ||
</p> | ||
</div> | ||
</app-demo> |
93 changes: 93 additions & 0 deletions
93
demo/app/samples/experimental/adapter-fix-scrollToItem.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
import { DemoContext, DemoSources, DemoSourceType } from '../../shared/interfaces'; | ||
import { Datasource } from '../../../../public_api'; | ||
import { doLog } from '../../shared/datasource-get'; | ||
|
||
@Component({ | ||
selector: 'app-adapter-fix-scroll-to-item', | ||
templateUrl: './adapter-fix-scrollToItem.component.html' | ||
}) | ||
export class DemoAdapterFixScrollToItemComponent { | ||
|
||
demoContext: DemoContext = <DemoContext>{ | ||
scope: 'experimental', | ||
title: `Adapter fix scrollToItem`, | ||
titleId: `adapter-fix-scrollToItem`, | ||
noInfo: true | ||
}; | ||
|
||
datasource = new Datasource({ | ||
get: (index, count, success) => { | ||
const data = []; | ||
for (let i = index; i < index + count; i++) { | ||
data.push({ id: i, text: 'item #' + i }); | ||
} | ||
success(data); | ||
}, | ||
devSettings: { | ||
debug: true | ||
} | ||
}); | ||
|
||
index: string; | ||
scrollToBottom: boolean; | ||
|
||
constructor() { | ||
this.index = '5'; | ||
this.scrollToBottom = false; | ||
} | ||
|
||
sources: DemoSources = [{ | ||
name: DemoSourceType.Template, | ||
text: `<button (click)="doScrollTo()">Scroll to</button> item # | ||
<input [(ngModel)]="index" size="2"> | ||
<input type="checkbox" [(ngModel)]="scrollToBottom"> - scroll to bottom | ||
<div class="viewport"> | ||
<div *uiScroll="let item of datasource"> | ||
<div class="item">{{item.text}}</div> | ||
</div> | ||
</div>` | ||
}, { | ||
name: DemoSourceType.Component, | ||
text: `index = '5' | ||
scrollToBottom = false; | ||
datasource = new Datasource({ | ||
get: (index, count, success) => { | ||
const data = []; | ||
for (let i = index; i < index + count; i++) { | ||
data.push({ id: i, text: 'item #' + i }); | ||
} | ||
success(data); | ||
} | ||
}); | ||
doScrollTo() { | ||
const index = Number(this.index); | ||
const alignToTop = !Boolean(this.scrollToBottom); | ||
if (!isNaN(index)) { | ||
this.datasource.adapter.fix({ | ||
scrollToItem: ({ data }) => data.id === index, | ||
scrollToItemOpt: alignToTop | ||
}); | ||
} | ||
} | ||
` | ||
}]; | ||
|
||
adapterFixUpdater = `Adapter.fix({ scrollToItem })`; | ||
|
||
doScrollTo() { | ||
const index = Number(this.index); | ||
const alignToTop = !Boolean(this.scrollToBottom); | ||
if (!isNaN(index)) { | ||
this.datasource.adapter.fix({ | ||
scrollToItem: ({ data }) => data.id === index, | ||
scrollToItemOpt: alignToTop | ||
}); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/component/processes/append.ts → src/component/processes/adapter/append.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/component/processes/check.ts → src/component/processes/adapter/check.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/component/processes/userClip.ts → src/component/processes/adapter/clip.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.