Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ const ReactNativeStyleAttributes: {[string]: AnyAttributeType, ...} = {
/**
* Linear Gradient
*/
experimental_backgroundImage: {process: processBackgroundImage},

experimental_backgroundImage: ReactNativeFeatureFlags.enableNativeCSSParsing()
? true
: {process: processBackgroundImage},
/**
* View
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @fantom_flags enableNativeCSSParsing:*
* @format
*/

Expand Down Expand Up @@ -229,6 +230,56 @@ describe('<View>', () => {
});
});
});

describe('background-image', () => {
it('it parses CSS and object syntax', () => {
const root = Fantom.createRoot();

Fantom.runTask(() => {
root.render(
<>
<View
style={{
experimental_backgroundImage:
'radial-gradient(#e66465, #9198e5)',
}}
/>
<View
style={{
experimental_backgroundImage: [
{
type: 'radial-gradient',
shape: 'ellipse',
position: {top: '50%', right: '50%'},
size: 'farthest-corner',
colorStops: [{color: '#e66465'}, {color: '#9198e5'}],
},
],
}}
/>
</>,
);
});

const expectedProps = {
backgroundImage:
'[radial-gradient(ellipse farthest-corner at 50% 50% , rgba(230, 100, 101, 1), rgba(145, 152, 229, 1))]',
};

expect(root.getRenderedOutput().toJSON()).toEqual([
{
children: [],
props: expectedProps,
type: 'View',
},
{
children: [],
props: expectedProps,
type: 'View',
},
]);
});
});
});

describe('pointerEvents', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ const validAttributesForNonEventProps = {
backgroundColor: {process: require('../StyleSheet/processColor').default},
transform: true,
transformOrigin: true,
experimental_backgroundImage: {
process: require('../StyleSheet/processBackgroundImage').default,
},
experimental_backgroundImage: ReactNativeFeatureFlags.enableNativeCSSParsing()
? (true as const)
: {process: require('../StyleSheet/processBackgroundImage').default},
boxShadow: ReactNativeFeatureFlags.enableNativeCSSParsing()
? (true as const)
: {process: require('../StyleSheet/processBoxShadow').default},
Expand Down
4 changes: 4 additions & 0 deletions packages/react-native/React/Fabric/Utils/RCTGradientUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ @implementation RCTGradientUtils
+ (std::vector<ProcessedColorStop>)getFixedColorStops:(const std::vector<ColorStop> &)colorStops
gradientLineLength:(CGFloat)gradientLineLength
{
if (colorStops.empty()) {
return {};
}

std::vector<ProcessedColorStop> fixedColorStops(colorStops.size());
bool hasNullPositions = false;
auto maxPositionSoFar = resolveColorStopPosition(colorStops[0].position, gradientLineLength);
Expand Down
Loading
Loading