Skip to content

Instantly share code, notes, and snippets.

@peterpme
Created April 19, 2018 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterpme/fceb24be3601b7f4d9e63161abddcf16 to your computer and use it in GitHub Desktop.
Save peterpme/fceb24be3601b7f4d9e63161abddcf16 to your computer and use it in GitHub Desktop.
withLoadingScreen HOC with options
import * as React from "react";
import hoistNonReactStatics from 'hoist-non-react-statics';
import { View, ActivityIndicator } from "react-native";
const withLoadingScreen = (size = "small") => WrappedComponent => {
class LoadingScreen extends React.PureComponent {
render() {
if (this.props.loading) return <ActivityIndicator size={size} color="white" />
return <WrappedComponent {...this.props} />;
}
};
hoistNonReactStatics(LoadingScreen, WrappedComponent);
return LoadingScreen
};
export default withLoadingScreen;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment