]> cat aescling's git repositories - mastodon.git/commitdiff
Fix loading of avatars before drawing them to canvas
authorEugen Rochko <eugen@zeonfederated.com>
Wed, 25 Jan 2017 16:23:17 +0000 (17:23 +0100)
committerEugen Rochko <eugen@zeonfederated.com>
Wed, 25 Jan 2017 16:23:17 +0000 (17:23 +0100)
app/assets/javascripts/components/components/avatar.jsx

index 30467da4d4d8ed6823d79aea34f8b13985085055..b8420014bd641665350ed06ca6a2bc8fde28f5ae 100644 (file)
@@ -24,7 +24,7 @@ const Avatar = React.createClass({
     this.setState({ hovering: false });
   },
 
-  componentDidMount () {
+  handleLoad () {
     this.canvas.getContext('2d').drawImage(this.image, 0, 0, this.props.size, this.props.size);
   },
 
@@ -41,7 +41,7 @@ const Avatar = React.createClass({
 
     return (
       <div onMouseEnter={this.handleMouseEnter} onMouseLeave={this.handleMouseLeave} style={{ ...this.props.style, width: `${this.props.size}px`, height: `${this.props.size}px`, position: 'relative' }}>
-        <img ref={this.setImageRef} src={this.props.src} width={this.props.size} height={this.props.size} alt='' style={{ position: 'absolute', top: '0', left: '0', display: hovering ? 'block' : 'none', borderRadius: '4px' }} />
+        <img ref={this.setImageRef} onLoad={this.handleLoad} src={this.props.src} width={this.props.size} height={this.props.size} alt='' style={{ position: 'absolute', top: '0', left: '0', visibility: hovering ? 'visible' : 'hidden', borderRadius: '4px' }} />
         <canvas ref={this.setCanvasRef} width={this.props.size} height={this.props.size} style={{ borderRadius: '4px' }} />
       </div>
     );