scroll-dispatcher.d.ts 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * @license
  3. * Copyright Google LLC All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. import { Platform } from '@angular/cdk/platform';
  9. import { ElementRef, NgZone, OnDestroy, Optional } from '@angular/core';
  10. import { Subscription, Observable } from 'rxjs';
  11. import { CdkScrollable } from './scrollable';
  12. /** Time in ms to throttle the scrolling events by default. */
  13. export declare const DEFAULT_SCROLL_TIME = 20;
  14. /**
  15. * Service contained all registered Scrollable references and emits an event when any one of the
  16. * Scrollable references emit a scrolled event.
  17. */
  18. export declare class ScrollDispatcher implements OnDestroy {
  19. private _ngZone;
  20. private _platform;
  21. constructor(_ngZone: NgZone, _platform: Platform);
  22. /** Subject for notifying that a registered scrollable reference element has been scrolled. */
  23. private _scrolled;
  24. /** Keeps track of the global `scroll` and `resize` subscriptions. */
  25. _globalSubscription: Subscription | null;
  26. /** Keeps track of the amount of subscriptions to `scrolled`. Used for cleaning up afterwards. */
  27. private _scrolledCount;
  28. /**
  29. * Map of all the scrollable references that are registered with the service and their
  30. * scroll event subscriptions.
  31. */
  32. scrollContainers: Map<CdkScrollable, Subscription>;
  33. /**
  34. * Registers a scrollable instance with the service and listens for its scrolled events. When the
  35. * scrollable is scrolled, the service emits the event to its scrolled observable.
  36. * @param scrollable Scrollable instance to be registered.
  37. */
  38. register(scrollable: CdkScrollable): void;
  39. /**
  40. * Deregisters a Scrollable reference and unsubscribes from its scroll event observable.
  41. * @param scrollable Scrollable instance to be deregistered.
  42. */
  43. deregister(scrollable: CdkScrollable): void;
  44. /**
  45. * Returns an observable that emits an event whenever any of the registered Scrollable
  46. * references (or window, document, or body) fire a scrolled event. Can provide a time in ms
  47. * to override the default "throttle" time.
  48. *
  49. * **Note:** in order to avoid hitting change detection for every scroll event,
  50. * all of the events emitted from this stream will be run outside the Angular zone.
  51. * If you need to update any data bindings as a result of a scroll event, you have
  52. * to run the callback using `NgZone.run`.
  53. */
  54. scrolled(auditTimeInMs?: number): Observable<CdkScrollable | void>;
  55. ngOnDestroy(): void;
  56. /**
  57. * Returns an observable that emits whenever any of the
  58. * scrollable ancestors of an element are scrolled.
  59. * @param elementRef Element whose ancestors to listen for.
  60. * @param auditTimeInMs Time to throttle the scroll events.
  61. */
  62. ancestorScrolled(elementRef: ElementRef, auditTimeInMs?: number): Observable<CdkScrollable | void>;
  63. /** Returns all registered Scrollables that contain the provided element. */
  64. getAncestorScrollContainers(elementRef: ElementRef): CdkScrollable[];
  65. /** Returns true if the element is contained within the provided Scrollable. */
  66. private _scrollableContainsElement;
  67. /** Sets up the global scroll listeners. */
  68. private _addGlobalListener;
  69. /** Cleans up the global scroll listener. */
  70. private _removeGlobalListener;
  71. }
  72. /** @docs-private @deprecated @breaking-change 8.0.0 */
  73. export declare function SCROLL_DISPATCHER_PROVIDER_FACTORY(parentDispatcher: ScrollDispatcher, ngZone: NgZone, platform: Platform): ScrollDispatcher;
  74. /** @docs-private @deprecated @breaking-change 8.0.0 */
  75. export declare const SCROLL_DISPATCHER_PROVIDER: {
  76. provide: typeof ScrollDispatcher;
  77. deps: (Optional[] | typeof NgZone | typeof Platform)[];
  78. useFactory: typeof SCROLL_DISPATCHER_PROVIDER_FACTORY;
  79. };