react-native-scroll-to-enhanced
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

react-native-scroll-to-enhanced

Some extra scrolling methods for scroll views

yarn add react-native-scroll-to-enhanced

Uses native code. React Native 0.61+ will handle this automatically. For older versions, follow whatever other packages do.

import React from "react";
import { View, ScrollView } from "react-native";
import { scrollToRect, scrollToView } from "react-native-scroll-to-enhanced";
 
const Example = () => {
  const scrollview = React.useRef();
  const view = React.useRef();
 
  const scrollToRectExample = () => {
    // Scroll to an exact rectangle
    // No-ops if the rectangle is already fully visible on screen
    scrollToRect(scrollview.current, {
      x: 50,
      y: 100,
      width: 200,
      height: 200
    });
  };
 
  const scrollToViewExample = () => {
    // Scroll to any child view
    // Does not need to be a direct descendant
    // No-ops if the child view is already fully visible on screen
    scrollToView(scrollview.current, view.current);
  };
 
  return (
    <ScrollView ref={scrollview}>
      <View ref={view} />
    </ScrollView>
  );
};
type scrollToRect = (
  scrollview: any,
  rect: {
    x: number,
    y: number,
    width: number,
    height: number,
    animated?: boolean
  }
) => void;
 
type scrollToView = (
  scrollview: any,
  view: any,
  rect?: { animated?: boolean }
) => void;

For a more complex example, including multi-directional scrolling, see the example

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.2
    2
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.2
    2
  • 1.0.1
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i react-native-scroll-to-enhanced

Weekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

31.1 kB

Total Files

17

Last publish

Collaborators

  • jacobp100