react-native-scroll-to-child
Version:
Scroll a ScrollView's child into the visible viewport
86 lines (77 loc) • 3.18 kB
text/typescript
import * as React from 'react';
import React__default, { ComponentType } from 'react';
import * as react_native from 'react-native';
import { LayoutRectangle, ScrollView, View } from 'react-native';
declare const computeScrollY: (scrollViewLayout: LayoutRectangle, viewLayout: LayoutRectangle, scrollY: number, insets: Insets, align: Align) => number;
declare const computeScrollX: (scrollViewLayout: LayoutRectangle, viewLayout: LayoutRectangle, scrollX: number, insets: Insets, align: Align) => number;
type FindNodeHandleArg = null | number | React__default.Component<any, any> | React__default.ComponentClass<any>;
declare const measureElement: (element: FindNodeHandleArg) => Promise<LayoutRectangle>;
type Insets = {
top?: number;
bottom?: number;
left?: number;
right?: number;
};
type Align = 'auto' | 'start' | 'end' | 'center';
type FullOptions = {
align: Align;
animated: boolean;
immediate: boolean;
insets: Insets;
computeScrollY: typeof computeScrollY;
computeScrollX: typeof computeScrollX;
measureElement: typeof measureElement;
};
type PartialOptions = Partial<FullOptions>;
type FullHOCConfig = {
getScrollViewNode: (scrollView: ScrollView) => ScrollView;
scrollEventThrottle: 16;
options: PartialOptions;
};
type PartialHOCConfig = Partial<FullHOCConfig>;
type ScrollViewProps = React__default.ComponentProps<typeof ScrollView>;
type HOCProps = ScrollViewProps & {
scrollIntoViewOptions?: PartialOptions;
scrollEventThrottle?: number;
contentOffset?: {
x: number;
y: number;
};
ref?: React__default.RefObject<ScrollView | null>;
};
type WrappableScrollView = ComponentType<ScrollViewProps>;
type WrappedScrollView = ComponentType<HOCProps>;
type GetScrollView = () => ScrollView;
type GetScrollY = () => number;
type GetScrollX = () => number;
type GetDefaultOptions = () => FullOptions;
type ScrollIntoViewDependencies = {
readonly getScrollView: GetScrollView;
readonly getScrollY: GetScrollY;
readonly getScrollX: GetScrollX;
readonly getDefaultOptions: GetDefaultOptions;
};
declare class ScrollIntoViewAPI {
private readonly dependencies;
constructor(dependencies: ScrollIntoViewDependencies);
private validateDependencies;
private getNormalizedOptions;
scrollIntoView: (view: View, options?: PartialOptions) => Promise<void>;
private performScroll;
private scrollIntoViewThrottled;
private scrollIntoViewImmediate;
}
declare function useScrollIntoView(): ScrollIntoViewAPI['scrollIntoView'];
declare const ScrollIntoView: React.ForwardRefExoticComponent<{
enabled?: boolean;
scrollIntoViewKey?: string | number | boolean;
animated?: boolean;
immediate?: boolean;
onMount?: boolean;
onUpdate?: boolean;
scrollIntoViewOptions?: PartialOptions;
scrollIntoViewAPI?: ScrollIntoViewAPI;
children?: React.ReactNode;
} & Partial<FullOptions> & react_native.ViewProps & React.RefAttributes<react_native.View>>;
declare const wrapScrollView: (comp: WrappableScrollView, config?: PartialHOCConfig) => WrappedScrollView;
export { ScrollIntoView, useScrollIntoView, wrapScrollView };