Skip to content

Commit 1cc12ce

Browse files
piaskowykfacebook-github-bot
authored andcommitted
Fix the serialization of the alpha channel in the rgba() color string format (#52087)
Summary: The alpha channel in the `rgba()` color string format should be a value between [0, 1] instead of [0, 255], as stated in the [React Native Documentation](https://reactnative.dev/docs/colors#red-green-blue-rgb). ## Changelog: [GENERAL] [FIXED] - Fix the serialization of the alpha channel in the `rgba()` color string format. Pull Request resolved: #52087 Test Plan: I didn't find any usage of that function in React Native, but it is part of the public API, and I just wanted to use it in Reanimated. Reviewed By: fabriziocucci Differential Revision: D76822560 Pulled By: javache fbshipit-source-id: 370d9729881c1eda794c1b9fe54d258242fde814
1 parent 28986a7 commit 1cc12ce

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

packages/react-native/Libraries/Components/__tests__/Button-itest.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ describe('<Button>', () => {
3131
.toJSX(),
3232
).toEqual(
3333
// Upper case on Android (also used by Fantom)
34-
<rn-view backgroundColor="rgba(33, 150, 243, 255)">
35-
<rn-paragraph foregroundColor="rgba(255, 255, 255, 255)">
34+
<rn-view backgroundColor="rgba(33, 150, 243, 1)">
35+
<rn-paragraph foregroundColor="rgba(255, 255, 255, 1)">
3636
HELLO
3737
</rn-paragraph>
3838
</rn-view>,
@@ -53,8 +53,8 @@ describe('<Button>', () => {
5353
.getRenderedOutput({props: ['foregroundColor', 'backgroundColor']})
5454
.toJSX(),
5555
).toEqual(
56-
<rn-view backgroundColor="rgba(0, 0, 255, 255)">
57-
<rn-paragraph foregroundColor="rgba(255, 255, 255, 255)">
56+
<rn-view backgroundColor="rgba(0, 0, 255, 1)">
57+
<rn-paragraph foregroundColor="rgba(255, 255, 255, 1)">
5858
HELLO
5959
</rn-paragraph>
6060
</rn-view>,
@@ -99,8 +99,8 @@ describe('<Button>', () => {
9999
.getRenderedOutput({props: ['foregroundColor', 'backgroundColor']})
100100
.toJSX(),
101101
).toEqual(
102-
<rn-view backgroundColor="rgba(223, 223, 223, 255)">
103-
<rn-paragraph foregroundColor="rgba(161, 161, 161, 255)">
102+
<rn-view backgroundColor="rgba(223, 223, 223, 1)">
103+
<rn-paragraph foregroundColor="rgba(161, 161, 161, 1)">
104104
HELLO
105105
</rn-paragraph>
106106
</rn-view>,
@@ -181,8 +181,8 @@ describe('<Button>', () => {
181181
.getRenderedOutput({props: ['foregroundColor', 'backgroundColor']})
182182
.toJSX(),
183183
).toEqual(
184-
<rn-view backgroundColor="rgba(33, 150, 243, 255)">
185-
<rn-paragraph foregroundColor="rgba(255, 255, 255, 255)">
184+
<rn-view backgroundColor="rgba(33, 150, 243, 1)">
185+
<rn-paragraph foregroundColor="rgba(255, 255, 255, 1)">
186186
HELLO
187187
</rn-paragraph>
188188
</rn-view>,
@@ -223,8 +223,8 @@ describe('<Button>', () => {
223223
.getRenderedOutput({props: ['foregroundColor', 'backgroundColor']})
224224
.toJSX(),
225225
).toEqual(
226-
<rn-view backgroundColor="rgba(223, 223, 223, 255)">
227-
<rn-paragraph foregroundColor="rgba(161, 161, 161, 255)">
226+
<rn-view backgroundColor="rgba(223, 223, 223, 1)">
227+
<rn-paragraph foregroundColor="rgba(161, 161, 161, 1)">
228228
HELLO
229229
</rn-paragraph>
230230
</rn-view>,

packages/react-native/ReactCommon/react/renderer/core/graphicsConversions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ inline std::string toString(const SharedColor& value) {
5050
std::snprintf(
5151
buffer.data(),
5252
buffer.size(),
53-
"rgba(%.0f, %.0f, %.0f, %.0f)",
53+
"rgba(%.0f, %.0f, %.0f, %g)",
5454
components.red * 255.f,
5555
components.green * 255.f,
5656
components.blue * 255.f,
57-
components.alpha * 255.f);
57+
components.alpha);
5858
return buffer.data();
5959
}
6060

packages/react-native/src/private/renderer/mounting/__tests__/Mounting-itest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ describe('ViewFlattening', () => {
380380
<rn-view
381381
width="100.000000"
382382
height="100.000000"
383-
backgroundColor="rgba(255, 255, 255, 127)"
383+
backgroundColor="rgba(255, 255, 255, 0.498039)"
384384
/>,
385385
);
386386
});

private/cxx-public-api/ReactNativeCPP.api

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28680,11 +28680,11 @@ inline std::string toString(const SharedColor& value) {
2868028680
std::snprintf(
2868128681
buffer.data(),
2868228682
buffer.size(),
28683-
"rgba(%.0f, %.0f, %.0f, %.0f)",
28683+
"rgba(%.0f, %.0f, %.0f, %g)",
2868428684
components.red * 255.f,
2868528685
components.green * 255.f,
2868628686
components.blue * 255.f,
28687-
components.alpha * 255.f);
28687+
components.alpha);
2868828688
return buffer.data();
2868928689
}
2869028690
inline void fromRawValue(

private/react-native-fantom/src/__tests__/Fantom-itest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,14 +535,14 @@ describe('Fantom', () => {
535535
{
536536
children: 'JSX is ',
537537
props: {
538-
foregroundColor: 'rgba(255, 0, 0, 255)',
538+
foregroundColor: 'rgba(255, 0, 0, 1)',
539539
},
540540
type: 'Text',
541541
},
542542
{
543543
children: 'easy!',
544544
props: {
545-
foregroundColor: 'rgba(0, 0, 255, 255)',
545+
foregroundColor: 'rgba(0, 0, 255, 1)',
546546
},
547547
type: 'Text',
548548
},

0 commit comments

Comments
 (0)