Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Linear Gradient: Colors washed out

I'm using the react-native-linear-gradient package to form a linear gradient. I've picked the exact same colors with color picker in XD design to form the same gradient in my app. Here is my code:

<LinearGradient start={{x:0,y:0}} end={{x:1,y:1}} style={StyleSheet.absoluteFill} colors={['#D300B5', '#FF5400']} >...

These hex values are the same values with the design, yet, here is the result compared with the design:

enter image description here

The colors are significantly washed out. I've checked the opacities to make sure everything is at 100%, there aren't anything over the gradient, the gradient view isn't extending beyond the screen, both XD, my Mac, and the iPhone X use the Display P3 color space.

Why are the colors washed out?

like image 410
Can Poyrazoğlu Avatar asked Oct 04 '19 08:10

Can Poyrazoğlu


People also ask

How do you set a linear gradient color in react-native?

<LinearGradient colors={['red', 'yellow', 'green' ]} style={styles. linearGradient} start={{ x: 0, y: 0.5 }} end={{ x: 1, y: 0.5 }} locations={[0, 0.7, 0.9]} > <Text>H. Location Gradient</Text> </LinearGradient> <LinearGradient colors={['red', 'yellow', 'green' ]} style={styles.

Does react-native support linear gradient?

Yes React Native Support Gradient Use react-native-linear-gradient library.

How do you fade the edge of a view in react-native?

For the fading gradient itself, you can either use something like react-native-linear-gradient (which is also built into Expo) or a semi-transparent image (black pixels will show content through, transparent pixels will block masked content).


1 Answers

Note: This solution is iOS-only and applies to all colors used in app.

After a long time of not being able to find out anything, I've created a patch of React Native itself, as the problem originates from how React Native creates colors itself in native code in RCTConvert.m:

return [UIColor colorWithRed:... green:... blue:...]

Switching both occurances (there are two as of writing) of colorWithRed to colorWithDisplayP3Red and rebuilding (don't forget as we're changing native code, hot reloading won't work) the app worked: Colors are now rendered in P3 color space. Please note that this approach changes all colors that you create/use in app, so every color will basically look more crisp.

like image 158
Can Poyrazoğlu Avatar answered Sep 28 '22 15:09

Can Poyrazoğlu