-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from nebulabroadcast/new-proxy-player
New proxy player
- Loading branch information
Showing
29 changed files
with
1,441 additions
and
611 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { useEffect, forwardRef } from 'react' | ||
import styled from 'styled-components' | ||
|
||
const CanvasContainer = styled.div` | ||
position: relative; | ||
padding: 0; | ||
margin: 0; | ||
canvas { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
bottom: 0; | ||
right: 0; | ||
} | ||
` | ||
|
||
const Canvas = forwardRef(({ style, onDraw, ...props }, ref) => { | ||
useEffect(() => { | ||
if (!ref.current) return | ||
const canvas = ref.current | ||
|
||
const handleResize = () => { | ||
canvas.width = canvas.parentElement.clientWidth | ||
canvas.height = canvas.parentElement.clientHeight | ||
if (onDraw) { | ||
onDraw({ target: canvas }) | ||
} | ||
} | ||
|
||
handleResize() | ||
|
||
const parentElement = canvas.parentElement | ||
const resizeObserver = new ResizeObserver(handleResize) | ||
resizeObserver.observe(parentElement) | ||
|
||
return () => resizeObserver.unobserve(parentElement) | ||
}, [ref]) | ||
|
||
return ( | ||
<CanvasContainer style={style}> | ||
<canvas ref={ref} {...props} /> | ||
</CanvasContainer> | ||
) | ||
}) | ||
Canvas.displayName = 'Canvas' | ||
|
||
export default Canvas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.