Skip to content

Commit 0146a0b

Browse files
author
Michael Johnston
committed
Better rendering of images with transparency.
Hide opaque background layers for images once the image has loaded. Fixes Flipboard#16.
1 parent aa1ebde commit 0146a0b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/Image.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,21 @@ var Image = React.createClass({
7676
render: function () {
7777
var rawImage;
7878
var imageStyle = assign({}, this.props.style);
79+
var style = assign({}, this.props.style);
80+
var backgroundStyle = assign({}, this.props.style);
7981
var useBackingStore = this.state.loaded ? this.props.useBackingStore : false;
8082

8183
// Hide the image until loaded.
8284
imageStyle.alpha = this.state.imageAlpha;
8385

86+
// Hide opaque background if image loaded so that images with transparent
87+
// do not render on top of solid color.
88+
style.backgroundColor = imageStyle.backgroundColor = null;
89+
backgroundStyle.alpha = clamp(1 - this.state.imageAlpha, 0, 1);
90+
8491
return (
85-
React.createElement(Group, {ref: 'main', style: this.props.style},
92+
React.createElement(Group, {ref: 'main', style: style},
93+
React.createElement(Layer, {ref: 'background', style: backgroundStyle}),
8694
React.createElement(RawImage, {ref: 'image', src: this.props.src, style: imageStyle, useBackingStore: useBackingStore})
8795
)
8896
);

0 commit comments

Comments
 (0)