Skip to content

Commit e6567ff

Browse files
BlackCat1397necolas
andcommitted
Fix opacity string value polyfill
This transform should occur after the unparsed value parsing. Close #371 Co-authored-by: Nicolas Gallagher <necolas@meta.com>
1 parent bd0f800 commit e6567ff

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

packages/react-strict-dom/src/native/css/processStyle.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,18 @@ export function processStyle(
110110
result[propName] = 0;
111111
continue;
112112
}
113-
// Polyfill support for string opacity on Android
114-
if (propName === 'opacity') {
115-
result[propName] = parseFloat(styleValue);
116-
continue;
117-
}
118113
// Polyfill support for custom property references (do this first)
119-
else if (stringContainsVariables(styleValue)) {
114+
if (stringContainsVariables(styleValue)) {
120115
result[propName] = CSSUnparsedValue.parse(propName, styleValue);
121116
continue;
122-
} else if (
117+
}
118+
// Polyfill support for backgroundImage using experimental API
119+
else if (propName === 'backgroundImage') {
120+
result.experimental_backgroundImage = styleValue;
121+
continue;
122+
}
123+
// Warn for unsupported caretColor values
124+
else if (
123125
propName === 'caretColor' &&
124126
(typeof styleValue === 'undefined' || styleValue === 'auto')
125127
) {
@@ -129,15 +131,17 @@ export function processStyle(
129131
);
130132
}
131133
continue;
132-
} else if (propName === 'backgroundImage') {
133-
result.experimental_backgroundImage = styleValue;
134-
continue;
135134
}
136135
// Workaround unsupported objectFit values
137136
else if (propName === 'objectFit' && styleValue === 'none') {
138137
result[propName] = 'scale-down';
139138
continue;
140139
}
140+
// Polyfill support for string opacity on Android
141+
else if (propName === 'opacity') {
142+
result[propName] = parseFloat(styleValue);
143+
continue;
144+
}
141145
// Polyfill placeContent
142146
else if (propName === 'placeContent') {
143147
// None of these values are supported in RN for both properties.

packages/react-strict-dom/tests/css-test.native.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1274,11 +1274,17 @@ describe('properties: custom property', () => {
12741274

12751275
test('parses a basic var correctly', () => {
12761276
const options = {
1277-
customProperties: { test: 'red' }
1277+
customProperties: {
1278+
opacity: '0.25',
1279+
test: 'red'
1280+
}
12781281
};
12791282
expect(
12801283
resolveCustomPropertyValue(options, ['color', 'var(--test)'])
12811284
).toEqual('red');
1285+
expect(
1286+
resolveCustomPropertyValue(options, ['opacity', 'var(--opacity)'])
1287+
).toEqual(0.25);
12821288
});
12831289

12841290
test('parses a var with a default value', () => {

0 commit comments

Comments
 (0)