/** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ import * as $ from 'jquery'; import APLRenderer from '../APLRenderer'; import { Component, FactoryFunction, IComponentProperties } from './Component'; import { Scrollable } from './Scrollable'; /** * @ignore */ export class ScrollView extends Scrollable { constructor(renderer: APLRenderer, component: APL.Component, factory: FactoryFunction, parent?: Component) { super(renderer, component, factory, parent); this.container.classList.add('scrollView'); } public init() { super.init(); } /** * @param component child component * @returns [offset,size on direction] * @memberof ScrollViewComponent */ public getChildTopOffset(component: Component): number { if (this.children.length === 0) { // no children return 0; } const topContainer = this.container; let element = component.container as HTMLElement; let top = 0; // use this instead of getClientBoundingRect to account for // scaling of the APLRenderer do { top += element.offsetTop || 0; element = element.offsetParent as HTMLElement; } while (element && element !== topContainer); return top; } public destroy() { $(this.container).off('scroll'); super.destroy(); } }