Last active
January 2, 2017 21:34
-
-
Save ericnograles/93e37a32cdb50d1ed34c98e374b3ca9f to your computer and use it in GitHub Desktop.
A Generic React Native Higher Order Component for a Loading Screen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { View, ActivityIndicator, Dimensions } from 'react-native' | |
import * as Animatable from 'react-native-animatable'; // TODO: Please install react-native-animatable as a dependency | |
const window = Dimensions.get('window'); | |
export default class LoadingView extends React.Component { | |
componentWillUpdate(nextProps) { | |
const { loading } = this.props; | |
if (this.refs.view && loading !== nextProps.loading) { | |
this.refs.view.fadeIn(300); | |
} | |
} | |
render() { | |
const { loading, children } = this.props; | |
let appliedStyle = {flex: 1}; | |
return ( | |
<Animatable.View ref="view" style={appliedStyle}> | |
{loading && | |
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}> | |
<ActivityIndicator size="large" /> | |
</View>} | |
{!loading && children} | |
</Animatable.View> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment