npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-native-scroll-to-child

v0.2.1

Published

Scroll a ScrollView's child into the visible viewport

Readme

react-native-scroll-to-child

Programmatically scroll a React Native ScrollView's child into view, either vertically, horizontally, or both.

npm downloads npm version CI codecov

[!NOTE] Why a hard-fork? The original project is not actively maintained, and I needed to add support for horizontal scrolling. This fork also aims to improve code readability and modernization. If you find this package useful, please consider starring the original repository as well!

Installation

pnpm install react-native-scroll-to-child

Features

  • Declarative Component API: Use the <ScrollIntoView /> component for a straightforward approach.
  • Imperative Hook API: Access useScrollIntoView() for more complex, event-driven scrolling.
  • Highly Configurable: Customize scroll behavior at multiple levels.
  • Alignment Modes: Control where the element aligns within the ScrollView (auto, start, end, center).
  • Insets: Add top and bottom insets to prevent elements from touching the ScrollView edges.
  • Horizontal & Vertical: Works for both vertical and horizontal ScrollViews.
  • TypeScript Support: Fully typed for a better development experience.
  • Composition Friendly: Supports Animated.ScrollView, react-native-keyboard-aware-scroll-view, and other ScrollView wrappers.

Examples

Declarative Component

This is the simplest way to use the library. Wrap the child you want to scroll to in the ScrollIntoView component and control its state with a boolean.

import { View, Text, ScrollView, Button } from 'react-native';
import { wrapScrollView, ScrollIntoView } from 'react-native-scroll-to-child';
import { useState } from 'react';

const CustomScrollView = wrapScrollView(ScrollView);

function MyScreen() {
    const [show, setShow] = useState(false);

    return (
        <CustomScrollView>
            <Button title="Scroll to View" onPress={() => setShow(true)} />
            <View style={{ height: 1000 }} />
            <ScrollIntoView show={show}>
                <Text>This view will be scrolled into view!</Text>
            </ScrollIntoView>
        </CustomScrollView>
    );
}

Imperative Hook

For more control, you can use the useScrollIntoView hook to scroll a ref into view imperatively.

import { View, Text, ScrollView, Button, Alert } from 'react-native';
import { wrapScrollView, useScrollIntoView } from 'react-native-scroll-to-child';
import { useRef } from 'react';

const CustomScrollView = wrapScrollView(ScrollView);

function MyScreen() {
    return (
        <CustomScrollView>
            <MyScreenContent />
        </CustomScrollView>
    );
}

function MyScreenContent() {
    const viewRef = useRef<View>(null);
    const scrollIntoView = useScrollIntoView();

    const handlePress = () => {
        if (viewRef.current) {
            scrollIntoView(viewRef.current, {
                align: 'center',
                animated: true,
            });
        } else {ß
            Alert.alert("Error", "The view isn't mounted yet.");
        }
    };

    return (
        <>
            <Button onPress={handlePress} title="Scroll to View" />
            <View style={{ height: 1000 }}>
                <Text>Some long ScrollView content</Text>
            </View>
            <View ref={viewRef}>
                <Text>This view will be scrolled into view on button press!</Text>
            </View>
        </>
    );
}

API

wrapScrollView(ScrollViewComponent, options?) Higher-Order Component (HOC)

This higher-order component wraps your ScrollView to provide the necessary context for scrolling.

  • ScrollViewComponent: The ScrollView component to wrap (e.g., ScrollView, Animated.ScrollView).
  • options (optional): Default options for all scrollIntoView calls within this ScrollView.

useScrollIntoView() Hook

A hook that returns the scrollIntoView function.

  • scrollIntoView(ref, options?): Scrolls the given ref into view.
    • ref: A ref to the component you want to scroll to.
    • options (optional): Override the default options for this specific call.

ScrollIntoView Component

A component that wraps a child and scrolls it into view based on the show prop.

  • show: A boolean that, when true, scrolls the child into view.
  • options (optional): Override the default options for this component.

| Option | Type | Default | Description | | ------------------ | ------------------------------------------------------------------ | ------------ | ------------------------------------------------------------------------------------------------------- | | align | 'auto', 'start', 'end', 'center' | 'auto' | Determines the alignment of the element within the ScrollView. | | animated | boolean | true | Whether to animate the scroll. | | immediate | boolean | false | If true, the call is not throttled. Useful for high-priority scrolls. | | insets | { top: number, bottom: number, left: number, right: number } | {...} | Adds padding around the element when scrolling it into view. | | computeScrollY | (scrollViewLayout, viewLayout, scrollY, insets, align) => number | undefined | Advanced: Override the default vertical scroll calculation. | | computeScrollX | (scrollViewLayout, viewLayout, scrollX, insets, align) => number | undefined | Advanced: Override the default horizontal scroll calculation. | | measureElement | (viewRef) => Promise<LayoutRectangle> | undefined | Advanced: Override how the element's layout is measured. |

Advanced Usage

You can provide custom configuration to wrapScrollView for advanced use cases, such as when using a custom ScrollView wrapper.

// All HOC configurations can also be passed as props to the wrapped `ScrollView` component.

const CustomScrollView = wrapScrollView(MyCustomScrollView, {
  // Provide default options for all scroll calls
  options: {
    align: 'center',
  },
  // If your custom ScrollView nests the underlying ScrollView,
  // provide a function to extract the actual ScrollView node.
  getScrollViewNode: ref => ref.getScrollView(),
  // Set a default throttle value for scroll events.
  scrollEventThrottle: 16,
});