-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathvideo-view.tsx
55 lines (47 loc) · 1.34 KB
/
video-view.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import * as React from 'react'
import { View, findNodeHandle } from 'react-native'
import Color from 'color'
import { RNZoomUs, RNZoomUsVideoView, NativeVideoProps } from './native'
export interface Props {
style?: NativeVideoProps["style"]
layout: NativeVideoProps["layout"]
}
const ZoomUsVideoView: React.FC<Props> = (props) => {
const { layout = [], ...otherProps } = props
const nativeLayout = layout.map(unit => {
return Object.assign({}, unit, {
x: Math.ceil(unit.x * 100),
y: Math.ceil(unit.y * 100),
width: Math.ceil(unit.width * 100),
height: Math.ceil(unit.height * 100),
background: Color(unit.background || '#000000').rgbNumber(),
})
})
const nativeEl = React.useRef(null)
React.useEffect(() => {
(async function register() {
if (nativeEl.current) {
await RNZoomUs.addVideoView(findNodeHandle(nativeEl.current))
}
})()
return () => {
(async function unregister() {
if (nativeEl.current) {
await RNZoomUs.removeVideoView(findNodeHandle(nativeEl.current))
}
})()
}
}, [nativeEl.current])
if (RNZoomUsVideoView) {
return (
<RNZoomUsVideoView
ref={nativeEl}
layout={nativeLayout}
{...otherProps}
/>
)
} else {
return (<View {...otherProps} />)
}
}
export default ZoomUsVideoView