Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't fullscreen the video when double-clicking components #144

Merged
merged 5 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"scripts": {
"prepare": "husky install",
"dev": "NODE_ENV=development webpack serve --config src/webpack.config.ts",
"dev": "cross-env NODE_ENV=development webpack serve --config src/webpack.config.ts",
"build": "webpack --config src/webpack.config.ts",
"lint:eslint": "eslint src --ext .ts,.tsx",
"lint:prettier": "prettier --check \"src/**/*.{js,jsx,ts,tsx,json,scss}\"",
Expand All @@ -38,6 +38,7 @@
"@typescript-eslint/eslint-plugin": "^6.4.0",
"@typescript-eslint/parser": "^6.4.0",
"copy-webpack-plugin": "^11.0.0",
"cross-env": "^7.0.3",
"css-loader": "^6.8.1",
"dotenv-webpack": "^8.0.1",
"eslint": "^8.47.0",
Expand Down
29 changes: 29 additions & 0 deletions src/pages/overlay/components/overlay/Overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,35 @@ export default function Overlay() {
return () => document.body.removeEventListener("click", bodyClick, true);
}, [bodyClick]);

// Handle body double clicks, ignoring them inside of overlay elements
const bodyDblClick = useCallback((e: MouseEvent) => {
// Get all the elements under the mouse
MattIPv4 marked this conversation as resolved.
Show resolved Hide resolved
const elements = document.elementsFromPoint(e.clientX, e.clientY);

// For each element, if it has a background then we want to ignore the click
// If we reach the body, then break out of the loop and propagate the event
for (const element of elements) {
if (element === document.body) break;

const style = getComputedStyle(element);
if (
style.backgroundImage !== "none" ||
style.backgroundColor !== "rgba(0, 0, 0, 0)"
) {
e.stopPropagation();
return;
}
}
}, []);

// If the user double clicks anywhere in the overlay itself, stop propagating the event
// This stops double clicks from toggling fullscreen video which is the default behavior
useEffect(() => {
document.body.addEventListener("dblclick", bodyDblClick, true);
return () =>
document.body.removeEventListener("dblclick", bodyDblClick, true);
}, [bodyDblClick]);

// Generate the context for the overlay options
const context = useMemo<OverlayOptionProps["context"]>(
() => ({
Expand Down