-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Streaming video overlay for better mobile support
- Loading branch information
1 parent
bcfae2c
commit 02a2668
Showing
37 changed files
with
749 additions
and
95 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,107 @@ | ||
import Input from '@material-ui/core/Input'; | ||
import Tooltip from '@material-ui/core/Tooltip'; | ||
import React, { MutableRefObject, useCallback, useEffect, useRef, useState } from 'react'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
const useStyles = makeStyles({ | ||
input: { | ||
height: '100%', | ||
display: 'flex', | ||
flexDirection: 'column', | ||
justifyContent: 'center', | ||
fontSize: 20, | ||
marginLeft: 10, | ||
width: 100, | ||
color: '#fff', | ||
pointerEvents: 'auto', | ||
}, | ||
}); | ||
|
||
interface Props { | ||
inputRef: MutableRefObject<HTMLInputElement | undefined>; | ||
offset: number; | ||
onOffset: (offset: number) => void; | ||
disableKeyEvents?: boolean; | ||
} | ||
|
||
export default function SubtitleOffsetInput({ inputRef, offset, onOffset, disableKeyEvents }: Props) { | ||
const { t } = useTranslation(); | ||
const classes = useStyles(); | ||
const [offsetInputWidth, setOffsetInputWidth] = useState<number>(5); | ||
const handleNumberInputClicked = useCallback((e: React.MouseEvent<HTMLInputElement>) => { | ||
const inputElement = e.target as HTMLInputElement; | ||
inputElement.setSelectionRange(0, inputElement.value?.length || 0); | ||
}, []); | ||
|
||
const updateOffset = useCallback( | ||
(offset: number) => { | ||
if (!inputRef.current) { | ||
return; | ||
} | ||
|
||
if (offset === 0) { | ||
inputRef.current.value = ''; | ||
setOffsetInputWidth(5); | ||
} else { | ||
const offsetSeconds = offset / 1000; | ||
const value = offsetSeconds >= 0 ? '+' + offsetSeconds.toFixed(2) : String(offsetSeconds.toFixed(2)); | ||
inputRef.current.value = value; | ||
setOffsetInputWidth(value.length); | ||
} | ||
|
||
inputRef.current.blur(); | ||
}, | ||
[inputRef] | ||
); | ||
useEffect(() => { | ||
updateOffset(offset); | ||
}, [offset, updateOffset]); | ||
|
||
useEffect(() => { | ||
if (disableKeyEvents) { | ||
return; | ||
} | ||
|
||
function handleKey(event: KeyboardEvent) { | ||
if (event.key === 'Enter') { | ||
if (inputRef.current !== null && inputRef.current === document.activeElement) { | ||
const newOffset = Number(inputRef.current.value); | ||
|
||
if (newOffset === offset) { | ||
updateOffset(offset); | ||
return; | ||
} | ||
|
||
if (Number.isNaN(newOffset)) { | ||
return; | ||
} | ||
|
||
onOffset(newOffset * 1000); | ||
} | ||
} | ||
} | ||
|
||
window.addEventListener('keydown', handleKey); | ||
|
||
return () => { | ||
window.removeEventListener('keydown', handleKey); | ||
}; | ||
}, [updateOffset, onOffset, disableKeyEvents, inputRef, offset]); | ||
|
||
return ( | ||
<Tooltip title={t('controls.subtitleOffset')!}> | ||
<Input | ||
style={{ | ||
width: `${offsetInputWidth}ch`, | ||
}} | ||
inputRef={inputRef} | ||
disableUnderline={true} | ||
className={classes.input} | ||
placeholder={'±' + Number(0).toFixed(2)} | ||
onClick={handleNumberInputClicked} | ||
onChange={(e) => setOffsetInputWidth(Math.max(5, e.target.value.length))} | ||
/> | ||
</Tooltip> | ||
); | ||
} |
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
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
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.