Skip to content

Commit d15383e

Browse files
NickGerlemanmeta-codesync[bot]
authored andcommitted
Export ViewConfig processor attributes from ReactNativeStyleAttributes (facebook#55674)
Summary: Pull Request resolved: facebook#55674 Centralize gated ViewConfig processor attributes into exported constants in `ReactNativeStyleAttributes.js`. This is a pure refactor — no new behavior. When `enableNativeCSSParsing()` is on, the JS processor is bypassed and the raw value is sent directly to native. Exported attributes: `colorAttribute`, `filterAttribute`, `boxShadowAttribute`, `backgroundImageAttribute`, `backgroundSizeAttribute`, `backgroundPositionAttribute`, `backgroundRepeatAttribute`. All ViewConfig files now import these constants instead of inlining `{process: require(...)}` or feature flag checks. Changelog: [Internal] Differential Revision: D94052734
1 parent aabdf55 commit d15383e

3 files changed

Lines changed: 57 additions & 36 deletions

File tree

packages/react-native/Libraries/Components/View/ReactNativeStyleAttributes.js

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,39 @@ import processTransform from '../../StyleSheet/processTransform';
2424
import processTransformOrigin from '../../StyleSheet/processTransformOrigin';
2525
import sizesDiffer from '../../Utilities/differ/sizesDiffer';
2626

27+
const nativeCSSParsing = ReactNativeFeatureFlags.enableNativeCSSParsing();
28+
2729
const colorAttributes = {process: processColor};
2830

31+
/**
32+
* Gated style attribute types. When native CSS parsing is enabled, the JS
33+
* processor is bypassed and the raw value is sent directly to native.
34+
* These are exported so that other ViewConfigs can reuse them.
35+
*/
36+
export const filterAttribute: AnyAttributeType = nativeCSSParsing
37+
? true
38+
: {process: processFilter};
39+
40+
export const boxShadowAttribute: AnyAttributeType = nativeCSSParsing
41+
? true
42+
: {process: processBoxShadow};
43+
44+
export const backgroundImageAttribute: AnyAttributeType = nativeCSSParsing
45+
? true
46+
: {process: processBackgroundImage};
47+
48+
export const backgroundSizeAttribute: AnyAttributeType = nativeCSSParsing
49+
? true
50+
: {process: processBackgroundSize};
51+
52+
export const backgroundPositionAttribute: AnyAttributeType = nativeCSSParsing
53+
? true
54+
: {process: processBackgroundPosition};
55+
56+
export const backgroundRepeatAttribute: AnyAttributeType = nativeCSSParsing
57+
? true
58+
: {process: processBackgroundRepeat};
59+
2960
const ReactNativeStyleAttributes: {[string]: AnyAttributeType, ...} = {
3061
/**
3162
* Layout
@@ -125,9 +156,7 @@ const ReactNativeStyleAttributes: {[string]: AnyAttributeType, ...} = {
125156
/**
126157
* Filter
127158
*/
128-
filter: ReactNativeFeatureFlags.enableNativeCSSParsing()
129-
? true
130-
: {process: processFilter},
159+
filter: filterAttribute,
131160

132161
/**
133162
* MixBlendMode
@@ -142,29 +171,27 @@ const ReactNativeStyleAttributes: {[string]: AnyAttributeType, ...} = {
142171
/*
143172
* BoxShadow
144173
*/
145-
boxShadow: ReactNativeFeatureFlags.enableNativeCSSParsing()
146-
? true
147-
: {process: processBoxShadow},
174+
boxShadow: boxShadowAttribute,
148175

149176
/**
150177
* BackgroundImage
151178
*/
152-
experimental_backgroundImage: {process: processBackgroundImage},
179+
experimental_backgroundImage: backgroundImageAttribute,
153180

154181
/**
155182
* BackgroundSize
156183
*/
157-
experimental_backgroundSize: {process: processBackgroundSize},
184+
experimental_backgroundSize: backgroundSizeAttribute,
158185

159186
/**
160187
* BackgroundPosition
161188
*/
162-
experimental_backgroundPosition: {process: processBackgroundPosition},
189+
experimental_backgroundPosition: backgroundPositionAttribute,
163190

164191
/**
165192
* BackgroundRepeat
166193
*/
167-
experimental_backgroundRepeat: {process: processBackgroundRepeat},
194+
experimental_backgroundRepeat: backgroundRepeatAttribute,
168195

169196
/**
170197
* View

packages/react-native/Libraries/NativeComponent/BaseViewConfig.android.js

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,15 @@
1010

1111
import type {PartialViewConfigWithoutName} from './PlatformBaseViewConfig';
1212

13-
import * as ReactNativeFeatureFlags from '../../src/private/featureflags/ReactNativeFeatureFlags';
1413
import ReactNativeStyleAttributes from '../Components/View/ReactNativeStyleAttributes';
14+
import {
15+
backgroundImageAttribute,
16+
backgroundPositionAttribute,
17+
backgroundRepeatAttribute,
18+
backgroundSizeAttribute,
19+
boxShadowAttribute,
20+
filterAttribute,
21+
} from '../Components/View/ReactNativeStyleAttributes';
1522
import {DynamicallyInjectedByGestureHandler} from './ViewConfigIgnore';
1623

1724
const bubblingEventTypes = {
@@ -191,24 +198,12 @@ const validAttributesForNonEventProps = {
191198
backgroundColor: {process: require('../StyleSheet/processColor').default},
192199
transform: true,
193200
transformOrigin: true,
194-
experimental_backgroundImage: ReactNativeFeatureFlags.enableNativeCSSParsing()
195-
? (true as const)
196-
: {process: require('../StyleSheet/processBackgroundImage').default},
197-
experimental_backgroundSize: {
198-
process: require('../StyleSheet/processBackgroundSize').default,
199-
},
200-
experimental_backgroundPosition: {
201-
process: require('../StyleSheet/processBackgroundPosition').default,
202-
},
203-
experimental_backgroundRepeat: {
204-
process: require('../StyleSheet/processBackgroundRepeat').default,
205-
},
206-
boxShadow: ReactNativeFeatureFlags.enableNativeCSSParsing()
207-
? (true as const)
208-
: {process: require('../StyleSheet/processBoxShadow').default},
209-
filter: ReactNativeFeatureFlags.enableNativeCSSParsing()
210-
? (true as const)
211-
: {process: require('../StyleSheet/processFilter').default},
201+
experimental_backgroundImage: backgroundImageAttribute,
202+
experimental_backgroundSize: backgroundSizeAttribute,
203+
experimental_backgroundPosition: backgroundPositionAttribute,
204+
experimental_backgroundRepeat: backgroundRepeatAttribute,
205+
boxShadow: boxShadowAttribute,
206+
filter: filterAttribute,
212207
mixBlendMode: true,
213208
isolation: true,
214209
opacity: true,

packages/react-native/Libraries/NativeComponent/BaseViewConfig.ios.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010

1111
import type {PartialViewConfigWithoutName} from './PlatformBaseViewConfig';
1212

13-
import * as ReactNativeFeatureFlags from '../../src/private/featureflags/ReactNativeFeatureFlags';
1413
import ReactNativeStyleAttributes from '../Components/View/ReactNativeStyleAttributes';
14+
import {
15+
boxShadowAttribute,
16+
filterAttribute,
17+
} from '../Components/View/ReactNativeStyleAttributes';
1518
import {
1619
ConditionallyIgnoredEventHandlers,
1720
DynamicallyInjectedByGestureHandler,
@@ -228,12 +231,8 @@ const validAttributesForNonEventProps = {
228231
hitSlop: {diff: require('../Utilities/differ/insetsDiffer').default},
229232
collapsable: true,
230233
collapsableChildren: true,
231-
filter: ReactNativeFeatureFlags.enableNativeCSSParsing()
232-
? (true as const)
233-
: {process: require('../StyleSheet/processFilter').default},
234-
boxShadow: ReactNativeFeatureFlags.enableNativeCSSParsing()
235-
? (true as const)
236-
: {process: require('../StyleSheet/processBoxShadow').default},
234+
filter: filterAttribute,
235+
boxShadow: boxShadowAttribute,
237236
mixBlendMode: true,
238237
isolation: true,
239238

0 commit comments

Comments
 (0)