UNPKG

@bestyled/contrib-flatlist

Version:

Implementation of FlatList for the BeStyled Design System

69 lines (68 loc) 2.42 kB
export declare enum ALIGNMENT { AUTO = "auto", START = "start", CENTER = "center", END = "end" } export declare type ItemSizeGetter = (index: number) => number; export interface SizeAndPosition { size: number; offset: number; } export interface Options { itemCount: number; estimatedItemSize: number; } export default class SizeAndPositionManager { private itemCount; private estimatedItemSize; lastMeasuredIndex: number; private itemSizeAndPositionData; constructor({ itemCount, estimatedItemSize }: Options); resize({ itemCount, estimatedItemSize }: Partial<Options>): void; private getSizeForIndex; /** * This method returns the size and position for the item at the specified index. * It calculates (or used cached values) for items leading up to the index. */ getSizeAndPositionForIndex(index: number): SizeAndPosition; setItem(index: number, size: number): boolean; private getSizeAndPositionOfLastMeasuredItem; /** * Total size of all items being measured. * This value will be completedly estimated initially. * As items as measured the estimate will be updated. */ getTotalSize(): number; /** * Determines a new offset that ensures a certain item is visible, given the alignment. * * @param align Desired alignment within container; one of "start" (default), "center", or "end" * @param containerSize Size (width or height) of the container viewport * @return Offset to use to ensure the specified item is visible */ getUpdatedOffsetForIndex({ align, containerSize, currentOffset, targetIndex }: { align: ALIGNMENT | string | undefined; containerSize: number; currentOffset: number; targetIndex: number; }): number; getVisibleRange({ containerSize, offset, overscanCount }: { containerSize: number; offset: number; overscanCount: number; }): { start?: number; stop?: number; paddingTop?: number; }; /** * Searches for the item (index) nearest the specified offset. * * If no exact match is found the next lowest item index will be returned. * This allows partially visible items (with offsets just before/above the fold) to be visible. */ private findNearestItem; private binarySearch; private exponentialSearch; }