-
Notifications
You must be signed in to change notification settings - Fork 25k
[Text] Ensure that the text background is transparent by default #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The way it is setup (at least in fb repo, not sure how open source is yet) is that we propagate the background color from the parent. In most of cases this is working as intended and gives the nice property that the layers do not need to be blended. This makes the gpu part faster at only a small cost. |
|
I will try to profile this later on a device to see the performance difference (or do you have numbers?). One thing is that UILabels are transparent but they are fast enough for UIKit apps so I don't know if the cost of blending is really a problem. The other thing is that I believe "opaque" on a UIView is a rendering hint, and iOS may optimize views with opaque background colors even if opaque = NO. |
|
Cc @sahrens who implemented it and @a2 @nicklockwood who may have insight in terms of performance |
|
I think it's more of an issue with text overlaid on complex hierarchies (and semi-transparent views overlaid on those, e.g. the groups photo viewer shadow while swiping to dismiss), and on worse devices like iphone 4/4s. Our groups app definitely shows tons of blending with this feature turned off. Even if it's not enough of a win to save dropped frames, there can still be meaningful benefit from saving battery by doing less work on the GPU, and it saves developers who fire up the blended layers mode from thinking they need to manually fix all the red (since most everything will automatically come up green out of the box). Finally, the Paper team mentioned that text renders more crisply into opaque buffers - I'm not sure if this is still true on iOS 8. -Spencer
|
|
That said, defaulting to transparent for the meantime seems ok. -Spencer
|
|
Hi Spencer, That's really good to know. I hadn't thought about the the opaque bit letting the renderer optimizer transparent overlays. The text crispness is interesting too. It looks like the system pre-renders the glyphs with subpixel anti-aliasing in the opaque case. I believe on the latest screens (thinking about the 6 Plus) the visual fidelity will always be high since individual pixels are actually finer than subpixels on older devices. Cool stuff.
From what I understand, React propagates background color down the view hierarchy, so if an ancestor view were to set an opaque background color, all descendant text views would inherit it. Since the Core Animation debugger was showing all green even with opaque=NO as long the text views had an opaque background color, I believe this diff wouldn't deoptimize nor lower the rendering quality of the groups app but I'd like to know for sure. |
For a very simple view I was observing that the text background was black and had to manually be set to transparent. This ensures that text nodes have a transparent background by default.
Test Plan: This example component no longer renders what looks like a black block, and instead displays legible text.
var Example = React.createClass({
render: function() {
return (
<View style={styles.container}>
<Text>hello</Text>
</View>
);
},
});
var styles = StyleSheet.create({
container: {
flex: 1,
},
};
|
This might be a helpful patch for new users who are trying out React Native, since when I first wrote some components they were rendered as black boxes (black text on a black background) without this diff. As far as I know this doesn't affect performance in cases where the text would have been displayed correctly (that is, not against a black background) and it's simple enough to get the no-blending optimization by setting a background color if blending ever becomes an issue. |
|
I'm happy to land this. |
9b61be2 to
41453a5
Compare
|
See #256. Closing this since GitHub didn't handle the private -> public transition well. |


For a very simple view I was observing that the text background was black and had to manually be set to transparent. This ensures that text nodes have a transparent background by default.
Test Plan: This example component no longer renders what looks like a black block, and instead displays legible text.