Created
April 23, 2018 13:47
-
-
Save peterpme/27fe5557cea7252731d7181fa79259f5 to your computer and use it in GitHub Desktop.
Loading Screen with Naming
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 * 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); | |
LoadingScreen.displayName = `WithLoadingScreen(${getDisplayName( | |
WrappedComponent | |
)})`; | |
return LoadingScreen | |
}; | |
function getDisplayName(WrappedComponent) { | |
return ( | |
WrappedComponent.displayName || WrappedComponent.name || "LoadingScreen" | |
); | |
} | |
export default withLoadingScreen; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment