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

react-ptrcontainer

v0.2.0

Published

A React component providing `Pull to Refresh` a view, as well as `infinite scrolling`.

Downloads

8

Readme

react-ptrcontainer

A React component for web apps, providing Pull to Refresh a viewiOS only, as well as infinite scrollingiOS & Android tested.

Usage

import React from 'react';
import { PtrContainer, PtrStatus } from 'react-ptrcontainer';

let content = [];

function getPtrIndicator (status) {
    // What to display while loading:
    if (status == PtrStatus.LOADING) {
        return (<div>Loading ...</div>);
    }

    // What to display when not loading:
    return (<div>Pull to Refresh</div>)
}

function onRefresh (ptrContainer) {
    // Refresh the contents
    content = [];

    // Reset the PtrContainer's status to IDLE
    ptrContainer.setPtrStatus(PtrStatus.IDLE);
}

React.render((
    <PtrContainer pullToRefreshIndicator={getPtrIndicator} onRefresh={onRefresh}>
        {content.map((article) => (
            <div>{article.title}</div>
        ))}
    </PtrContainer>
), document.body);

The component will wrapp its children in a container that's not only scrollable, but can be panned vertically so that a second container becomes visible (the indicator).
The indicator can be rendered differently, depending on the component's current PtrStatus.

Optionally, one can enable "Infinite Scrolling" by using the properties infiniteScrollingIndicator and onLoadFurther. When the corresponding element enters the component's visible area, the onLoadFurther function will be invoked and additional content can be loaded and appended.

Props

Name | Type | Description -----------------------------|----------|------------ id | string | id attribute to apply to the component's DOM node. className | string | class attribute to apply to the component's DOM node. pullToRefreshIndicator | function | The "Pull to Refresh" indicator's content to be rendered. onRefresh | function | The function to invoke when "Pull to Refresh" has been triggered. infiniteScrollingIndicator | function | The "Infinite Scrolling" indicator's content to be rendered. onLoadFurther | function | The function to invoke when "Infinite Scrolling" has been triggered.

ScrollIntoViewportTrigger

The PtrContainer's "Infinite Scrolling" functionality can also be used out of the PtrContainer component.
Just import the correspondent component from the module:

import { ScrollIntoViewportTrigger } from 'react-ptrcomponent';

and use it in your own render method:

render () {

    return (

        // ...

        <ScrollIntoViewportTrigger onTrigger={onLoadFurther}>
            Loading more ...
        </ScrollIntoViewportTrigger>

        // ...

    );

}

Name | Type | Description ------------------|----------|------------ className | string | A class attribute to apply to the component's DOM node. onTrigger | function | The function to invoke when triggered. scrollContainer | object | Determines the scrollable element (as React component), if it is not the trigger component's parent.

Platform Support

PtrContainer Support for iOS only

As PtrContainer makes use of the iOS WebViews' native rubberband scrolling, it is currently not supporting any other platform... yet.

ScrollIntoViewportTrigger Support

ScrollIntoViewportTrigger has been successfully tested on iOS and Android.

Credits

Pull to Refresh bases upon visiongeist/pull-to-refresh-js.

hzdg/react-imageloader shamelessly used as kind of blueprint for the whole module setup, especially the tests.