Ensure screenshot does not block webamp

This commit is contained in:
Jordan Eldredge 2018-12-01 13:05:20 -08:00
parent 97d5ecbf4f
commit b637e32c5d
3 changed files with 20 additions and 18 deletions

View file

@ -79,11 +79,10 @@ body.overlay-open .overlay {
color: white;
}
#focused-skin .focused-preview {
-webkit-transition: opacity 400ms ease-in-out;
-moz-transition: opacity 400ms ease-in-out;
-ms-transition: opacity 400ms ease-in-out;
#focused-skin {
visibility: visible;
}
#focused-skin .focused-preview.loaded {
#focused-skin.loaded {
opacity: 0;
visibility: hidden;
}

View file

@ -1,6 +1,7 @@
import React from "react";
import ReactDOM from "react-dom";
import { connect } from "react-redux";
import classnames from "classnames";
import WebampComponent from "./WebampComponent";
import * as Utils from "./utils";
import * as Selectors from "./redux/selectors";
@ -11,9 +12,10 @@ class FocusedSkin extends React.Component {
super(props);
// TODO: Handle the case were we come from a permalink
if (this.props.initialPosition == null) {
this.state = this._getCenteredState();
this.state = Object.assign({ loaded: false }, this._getCenteredState());
} else {
this.state = {
loaded: false,
top: this.props.initialPosition.top,
left: this.props.initialPosition.left,
width: this.props.initialWidth,
@ -49,9 +51,11 @@ class FocusedSkin extends React.Component {
};
}
render() {
const { loaded } = this.state;
return ReactDOM.createPortal(
<div
id="focused-skin"
className={classnames({ loaded })}
style={{
position: "fixed",
height: this.state.height,
@ -60,13 +64,14 @@ class FocusedSkin extends React.Component {
this.state.left
)}px) translateY(${Math.round(this.state.top)}px)`,
transition:
"transform 400ms ease-out, height 400ms ease-out, width 400ms ease-out"
"all 400ms ease-out, height 400ms ease-out, width 400ms ease-out"
}}
>
<WebampComponent
key={this.props.hash} // Don't reuse instances
skinUrl={Utils.skinUrlFromHash(this.props.hash)}
screenshotUrl={Utils.screenshotUrlFromHash(this.props.hash)}
loaded={() => this.setState({ loaded: true })}
/>
<div className="metadata">
<div className="file-name">

View file

@ -1,13 +1,10 @@
import React from "react";
import ReactDOM from "react-dom";
import { connect } from "react-redux";
import classnames from "classnames";
import * as ActionCreators from "./redux/actionCreators";
class WebampComponent extends React.Component {
constructor(props) {
super(props);
this.state = { loading: true };
}
componentDidMount() {
this._loadWebamp();
@ -15,6 +12,9 @@ class WebampComponent extends React.Component {
componentWillUnmount() {
this._unmounted = true;
if (this._renderTimeout) {
clearTimeout(this._renderTimeout);
}
if (this._webamp) {
// TODO: Repace this with this._webamp.destroy() once we upgrade.
const close = document.querySelector("#webamp #close");
@ -50,17 +50,15 @@ class WebampComponent extends React.Component {
// TODO: Technically we should unsubscribe this on unmount
this._webamp.onClose(this.props.closeModal);
setTimeout(async () => {
this._renderTimeout = setTimeout(async () => {
await this._webamp.renderWhenReady(this._ref);
this.setState({ loading: false });
}, 400);
if (this._unmounted === true) {
return;
}
if (!this._unmounted) {
this.props.loaded();
}
}, 500);
}
render() {
const { loading } = this.state;
return (
<div style={{ width: "100%", height: "100%" }}>
<div
@ -68,7 +66,7 @@ class WebampComponent extends React.Component {
style={{ position: "absolute", width: "100%", height: "100%" }}
/>
<img
className={classnames("focused-preview", { loaded: !loading })}
className={"focused-preview"}
style={{
width: "100%",
height: "100%",