All Projects → LifCare → react-native-stateview

LifCare / react-native-stateview

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

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-native-stateview

react-simple-image-slider
simple image slider component for react
Stars: ✭ 127 (+353.57%)
Mutual labels:  react-component
react-credit-cards
Beautiful credit cards for your payment forms
Stars: ✭ 2,386 (+8421.43%)
Mutual labels:  react-component
animation-wrapper-view
Declarative animations with imperative controls for RN/RNW.
Stars: ✭ 53 (+89.29%)
Mutual labels:  react-component
fhir-questionnaire-render-react
Render FHIR Questionnaire as a web form using FHIRFormJS
Stars: ✭ 18 (-35.71%)
Mutual labels:  react-component
react-drag-list
A simple draggable list component。
Stars: ✭ 30 (+7.14%)
Mutual labels:  react-component
fluent-windows
🌈 React components that inspired by Microsoft's Fluent Design System.
Stars: ✭ 122 (+335.71%)
Mutual labels:  react-component
tiny-ui
⚛️ A friendly UI component set for React.js
Stars: ✭ 202 (+621.43%)
Mutual labels:  react-component
react-markdown-heading
Render markdown table of contents as React component.
Stars: ✭ 18 (-35.71%)
Mutual labels:  react-component
react-timepicker
React timepicker in Android KitKat style
Stars: ✭ 23 (-17.86%)
Mutual labels:  react-component
histoslider
📊 A D3 based histogram slider component for React.
Stars: ✭ 31 (+10.71%)
Mutual labels:  react-component
esn
这是一个常用js小型工具库
Stars: ✭ 15 (-46.43%)
Mutual labels:  react-component
react-table-filter
Create Filters on table column items(like Excel)
Stars: ✭ 54 (+92.86%)
Mutual labels:  react-component
react-crud-icons
57 SVG icons for CRUD applications, packaged as a React component with light & dark themes and tooltip.
Stars: ✭ 19 (-32.14%)
Mutual labels:  react-component
react-infinite-scroller
⏬ Infinite scroll component for React in ES6
Stars: ✭ 3,064 (+10842.86%)
Mutual labels:  react-component
React-Limited-Infinite-Scroll
A limited infinite scroll component for React(React有限无限加载组件)
Stars: ✭ 37 (+32.14%)
Mutual labels:  react-component
VOSviewer-Online
VOSviewer Online is a tool for network visualization. It is a web-based version of VOSviewer, a popular tool for constructing and visualizing bibliometric networks.
Stars: ✭ 44 (+57.14%)
Mutual labels:  react-component
react-crossfade-image
react-crossfade-image - Simple React component for crossfading images - No CSS needed
Stars: ✭ 33 (+17.86%)
Mutual labels:  react-component
react-accessible-modal
Accessible modal dialog component for React
Stars: ✭ 17 (-39.29%)
Mutual labels:  react-component
react-async-button
React button component for handling async actions
Stars: ✭ 31 (+10.71%)
Mutual labels:  react-component
react-material-datetimepicker
Material DateTime Picker для React.js
Stars: ✭ 12 (-57.14%)
Mutual labels:  react-component

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 {}

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].