Skip to content

Instantly share code, notes, and snippets.

@alinz
Last active February 24, 2018 17:48
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 alinz/aa0e8ed48841df6ccbd7c5950a93a813 to your computer and use it in GitHub Desktop.
Save alinz/aa0e8ed48841df6ccbd7c5950a93a813 to your computer and use it in GitHub Desktop.
Styled Component in React-Native
// @flow
import * as React from 'react'
import { View, Text, ScrollView, StyleSheet } from 'react-native'
const styled = (Component: React.ComponentType<any>) => (style: any = {}) => {
const container = StyleSheet.create({ container: style }).container
return (props: any = {}) => {
const { style, ...rest } = props
return <Component style={[container, style]} {...rest} />
}
}
styled.View = styled(View)
styled.Text = styled(Text)
styled.ScrollView = styled(ScrollView)
export default styled
/**
example of using this
const MyView = styled.View({
flex: 1,
backgroundColor: 'red'
})
<MyView />
or
const StyledCustomComponent = styled(MyCustom)({
flex: 1,
backgroundColor: 'red'
})
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment