mirror of
https://github.com/captbaritone/webamp.git
synced 2026-01-23 10:15:31 +00:00
Add portal for Milkdrop Desktop mode
This commit is contained in:
parent
20c064cb84
commit
748cd70520
3 changed files with 56 additions and 13 deletions
8
css/milkdrop-window.css
Normal file
8
css/milkdrop-window.css
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
.webamp-desktop {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: -1;
|
||||
}
|
||||
22
js/components/MilkdropWindow/Desktop.js
Normal file
22
js/components/MilkdropWindow/Desktop.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import React from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
|
||||
export default class Desktop extends React.Component {
|
||||
componentWillUnmount() {
|
||||
document.body.removeChild(this._desktopNode);
|
||||
this._desktopNode = null;
|
||||
}
|
||||
|
||||
_getNode() {
|
||||
if (this._desktopNode == null) {
|
||||
this._desktopNode = document.createElement("div");
|
||||
this._desktopNode.classList.add("webamp-desktop");
|
||||
document.body.appendChild(this._desktopNode);
|
||||
}
|
||||
return this._desktopNode;
|
||||
}
|
||||
|
||||
render() {
|
||||
return ReactDOM.createPortal(this.props.children, this._getNode());
|
||||
}
|
||||
}
|
||||
|
|
@ -2,18 +2,26 @@ import React from "react";
|
|||
import screenfull from "screenfull";
|
||||
import ContextMenuWrapper from "../ContextMenuWrapper";
|
||||
import MilkdropContextMenu from "./MilkdropContextMenu";
|
||||
import Desktop from "./Desktop";
|
||||
|
||||
import Presets from "./Presets";
|
||||
import Milkdrop from "./Milkdrop";
|
||||
import Background from "./Background";
|
||||
|
||||
import "../../../css/milkdrop-window.css";
|
||||
|
||||
// This component is just responsible for loading dependencies.
|
||||
// This simplifies the inner <Milkdrop /> component, by allowing
|
||||
// it to alwasy assume that it has it's dependencies.
|
||||
export default class PresetsLoader extends React.Component {
|
||||
constructor() {
|
||||
super();
|
||||
this.state = { presets: null, butterchurn: null, isFullscreen: false };
|
||||
this.state = {
|
||||
presets: null,
|
||||
butterchurn: null,
|
||||
isFullscreen: false,
|
||||
desktop: false
|
||||
};
|
||||
this._handleFullscreenChange = this._handleFullscreenChange.bind(this);
|
||||
this._handleRequestFullsceen = this._handleRequestFullsceen.bind(this);
|
||||
}
|
||||
|
|
@ -58,9 +66,23 @@ export default class PresetsLoader extends React.Component {
|
|||
const { butterchurn, presets } = this.state;
|
||||
const loaded = butterchurn != null && presets != null;
|
||||
|
||||
const width = this.state.isFullscreen ? screen.width : this.props.width;
|
||||
let size = { width: this.props.width, height: this.props.height };
|
||||
if (this.state.isFullscreen) {
|
||||
size = { width: screen.width, height: screen.height };
|
||||
} else if (this.state.desktop) {
|
||||
size = { width: window.innerWidth, height: window.innerHeight };
|
||||
}
|
||||
|
||||
const height = this.state.isFullscreen ? screen.height : this.props.height;
|
||||
const milkdrop = loaded && (
|
||||
<Milkdrop
|
||||
{...this.props}
|
||||
width={size.width}
|
||||
height={size.height}
|
||||
isFullscreen={this.state.isFullscreen}
|
||||
presets={presets}
|
||||
butterchurn={butterchurn}
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
<ContextMenuWrapper
|
||||
|
|
@ -73,16 +95,7 @@ export default class PresetsLoader extends React.Component {
|
|||
)}
|
||||
>
|
||||
<Background innerRef={node => (this._wrapperNode = node)}>
|
||||
{loaded && (
|
||||
<Milkdrop
|
||||
{...this.props}
|
||||
width={width}
|
||||
height={height}
|
||||
isFullscreen={this.state.isFullscreen}
|
||||
presets={presets}
|
||||
butterchurn={butterchurn}
|
||||
/>
|
||||
)}
|
||||
{this.state.desktop ? <Desktop>{milkdrop}</Desktop> : milkdrop}
|
||||
</Background>
|
||||
</ContextMenuWrapper>
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue