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-native-stateview

v1.1.5

Published

A react native wrapper view to add loading, content, error and placeholder states to your component

Downloads

20

Readme

react-native-stateview

A react native wrapper view to add loading, content, error and placeholder states to your component

Expo

Try it out on expo. Just download the expo app, scan code and you are good to go.

Installation

Using npm:

npm i --save react-native-stateview

Using yarn:

yarn add react-native-stateview

##Usage

You can wrap your view in StateView to give states to it. The StateView has with 4 states: loading, content, placeholder and error.

Import react-native-keyboard-aware-scroll-view and wrap your content inside it:

import StateView from 'react-native-stateview'
<StateView>
    <View>
        // ...
    </View>
</StateView>

There are some props which you can use to configure the StateView, as given below in API section, but all of them are optional.

API

Props

Generic Props

| Prop | Type | Defaults | Description | |----------|----------|--------------|-----------------| | containerStyle | PropTypes.object | {} | Style of container view | | state | PropTypes.oneOf([StateView.State.loading, StateView.State.placeholder, StateView.State.error, StateView.State.content]) | StateView.State.loading | The state of StateView. | | color | PropTypes.string | '#000' | A general tint color for all views. | | imageStyle | PropTypes.object | {} | Styles for image of placeholder and error view. Overrides the default styles. | | titleStyle | PropTypes.object | {} | Styles for title of loading, placeholder and error view. Overrides the default styles. | | bodyStyle | PropTypes.object | {} | Styles for body of placeholder and error view. Overrides the default styles. | | buttonStyle | PropTypes.object | {} | Styles for button of placeholder and error view. Overrides the default styles. | | buttonTextStyle | PropTypes.object | {} | Styles for button text of placeholder and error view. Overrides the default styles. |

Loading View Props

| Prop | Type | Defaults | Description | |----------|----------|--------------|-----------------| | loadingView | PropTypes.element | undefined | A custom loading view. | | loadingTitle | PropTypes.string | '' | The title for the default loading view. | | loadingTitleStyle | PropTypes.object | {} | Styles for title of loading view. Overrides the titleStyle and default styles. |

Placeholder View Props

| Prop | Type | Defaults | Description | |----------|----------|--------------|-----------------| | placeholderView | PropTypes.element | undefined | A custom placeholder view | | placeholderImageRes | PropTypes.number.isRequirednumber | - | Image resource id of the placeholder view image | | placeholderTitle | PropTypes.string | '' | Title text of the placeholder view | | placeholderBody | PropTypes.string | '' | Body text of the placeholder view | | placeholderButtonText | PropTypes.string | '' | Action button text of the placeholder view | | placeholderButtonAction | PropTypes.func | () => {} | Function that is executed when the placeholder view button is clicked. The button is not rendered if this is null or undefined | | placeholderImageStyle | PropTypes.object | {} | Styles for image of placeholder view. Overrides the imageStyle and default styles. | | placeholderTitleStyle | PropTypes.object | {} | Styles for title of placeholder view. Overrides the titleStyle and default styles. | | placeholderBodyStyle | PropTypes.object | {} | Styles for body of placeholder view. Overrides the bodyStyle and default styles. | | placeholderButtonStyle | PropTypes.object | {} | Styles for button of placeholder view. Overrides the buttonStyle and default styles. | | placeholderButtonTextStyle | PropTypes.object | {} | | Styles for button text of placeholder view. Overrides the buttonTextStyle and default styles. |

Error View Props

| Prop | Type | Defaults | Description | |----------|----------|--------------|-----------------| | errorView | PropTypes.element | undefined | A custom error view | | errorImageRes | PropTypes.number.isRequirednumber | - | Image resource id of the error view image | | errorTitle | PropTypes.string | '' | Title text of the error view | | errorBody | PropTypes.string | '' | Body text of the error view | | errorButtonText | PropTypes.string | '' | Action button text of the error view | | errorButtonAction | PropTypes.func | () => {} | Function that is executed when the error view button is clicked. The button is not rendered if this is null or undefined | | errorImageStyle | PropTypes.object | {} | Styles for image of error view. Overrides the imageStyle and default styles. | | errorTitleStyle | PropTypes.object | {} | Styles for title of error view. Overrides the titleStyle and default styles. | | errorBodyStyle | PropTypes.object | {} | Styles for body of error view. Overrides the bodyStyle and default styles. | | errorButtonStyle | PropTypes.object | {} | Styles for button of error view. Overrides the buttonStyle and default styles. | | errorButtonTextStyle | PropTypes.object | {} | Styles for button text of error view. Overrides the buttonTextStyle and default styles. |

Usage

A StateView with some styles overridded looks something like this:

<StateView
    style={styles.container}
    state={this.state.state}
    color="#5430EC"

    imageStyle={{
        width: 100,
        height: 100,
    }}
    placeholderTitleStyle={{
        color: '#5430EC',
        fontSize: 30
    }}
    buttonStyle={{
        borderRadius: 100,
        shadowColor: '#333',
        shadowOpacity: .6,
        shadowOffset: {
            width: 0,
            height: 3
        }
    }}

    loadingView={(
        <View>
            <ActivityIndicator
                color="#24B32D"
                size="large"/>
            <Text style={{
                fontSize: 20,
                textAlign: 'center',
                marginTop: 20,
                color: '#24B32D',
                fontWeight: 'bold'
            }}>
                Let me see what's cooking...
            </Text>
        </View>
    )}

    placeholderImageRes={require("./icons/ic_pizza.png")}
    placeholderTitle="We're all out!"
    placeholderBody={`It looks like we all out of dishes.\nCome back tomorrow for a nice slice of pizza!`}
    placeholderButtonText="How about now?"
    placeholderButtonAction={() => this._handleRefresh(0)}

    errorImageRes={require("./icons/ic_salt.png")}
    errorTitle="Eh?! This shouldn't be happening"
    errorBody="Don't get so salty. We're working on it!"
    errorButtonText="FIX IT NOW!"
    errorButtonAction={() => this._handleRefresh(0)}
    errorTitleStyle={{
        color: '#E83F6F',
        fontSize: 25
    }}
    errorBodyStyle={{
        color: '#E83F6F',
        marginTop: 10,
        fontSize: 15
    }}
    errorButtonStyle={{
        backgroundColor: '#E83F6F'
    }}
    errorButtonTextStyle={{
        color: '#fff2f6'
    }}
    >

    // ... your content view goes here

    </StateView>

This does look cluttered but StateView has some decent styles for every component and in most cases you should be good to go by just setting color prop to your app's primary color, along with the title, body, button text and it's action. But if you do prefer styling it completely, we recommend you create a component which wraps the StateView and sets all the styles so you don't have to do it everywhere manually.

License

MIT.