Skip to content

Commit

Permalink
docs: add api doc for viewport scroller (#27381)
Browse files Browse the repository at this point in the history
PR Close #27381
  • Loading branch information
jbogarthyde authored and benlesh committed Dec 26, 2018
1 parent d1de9ff commit c4f7727
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions packages/common/src/viewport_scroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {defineInjectable, inject} from '@angular/core';
import {DOCUMENT} from './dom_tokens';

/**
* Manages the scroll position.
* Defines a scroll position manager. Implemented by `BrowserViewportScroller`.
*
* @publicApi
*/
Expand All @@ -24,40 +24,40 @@ export abstract class ViewportScroller {

/**
* Configures the top offset used when scrolling to an anchor.
* @param offset A position in screen coordinates (a tuple with x and y values)
* or a function that returns the top offset position.
*
* When given a tuple with two number, the service will always use the numbers.
* When given a function, the service will invoke the function every time it restores scroll
* position.
*/
abstract setOffset(offset: [number, number]|(() => [number, number])): void;

/**
* Returns the current scroll position.
* Retrieves the current scroll position.
* @returns A position in screen coordinates (a tuple with x and y values).
*/
abstract getScrollPosition(): [number, number];

/**
* Sets the scroll position.
* Scrolls to a specified position.
* @param position A position in screen coordinates (a tuple with x and y values).
*/
abstract scrollToPosition(position: [number, number]): void;

/**
* Scrolls to the provided anchor.
* Scrolls to an anchor element.
* @param anchor The ID of the anchor element.
*/
abstract scrollToAnchor(anchor: string): void;

/**
*
* Disables automatic scroll restoration provided by the browser.
*
* See also [window.history.scrollRestoration
* info](https://developers.google.com/web/updates/2015/09/history-api-scroll-restoration)
* info](https://developers.google.com/web/updates/2015/09/history-api-scroll-restoration).
*/
abstract setHistoryScrollRestoration(scrollRestoration: 'auto'|'manual'): void;
}

/**
* Manages the scroll position.
* Manages the scroll position for a browser window.
*/
export class BrowserViewportScroller implements ViewportScroller {
private offset: () => [number, number] = () => [0, 0];
Expand All @@ -66,10 +66,9 @@ export class BrowserViewportScroller implements ViewportScroller {

/**
* Configures the top offset used when scrolling to an anchor.
* @param offset A position in screen coordinates (a tuple with x and y values)
* or a function that returns the top offset position.
*
* * When given a number, the service will always use the number.
* * When given a function, the service will invoke the function every time it restores scroll
* position.
*/
setOffset(offset: [number, number]|(() => [number, number])): void {
if (Array.isArray(offset)) {
Expand All @@ -80,7 +79,8 @@ export class BrowserViewportScroller implements ViewportScroller {
}

/**
* Returns the current scroll position.
* Retrieves the current scroll position.
* @returns The position in screen coordinates.
*/
getScrollPosition(): [number, number] {
if (this.supportScrollRestoration()) {
Expand All @@ -92,6 +92,7 @@ export class BrowserViewportScroller implements ViewportScroller {

/**
* Sets the scroll position.
* @param position The new position in screen coordinates.
*/
scrollToPosition(position: [number, number]): void {
if (this.supportScrollRestoration()) {
Expand All @@ -100,7 +101,8 @@ export class BrowserViewportScroller implements ViewportScroller {
}

/**
* Scrolls to the provided anchor.
* Scrolls to an anchor element.
* @param anchor The ID of the anchor element.
*/
scrollToAnchor(anchor: string): void {
if (this.supportScrollRestoration()) {
Expand Down

0 comments on commit c4f7727

Please sign in to comment.