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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cantonjs/react-scroll-view

v0.4.2

Published

react scroll component using intersection observer API

Downloads

1,327

Readme

This project is currently in beta and APIs are subject to change before v1.0 release.

react-scroll-view [WIP]

CircleCI Build Status

React scroll component using Intersection Observer API in favor of scroll events.

Features

  • Support sticky for cross browsers (including Mobile Safari)
  • Support refresh control
  • Support onEndReach(), onScrollStart() and onScrollEnd() events
  • Easy to observe the intersections between ScrollView and children

Installation

$ yarn add @cantonjs/react-scroll-view intersection-observer

Intersection Observer API is required. You should include the polyfill yourself for cross-browser support

Getting Started

import "intersection-observer";
import React, { Component } from "react";
import { ScrollView } from "@cantonjs/react-scroll-view";

export default class App extends Component {
  handleEndReached = () => {
    console.log("load more");
  };

  render() {
    return (
      <ScrollView onEndReached={this.handleEndReached} style={{ height: '100vh' }}>
        <h1>React Scroll View</h1>
        <p>Awseome!</p>
      </ScrollView>
    );
  }
}

References

ScrollView Component

import { ScrollView } from "@cantonjs/react-scroll-view";

Scroll view component

Props

| Property | Description | Type | | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | -------- | | style | These styles will be applied to the ScrollView container | Object | | className | The className will be applied to the ScrollView container | string | | contentContainerStyle | These styles will be applied to the ScrollView content container which wraps all of the child views | Object | | contentContainerClassName | The className will be applied to the ScrollView content container which wraps all of the child views | string | | onScroll | Fires at most once per frame during scrolling | Function | | onScrollStart | Called once when the scroll starts | Function | | onScrollEnd | Called once when the scroll ends | Function | | onEndReached | Called once when the scroll position gets within endReachedThreshold of the rendered content | Function | | endReachedThreshold | How far from the end (in pixels) the bottom to trigger the onEndReached callback | Number | | isHorizontal | When true, the ScrollView's children are arranged horizontally in a row instead of vertically in a column. Defaults to false | Boolean | | disabled | When true, the view cannot be scrolled. Defaults to false | Boolean | | refreshControl | A RefreshControl component, used to provide pull-to-refresh functionality for the ScrollView. Only works for vertical ScrollViews | Element | | innerRef | Use this to access the dom (DIV) ref | Function |

The rest of the props are exactly the same as the original DOM attributes.

Methods

| Method | Description | | ------------- | ------------------------------------ | | scrollTo(val) | Scrolls to a given value immediately |

ScrollObserver Component

import { ScrollObserver } from "@cantonjs/react-scroll-view";

Wrap any child component and observe it when in ScrollView.

Props

| Property | Description | Type | | -------- | ----------------------------------------------------------------------------------------- | -------- | | onEnter | Fires once when the children nodes enter | Function | | onLeave | Fires once when the children nodes leave | Function | | innerRef | Use this to access the internal ref | Function | | children | Children must be a function. Will receive an object with isIntersecting and ref props | Function |

Children function

The children prop will receive the following object shape:

| Property | Description | Type | | -------------- | --------------------------------------------------------------------------------------- | -------- | | ref | Must be passed down to your component's ref in order to obtain a proper node to observe | Function | | isIntersecting | Will be true if the target element intersects with the ScrollView | Boolean |

Example

import "intersection-observer";
import React, { Component } from "react";
import { ScrollView, ScrollObserver } from "@cantonjs/react-scroll-view";

export default class App extends Component {
  render() {
    return (
      <ScrollView style={{ height: '100vh' }}>
        <h1>React Scroll View</h1>
        <p>Awseome!</p>
        <ScrollObserver>
          {({ ref, isIntersecting }) =>
            <img
              ref={ref}
              src="/img.jpg"
              alt="lazy image"
              style={{ display: isIntersecting ? 'inline-block' : 'none' }}
            />
          }
        </ScrollObserver>
      </ScrollView>
    );
  }
}

StickySection Component

import { StickySection } from "@cantonjs/react-scroll-view";

Section component with a sticky header.

Props

| Property | Description | Type | | -------- | -------------------------- | ------------- | | sticky | Sticky header node element | Node/Function |

The rest of the props are exactly the same as the original DOM attributes.

Example

import "intersection-observer";
import React, { Component } from "react";
import { ScrollView, ScrollSection } from "@cantonjs/react-scroll-view";

export default class App extends Component {
  render() {
    return (
      <ScrollView style={{ height: '100vh' }}>
        <StickySection sticky={<h1>A</h1>}>
          <ul>
            <li>Adelia Pisano</li>
            <li>Alayna Loredo</li>
          </ul>
        </StickySection>
        <StickySection sticky={<h1>B</h1>}>
          <ul>
            <li>Brant Hunsberger</li>
          </ul>
        </StickySection>
        <StickySection sticky={<h1>C</h1>}>
          <ul>
            <li>Carl Wetzler</li>
            <li>Cherry Greeno</li>
            <li>Cris Kepley</li>
          </ul>
        </StickySection>
      </ScrollView>
    );
  }
}

RefreshControl Component

import { RefreshControl } from "@cantonjs/react-scroll-view";

RefreshControl component

Props

| Property | Description | Type | | ------------ | ------------------------------------------------------- | -------- | | onRefresh | Called when the view starts refreshing | Function | | isRefreshing | Whether the view should be indicating an active refresh | Boolean | | color | The refreshControl icon color | String |

The rest of the props are exactly the same as the original DOM attributes.

Methods

| Method | Description | | ---------------- | ----------------------------- | | requestRefresh() | Request to call onRefresh() |

Example

import "intersection-observer";
import React, { Component } from "react";
import { ScrollView, RefreshControl } from "@cantonjs/react-scroll-view";

export default class App extends Component {
  state = {
    isRefreshing: false,
  };
  
  handleRefresh = () => {
    this.setState({
      isRefreshing: true,
    });
  };

  render() {
    const { isRefreshing } = this.state;
    return (
      <ScrollView
        style={{ height: '100vh' }}
        refreshControl={
          <RefreshControl
            onRefresh={this.handleRefresh}
            isRefreshing={isRefreshing}
          />
        }
      >
        <h1>React Scroll View</h1>
        <p>Awseome!</p>
      </ScrollView>
    );
  }
}

License

MIT