@@ -4,9 +4,9 @@ import PropTypes from 'prop-types';
4
4
5
5
import { Text , useWindowDimensions , View } from 'react-native' ;
6
6
import { utils } from '@monkvision/toolkit' ;
7
+ import Webcam from 'react-webcam' ;
7
8
8
9
import { findDevices , findBestCandidate , setVideoSource } from './utils' ;
9
- import getOS from '../../utils/getOS' ;
10
10
import styles from './styles' ;
11
11
12
12
const { getSize } = utils . styles ;
@@ -20,7 +20,6 @@ const Video = React.forwardRef(
20
20
21
21
const Camera = ( { children, containerStyle, onCameraReady, title } , ref ) => {
22
22
const videoRef = useRef ( ) ;
23
- const expoCameraRef = useRef ( ) ;
24
23
const windowDimensions = useWindowDimensions ( ) ;
25
24
26
25
const [ camera , setCamera ] = useState ( {
@@ -29,6 +28,7 @@ const Camera = ({ children, containerStyle, onCameraReady, title }, ref) => {
29
28
height : 0 ,
30
29
ratio : '4:3' ,
31
30
pictureSize : '' ,
31
+ constraints : { } ,
32
32
} ) ;
33
33
34
34
const [ loading , setLoading ] = useState ( false ) ;
@@ -41,9 +41,15 @@ const Camera = ({ children, containerStyle, onCameraReady, title }, ref) => {
41
41
useImperativeHandle ( ref , ( ) => ( {
42
42
async takePicture ( ) {
43
43
if ( ! videoRef . current ) { throw new Error ( 'Camera is not ready!' ) ; }
44
+
45
+ if ( utils . getOS ( ) === 'iOS' ) {
46
+ const uri = videoRef . current . getScreenshot ( ) ;
47
+ return { uri } ;
48
+ }
49
+
44
50
const { width, height, stream } = camera ;
45
51
46
- if ( ImageCapture && getOS ( ) !== 'ios ' ) {
52
+ if ( ImageCapture && utils . getOS ( ) !== 'iOS ' ) {
47
53
const track = stream . getVideoTracks ( ) [ 0 ] ;
48
54
const imageCapture = new ImageCapture ( track ) ;
49
55
@@ -64,7 +70,7 @@ const Camera = ({ children, containerStyle, onCameraReady, title }, ref) => {
64
70
canvas . getContext ( '2d' )
65
71
. drawImage ( videoRef . current , 0 , 0 , width , height ) ;
66
72
67
- const imageType = utils . getOS ( ) === 'ios ' ? 'image/png' : 'image/webp' ;
73
+ const imageType = utils . getOS ( ) === 'iOS ' ? 'image/png' : 'image/webp' ;
68
74
const uri = canvas . toDataURL ( imageType ) ;
69
75
70
76
return { uri } ;
@@ -90,7 +96,9 @@ const Camera = ({ children, containerStyle, onCameraReady, title }, ref) => {
90
96
const devices = await findDevices ( ) ;
91
97
const bestCandidate = await findBestCandidate ( devices ) ;
92
98
93
- setVideoSource ( videoRef . current , bestCandidate . stream ) ;
99
+ if ( utils . getOS ( ) !== 'iOS' ) {
100
+ setVideoSource ( videoRef . current , bestCandidate . stream ) ;
101
+ }
94
102
95
103
setCamera ( bestCandidate ) ;
96
104
setLoading ( false ) ;
@@ -106,13 +114,27 @@ const Camera = ({ children, containerStyle, onCameraReady, title }, ref) => {
106
114
accessibilityLabel = "Camera container"
107
115
style = { [ styles . container , containerStyle ] }
108
116
>
109
- { /* eslint-disable-next-line jsx-a11y/media-has-caption */ }
110
- < Video
111
- autoPlay
112
- playsInline
113
- ref = { videoRef }
114
- { ...videoSize }
115
- />
117
+
118
+ { utils . getOS ( ) === 'iOS' ? (
119
+ < Webcam
120
+ ref = { videoRef }
121
+ screenshotQuality = { 1 }
122
+ videoConstraints = { camera . constraints . video }
123
+ audioConstraints = { camera . constraints . audio }
124
+ minScreenshotHeight = { camera . height }
125
+ minScreenshotWidth = { camera . width }
126
+ style = { videoSize }
127
+ { ...videoSize }
128
+ />
129
+ ) : (
130
+ /* eslint-disable-next-line jsx-a11y/media-has-caption */
131
+ < Video
132
+ autoPlay
133
+ playsInline
134
+ ref = { videoRef }
135
+ { ...videoSize }
136
+ />
137
+ ) }
116
138
{ children }
117
139
< Text style = { styles . title } > { title } </ Text >
118
140
</ View >
0 commit comments