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:
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?
<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.
Yes React Native Support Gradient Use react-native-linear-gradient library.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With