/**
 * Created by ananya.chandra on 20/09/18.
 */ import StickyObject , { StickyObjectProps , StickyType } from "./StickyObject" ; import BinarySearch , { ValueAndIndex } from "../../utils/BinarySearch" ; import { WindowCorrection } from "../ViewabilityTracker" ; export default class StickyHeader < P extends StickyObjectProps > extends StickyObject < P > { constructor ( props , context ? ) { super ( props , context ) ; } public onScroll ( offsetY ) { const startCorrection = this . getWindowCorrection ( this . props ) . startCorrection ; if ( startCorrection ) { this . containerPosition = { top : startCorrection } ; offsetY += startCorrection ; } super . onScroll ( offsetY ) ; } protected initStickyParams ( ) { this . stickyType = StickyType . HEADER ; this . stickyTypeMultiplier = 1 ; this . containerPosition = { top : this . getWindowCorrection ( this . props ) . startCorrection } ; this . bounceScrolling = true ; } protected calculateVisibleStickyIndex ( stickyIndices , smallestVisibleIndex , largestVisibleIndex , offsetY , windowBound ? ) { if ( stickyIndices && smallestVisibleIndex !== undefined ) { this . bounceScrolling = this . hasReachedBoundary ( offsetY , windowBound ) ; if ( smallestVisibleIndex < stickyIndices [ 0 ] || this . bounceScrolling ) { this . stickyVisiblity = false ; } else { this . stickyVisiblity = true ; const valueAndIndex = BinarySearch . findValueSmallerThanTarget ( stickyIndices , smallestVisibleIndex ) ; if ( valueAndIndex ) { this . currentIndex = valueAndIndex . index ; this . currentStickyIndex = valueAndIndex . value ; } else { console . log ( "Header sticky index calculation gone wrong." ) ; } } } } protected getNextYd ( nextY , nextHeight ) { return nextY ; } protected getCurrentYd ( currentY , currentHeight ) { return currentY ; } protected getScrollY ( offsetY , scrollableHeight ) { return offsetY ; } protected hasReachedBoundary ( offsetY , _windowBound ? ) { return false ; } }