@@ -14,7 +14,7 @@ import {
1414 SectionList ,
1515} from 'react-native' ;
1616import type { StyledComponent , CompiledStyles , AttrsFunction } from './types' ;
17- import type { StyleMetadata , StyledFactory , StyleObject , PropsWithTheme , StyleValue , DynamicPatchFunction } from './types/styled-types' ;
17+ import type { StyleMetadata , StyledFactory , StyleObject , PropsWithTheme , StyleValue , DynamicPatchFunction , AttrsValue } from './types/styled-types' ;
1818import { useTheme } from './theme' ;
1919import { parseCSS } from './css-runtime-parser' ;
2020import {
@@ -32,6 +32,7 @@ import {
3232 filterProps ,
3333 hasTransientProps ,
3434 mergeAttrsWithProps ,
35+ combineAttrs ,
3536} from './utils/props-filter' ;
3637
3738/**
@@ -71,6 +72,8 @@ function styledFunction<C extends ComponentType<any>, P = {}, AttrsP = {}>(
7172
7273 // Extract base component's metadata (handles Animated components)
7374 const baseMetadata = extractBaseMetadata ( BaseComponent ) ;
75+ const combinedAttrs = combineAttrs ( baseMetadata . attrs , attrs ) ;
76+ const hasAttrs = Boolean ( combinedAttrs ) ;
7477
7578 // Merge parent and child styles
7679 const { mergedCompiledStyles, mergedStyleKeys } = mergeMetadata (
@@ -85,11 +88,11 @@ function styledFunction<C extends ComponentType<any>, P = {}, AttrsP = {}>(
8588 ) ;
8689
8790 const StyledComponent = forwardRef < unknown , Record < string , unknown > > ( ( props , ref ) => {
88- // eslint-disable-next-line @typescript-eslint/no-explicit-any
89- const Component = ( props . as || BaseComponent ) as ComponentType < any > ;
90-
9191 // Fast path: static styles only (no dynamic, no attrs, no external style)
92- if ( ! getDynamicPatch && ! attrs && ! props . style ) {
92+ if ( ! getDynamicPatch && ! hasAttrs && ! props . style ) {
93+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
94+ const Component = ( props . as || BaseComponent ) as ComponentType < any > ;
95+
9396 // Check if we have any transient props first
9497 const hasTransient = hasTransientProps ( props ) ;
9598
@@ -105,13 +108,13 @@ function styledFunction<C extends ComponentType<any>, P = {}, AttrsP = {}>(
105108 }
106109
107110 // Slow path: dynamic styles, attrs, or external styles
108- // eslint-disable-next-line @typescript-eslint/no-unused-vars
109- const { as : _ , style : externalStyle , ...restProps } = props ;
111+ const { as : asProp , style : externalStyle , ...restProps } = props ;
110112 const theme = useTheme ( ) ;
111113
112114 // Build final props with theme
113115 const propsWithTheme : PropsWithTheme = { ...restProps , theme } ;
114- const mergedProps = mergeAttrsWithProps ( attrs , propsWithTheme ) ;
116+ const propsWithAttrs = mergeAttrsWithProps ( combinedAttrs , propsWithTheme ) ;
117+ const mergedProps = propsWithAttrs ;
115118
116119 // Compute and merge dynamic patches
117120 const dynamicPatch = mergeDynamicPatches (
@@ -132,9 +135,11 @@ function styledFunction<C extends ComponentType<any>, P = {}, AttrsP = {}>(
132135 ) ;
133136
134137 // Filter props and add styles
135- const forwardedProps = filterProps ( restProps , ref ) ;
138+ const forwardedProps = filterProps ( propsWithAttrs , ref ) ;
136139 forwardedProps . style = styles ;
137140
141+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
142+ const Component = ( asProp || ( propsWithAttrs . as as ComponentType < any > ) || BaseComponent ) as ComponentType < any > ;
138143 return < Component { ...forwardedProps } /> ;
139144 } ) ;
140145
@@ -158,7 +163,7 @@ function styledFunction<C extends ComponentType<any>, P = {}, AttrsP = {}>(
158163 ) : StyledComponent < C , P , AttrsP & NewAttrs > {
159164 return createStyledComponent ( {
160165 ...metadata ,
161- attrs : attrsArg as Record < string , unknown > ,
166+ attrs : attrsArg as AttrsValue ,
162167 } ) ;
163168 } ;
164169
@@ -174,7 +179,7 @@ function styledFunction<C extends ComponentType<any>, P = {}, AttrsP = {}>(
174179 compiledStyles : mergedCompiledStyles ,
175180 styleKeys : mergedStyleKeys ,
176181 getDynamicPatch : combinedGetDynamicPatch ,
177- attrs,
182+ attrs : combinedAttrs ,
178183 } ,
179184 BaseComponent
180185 ) ;
@@ -208,7 +213,7 @@ function styledFunction<C extends ComponentType<any>, P = {}, AttrsP = {}>(
208213 compiledStyles,
209214 styleKeys : compiledStyles ? [ 'base' ] : undefined ,
210215 getDynamicPatch : dynamicGetter as DynamicPatchFunction | undefined ,
211- attrs : baseAttrs as Record < string , unknown > ,
216+ attrs : baseAttrs as AttrsValue ,
212217 } ;
213218
214219 return createStyledComponent ( metadata ) ;
@@ -220,7 +225,11 @@ function styledFunction<C extends ComponentType<any>, P = {}, AttrsP = {}>(
220225 factory . __withStyles = function (
221226 metadata : StyleMetadata
222227 ) : StyledComponent < C , P > {
223- return createStyledComponent ( { ...metadata , attrs : baseAttrs as Record < string , unknown > } ) ;
228+ const mergedAttrs = combineAttrs (
229+ baseAttrs as AttrsValue | undefined ,
230+ metadata . attrs
231+ ) ;
232+ return createStyledComponent ( { ...metadata , attrs : mergedAttrs } ) ;
224233 } ;
225234
226235 /**
0 commit comments