import * as React from 'react'; import { View, Text, ScrollView as NativeScrollView, FlatList as NativeFlatList, FlatListProps, Pressable } from 'react-native'; import type { ComponentProps, ReactNode, RefObject } from 'react'; type Unpromisify = T extends Promise ? R : T; /** * The following is taken/edited from `useScrollToTop` from `@react-navigation/native` */ type ScrollOptions = { y?: number; animated?: boolean; }; type ScrollableView = { scrollToTop(): void; } | { scrollTo(options: ScrollOptions): void; } | { scrollToOffset(options: { offset?: number; animated?: boolean; }): void; } | { scrollResponderScrollTo(options: ScrollOptions): void; }; type ScrollableWrapper = { getScrollResponder(): ReactNode; } | { getNode(): ScrollableView; } | ScrollableView; /** * End of react-navigation code. */ type ScrollToOptions = { animated?: boolean; /** * A number that determines how far from the content you want to scroll. * * Default: `-10`, which means it scrolls to 10 pixels before the content. */ offset?: number; }; export interface Anchors { } export type AnchorsRef = { scrollTo: (name: Anchor, options?: ScrollToOptions) => Promise<{ success: true; } | { success: false; message: string; }>; }; /** * If you need to control a `ScrollView` or `FlatList` from outside of their scope: * * ```jsx * import React from 'react' * import { useAnchors, ScrollView } from '@nandorojo/anchor' * * export default function App() { * const anchors = useAnchors() * * const onPress = () => { * anchors.current?.scrollTo('list') * } * * return ( * * * * ) * } * ``` */ declare const useAnchors: () => React.RefObject; type Anchor = Anchors['anchor'] extends string ? Anchors['anchor'] : string; type AnchorsContext = { targetRefs: RefObject>; scrollRef: RefObject; registerTargetRef: (name: Anchor, ref: View | Text) => void; registerScrollRef: (ref: ScrollableWrapper | null) => void; horizontal: ComponentProps['horizontal']; scrollTo: AnchorsRef['scrollTo']; }; declare const AnchorsContext: React.Context; declare function useRegisterTarget(): { register: (name: Anchor) => (ref: View) => void; }; declare function useScrollTo(): { scrollTo: (name: Anchor, options?: ScrollToOptions) => Promise<{ success: true; } | { success: false; message: string; }>; }; declare function useRegisterScroller(): { registerScrollRef: (ref: ScrollableWrapper | null) => void; }; declare function AnchorProvider({ children, horizontal, anchors }: { children: ReactNode; anchors?: RefObject; } & Pick): import("react/jsx-runtime").JSX.Element; /** * Identical to the normal React Native `ScrollView`, except that it allows scrolling to anchor links. * * If you use this component, you don't need to use the `AnchorProvider`. It implements it for you. */ declare const ScrollView: React.ForwardRefExoticComponent; } & Pick, "anchors"> & React.RefAttributes>; /** * Identical to the normal React Native flatlist, except that it allows scrolling to anchor links. * * If you use this component, you don't need to use the `AnchorProvider`. * * One important difference: if you want to use the `ref`, pass it to `flatListRef` instead of `ref`. */ declare function FlatList({ flatListRef, horizontal, anchors, ...props }: FlatListProps & { flatListRef?: RefObject; } & Pick, 'anchors'>): import("react/jsx-runtime").JSX.Element; declare function ScrollTo({ target, onPress, options, onRequestScrollTo, ...props }: { children?: ReactNode; target: Anchor; options?: ScrollToOptions; onRequestScrollTo?: (props: Unpromisify['scrollTo']>>) => void; } & ComponentProps): import("react/jsx-runtime").JSX.Element; declare const Target: React.ForwardRefExoticComponent<{ name: Anchor; children?: ReactNode; } & import("react-native").ViewProps & React.RefAttributes>; declare const AnchorsConsumer: React.Consumer; export { AnchorProvider, ScrollView, FlatList, useRegisterTarget, useScrollTo, ScrollTo, Target, ScrollTo as Anchor, useRegisterScroller, useAnchors, AnchorsConsumer }; //# sourceMappingURL=index.d.ts.map