Skip to content

Instantly share code, notes, and snippets.

@ssomnoremac
Last active August 21, 2017 17:49
Show Gist options
  • Save ssomnoremac/21ea4032c4bf5044e7fc34fe7f44a341 to your computer and use it in GitHub Desktop.
Save ssomnoremac/21ea4032c4bf5044e7fc34fe7f44a341 to your computer and use it in GitHub Desktop.
import React from 'react';
import {
View,
Image,
ListView,
ScrollView,
Text,
TouchableHighlight,
TouchableNativeFeedback,
TouchableOpacity,
TouchableWithoutFeedback,
StyleSheet
} from 'react-native'
let Styled = {}
const StyledComponent = (Component) => (styles) => (props) => {
const {
styles: inlineStyles,
children,
...otherProps,
} = props
const cachedStyles = StyleSheet.create(styles)
return(
<Component style={[cachedStyles, inlineStyles]} {...otherProps}>
{children}
</Component>
)
};
Styled.View = StyledComponent(View)
Styled.Image = StyledComponent(Image)
Styled.ListView = StyledComponent(ListView)
Styled.ScrollView = StyledComponent(ScrollView)
Styled.Text = StyledComponent(Text)
Styled.TouchableHighlight = StyledComponent(TouchableHighlight)
Styled.TouchableNativeFeedback = StyledComponent(TouchableNativeFeedback)
Styled.TouchableOpacity = StyledComponent(TouchableOpacity)
Styled.TouchableWithoutFeedback = StyledComponent(TouchableWithoutFeedback)
export default Styled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment