[iOS] Opacity prop of Text applies double times.
See original GitHub issue🐛 Bug Report
On iOS, Text
component with style prop opacity
applies twice.
It seems the base class of RCTTextView
is RCTView
, and it causes the style prop opacity
applies double times to RCTTevtView
.
Roughly, delete this line in RCTBaseTextViewManager.m
fix this issue.
To Reproduce
//Please check the example code below.
const styles = StyleSheet.create({
rgba: {
fontSize: 20,
marginBottom: 10,
color: 'rgba(0, 0, 0, 0.25)'
},
opacity_50: {
fontSize: 20,
marginBottom: 10,
color: '#000',
opacity: 0.5
},
opacity_25: {
fontSize: 20,
marginBottom: 10,
color: '#000',
opacity: 0.25
},
hexa: {
fontSize: 20,
color: '#00000040' //rrggbbaa
}
}
Expected Behavior
It should be rendered as same as Android (right image above).
Code Example
https://snack.expo.io/Hy8RhMkYN
In iOS environment, compare the rendered colors of Text component with style { opacity: 0.5 }
and { color: 'rgba(0, 0, 0, 0.25)' }
- those are seems same.
Environment
React Native Environment Info:
System:
OS: macOS 10.14
CPU: (4) x64 Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
Memory: 225.85 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 11.5.0 - ~/.nvm/versions/node/v11.5.0/bin/node
Yarn: 1.10.1 - /usr/local/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v11.5.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
Android SDK:
API Levels: 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28
Build Tools: 23.0.1, 23.0.2, 23.0.3, 25.0.2, 25.0.3, 26.0.0, 26.0.1, 26.0.2, 26.0.3, 27.0.3, 28.0.2, 28.0.3
System Images: android-19 | Google APIs Intel x86 Atom, android-22 | Google APIs Intel x86 Atom, android-25 | Google Play Intel x86 Atom, android-26 | Google Play Intel x86 Atom
IDEs:
Android Studio: 3.2 AI-181.5540.7.32.5056338
Xcode: 10.1/10B61 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.3 => 16.8.3
react-native: 0.59.2 => 0.59.2
npmGlobalPackages:
react-native-cli: 2.0.1
react-native-create-library: 3.1.2
Issue Analytics
- State:
- Created 4 years ago
- Comments:16 (14 by maintainers)
Top Results From Across the Web
How could one achieve a see-through text effect in iOS?
In iOS i wrote code in swift language. I created a layer. Setup layer property as layer.opacity = 0.5. You can change this...
Read more >Change gradient color and opacity in Motion - Apple Support
Change the colors in a gradient · Double-click a color tag. · Click a color tag, click the disclosure triangle to the left...
Read more >text-emphasis - CSS: Cascading Style Sheets - MDN Web Docs
The text-emphasis CSS property applies emphasis marks to text (except ... text-emphasis: filled double-circle blue; ... Safari on iOS7.
Read more >Moving views with DragGesture and offset() - Hacking with Swift
The use of 2 there is intentional, because it allows the card to stay opaque while being dragged just a little. So, if...
Read more >TextStyle class - painting library - Flutter - Dart API docs
Applying the style in this way creates bold text. link. assignment ... withOpacity is used to create a derivative color with the desired...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@lukewalczak Well, you may thought that text with
OPACITY BG
is not rendered as translucent, right? The conbined style of that text component is -and I think it’s reasonable that applying opacity to
Text
component once, make both color of text and background as 50% of translucency. (Which is as shown in the image you attached.)On the other hand, the text components of both
RGBA BG
andHEXA BG
has 50% of translucency, so the colors of texts are mixed with each color of background.Oh, I see now, the issue is not about nested text components at all!
So, the solution should be pretty simple, we should just add
self.textAttributes.opacity = NAN;
similarly to what we did in #23872.Who wants to contribute? 😉