-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCameraView.js
More file actions
47 lines (42 loc) · 1.22 KB
/
CameraView.js
File metadata and controls
47 lines (42 loc) · 1.22 KB
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
import React, { useCallback, useMemo, useRef } from 'react';
import {
findNodeHandle,
requireNativeComponent,
UIManager,
ViewPropTypes,
} from 'react-native';
const RCTCameraView = requireNativeComponent('RTMPCamera');
const CameraView = React.forwardRef((props, ref) => {
const camera = useRef();
const refObject = useMemo(() => {
return {
start: (...args) => {
UIManager.dispatchViewManagerCommand(
findNodeHandle(camera.current),
UIManager.getViewManagerConfig('RTMPCamera').Commands.start,
args,
);
},
stop: (...args) => {
UIManager.dispatchViewManagerCommand(
findNodeHandle(camera.current),
UIManager.getViewManagerConfig('RTMPCamera').Commands.stop,
args,
);
},
};
}, []);
ref.current = refObject;
const { onChangeState, ...viewProps } = props;
const handleChangeState = useCallback(
({ nativeEvent }) => {
onChangeState?.(nativeEvent?.code, nativeEvent?.msg);
},
[onChangeState],
);
return (
<RCTCameraView ref={camera} {...props} onChangeState={handleChangeState} />
);
});
CameraView.propTypes = ViewPropTypes;
export default CameraView;