[Fix] revert fileRenderFloating vs Mobile change ()

* Bump react-draggable

Old version was giving out console errors for outdated react functions

* Refactor fileRenderFloating

* Merge fileRenderMobile into fileRenderFloating

* Fixes from review

* Attempt fix failed to view live
This commit is contained in:
saltrafael 2022-02-23 18:13:22 -03:00 committed by GitHub
parent d6cd3caa77
commit 17e3fcc27c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 354 additions and 530 deletions
ui/component/fileRenderFloating

View file

@ -0,0 +1,54 @@
// @flow
import { FLOATING_PLAYER_CLASS } from './view';
function getRootEl() {
return document && document.documentElement;
}
export function getScreenWidth() {
const mainEl = getRootEl();
return mainEl ? mainEl.clientWidth : window.innerWidth;
}
export function getScreenHeight() {
const mainEl = getRootEl();
return mainEl ? mainEl.clientHeight : window.innerHeight;
}
export function getFloatingPlayerRect() {
const elem = document.querySelector(`.${FLOATING_PLAYER_CLASS}`);
return elem ? elem.getBoundingClientRect() : null;
}
export function clampFloatingPlayerToScreen(x: number, y: number) {
const playerRect = getFloatingPlayerRect();
let newX = x;
let newY = y;
if (playerRect) {
const screenW = getScreenWidth();
const screenH = getScreenHeight();
if (x + playerRect.width > screenW) {
newX = screenW - playerRect.width;
} else if (x < 0) {
newX = 0;
}
if (y + playerRect.height > screenH) {
newY = screenH - playerRect.height;
} else if (y < 0) {
newY = 0;
}
}
return { x: newX, y: newY };
}
export function calculateRelativePos(x: number, y: number) {
return {
x: x / getScreenWidth(),
y: y / getScreenHeight(),
};
}