11import React , { PropsWithChildren , createElement , useContext } from 'react'
22import {
3+ ActivityIndicator ,
34 Button ,
5+ DrawerLayoutAndroid ,
46 FlatList ,
57 Image ,
68 ImageBackground ,
@@ -12,6 +14,7 @@ import {
1214 ScrollView ,
1315 SectionList ,
1416 StyleProp ,
17+ Switch ,
1518 Text ,
1619 TextInput ,
1720 TouchableHighlight ,
@@ -33,26 +36,15 @@ import {
3336 AsComponentProps ,
3437 UnknownStyles ,
3538 StyledObject ,
39+ StyledComponent ,
40+ AnyStyleProps ,
3641} from './types'
3742import { buildPropsFromAttrs } from './buildPropsFromAttrs'
3843import { substitute , runtime , mixin } from './parsers'
3944import { createTheme } from './theme'
4045import { splitAttrs } from './splitAttrs'
4146import { buildDynamicStyles } from './buildDynamicStyles'
42- import { isFunction } from './utils'
43-
44- interface AnyStyleProps {
45- style ?: StyleProp < UnknownStyles >
46- }
47-
48- type StyledComponent = React . ForwardRefExoticComponent < Omit < React . PropsWithChildren < UnknownProps & AnyStyleProps & AsComponentProps > , "ref" > & React . RefAttributes < unknown > > & {
49- isStyled ?: boolean
50- initialStyles : UnknownStyles
51- attrs : InnerAttrs [ ]
52- origin : AnyComponent
53- }
54-
55- const isStyledComponent = ( component : AnyComponent ) : component is StyledComponent => ! ! ( component as StyledComponent ) ?. isStyled
47+ import { isFunction , isStyledComponent } from './utils'
5648
5749const methods = {
5850 substitute,
@@ -70,7 +62,7 @@ export function createStyled<Theme extends AnyTheme>() {
7062 throw new Error ( 'It seems you forgot to add babel plugin.' )
7163 }
7264 }
73- initialStyles = isStyledComponent ( Component ) ? { ...Component . initialStyles , ...initialStyles } : initialStyles
65+ initialStyles = isStyledComponent ( Component ) ? { ...Component . styles , ...initialStyles } : initialStyles
7466 attrs = isStyledComponent ( Component ) ? [ ...Component . attrs , ...attrs ] : attrs
7567 const hasDynamicStyles = Object . keys ( initialStyles ) . some ( ( key ) => isFunction ( initialStyles [ key ] ) )
7668 const fixedStyle = hasDynamicStyles ? undefined : initialStyles
@@ -112,7 +104,7 @@ export function createStyled<Theme extends AnyTheme>() {
112104
113105 StyledComponent . displayName = 'StyledComponent'
114106 StyledComponent . isStyled = true
115- StyledComponent . initialStyles = initialStyles
107+ StyledComponent . styles = initialStyles
116108 StyledComponent . attrs = attrs
117109 StyledComponent . defaultProps = Object . assign ( { style : fixedStyle } , fixedProps )
118110 StyledComponent . origin = origin
@@ -129,10 +121,12 @@ export function createStyled<Theme extends AnyTheme>() {
129121 innerStyled . attrs = attrs ( innerStyled )
130122 // We use as unknown as Type constraction here becasue
131123 // it is expected that argument so the styled function is transformed to an Array<Array> type during Babel transpilation.
132- return innerStyled as Styled < C , Theme >
124+ return innerStyled as unknown as Styled < C , Theme >
133125 }
134126
127+ styled . ActivityIndicator = styled ( ActivityIndicator )
135128 styled . Button = styled ( Button )
129+ styled . DrawerLayoutAndroid = styled ( DrawerLayoutAndroid )
136130 styled . FlatList = styled ( FlatList )
137131 styled . Image = styled ( Image )
138132 styled . KeyboardAvoidingView = styled ( KeyboardAvoidingView )
@@ -142,6 +136,7 @@ export function createStyled<Theme extends AnyTheme>() {
142136 styled . SafeAreaView = styled ( SafeAreaView )
143137 styled . ScrollView = styled ( ScrollView )
144138 styled . SectionList = styled ( SectionList )
139+ styled . Switch = styled ( Switch )
145140 styled . Text = styled ( Text )
146141 styled . TextInput = styled ( TextInput )
147142 styled . TouchableHighlight = styled ( TouchableHighlight )
0 commit comments