Skip to content

Commit 537a564

Browse files
committed
Fix layout
1 parent c557aa2 commit 537a564

File tree

4 files changed

+42
-12
lines changed

4 files changed

+42
-12
lines changed

packages/camera/src/components/Camera/index.js

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,30 @@ const tests = [
7676
ratio: '4:3',
7777
}];
7878

79-
const { getUserMedia } = navigator.mediaDevices || navigator.mozGetUserMedia;
79+
function getUserMedia(constraints) {
80+
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
81+
return navigator.mediaDevices.getUserMedia(constraints);
82+
}
83+
84+
// Some browsers partially implement mediaDevices. We can't just assign an object
85+
// with getUserMedia as it would overwrite existing properties.
86+
// Here, we will just add the getUserMedia property if it's missing.
87+
88+
// First get hold of the legacy getUserMedia, if present
89+
const get = navigator.getUserMedia
90+
|| navigator.webkitGetUserMedia
91+
|| navigator.mozGetUserMedia
92+
|| (() => {
93+
const error = new Error('Permission unimplemented');
94+
error.code = 0;
95+
error.name = 'NotAllowedError';
96+
throw error;
97+
});
98+
99+
return new Promise((resolve, reject) => {
100+
get.call(navigator, constraints, resolve, reject);
101+
});
102+
}
80103

81104
const Camera = ({ children, containerStyle, onCameraReady, title }, ref) => {
82105
const windowDimensions = useWindowDimensions();
@@ -85,7 +108,7 @@ const Camera = ({ children, containerStyle, onCameraReady, title }, ref) => {
85108
const [candidate, setCandidate] = useState();
86109
const [loading, setLoading] = useState(false);
87110

88-
const { width: videoWith, height: videoHeight } = useMemo(() => {
111+
const { width: videoWidth, height: videoHeight } = useMemo(() => {
89112
if (!candidate) { return { width: 0, height: 0 }; }
90113
return getSize(candidate.test.ratio, windowDimensions, 'number');
91114
}, [candidate, windowDimensions]);
@@ -163,7 +186,9 @@ const Camera = ({ children, containerStyle, onCameraReady, title }, ref) => {
163186
.drawImage(videoEl.current, 0, 0, canvasEl.current.width, canvasEl.current.height);
164187

165188
const imageType = utils.getOS() === 'ios' ? 'image/png' : 'image/webp';
166-
return { uri: canvasEl.current.toDataURL(imageType) };
189+
const uri = canvasEl.current.toDataURL(imageType);
190+
191+
return { uri };
167192
},
168193
async resumePreview() {
169194
if (videoEl.current) {
@@ -194,15 +219,16 @@ const Camera = ({ children, containerStyle, onCameraReady, title }, ref) => {
194219

195220
if ('srcObject' in video) {
196221
video.srcObject = bestCandidate.stream;
222+
video.play();
197223
} else {
198224
video.src = window.URL.createObjectURL(bestCandidate.stream);
199225
}
200226

201-
video.onloadedmetadata = () => { video.play(); };
202-
203227
canvas.width = bestCandidate.test.width;
204228
canvas.height = bestCandidate.test.height;
205229

230+
video.onloadedmetadata = () => { video.play(); };
231+
206232
setLoading(false);
207233
onCameraReady();
208234
}
@@ -211,6 +237,7 @@ const Camera = ({ children, containerStyle, onCameraReady, title }, ref) => {
211237

212238
return (
213239
<View
240+
pointerEvents="box-none"
214241
accessibilityLabel="Camera container"
215242
style={[styles.container, containerStyle]}
216243
>
@@ -219,7 +246,7 @@ const Camera = ({ children, containerStyle, onCameraReady, title }, ref) => {
219246
autoPlay
220247
playsInline
221248
ref={videoEl}
222-
width={videoWith}
249+
width={videoWidth}
223250
height={videoHeight}
224251
/>
225252
<canvas ref={canvasEl} />

packages/camera/src/components/Camera/styles.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export default StyleSheet.create({
44
container: {
55
display: 'flex',
66
alignItems: 'center',
7+
position: 'absolute',
8+
top: 0,
79
},
810
title: {
911
alignSelf: 'center',

packages/camera/src/components/Capture/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ import {
2929
} from './hooks';
3030

3131
const styles = StyleSheet.create({
32-
container: { flex: 1 },
32+
container: {
33+
flex: 1,
34+
},
3335
loading: {
3436
flex: 1,
3537
alignItems: 'center',
@@ -75,7 +77,6 @@ const styles = StyleSheet.create({
7577
* @param submitButtonLabel
7678
* @param thumbnailStyle
7779
* @param uploads
78-
* @param submitButtonProps
7980
* @param task
8081
* @return {JSX.Element}
8182
* @constructor

packages/toolkit/src/utils/styles/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,19 @@ export const flex = {
4646
*/
4747
export function getSize(ratio = '4:3', { height, width, windowHeight, windowWidth }, returnType) {
4848
const [a, b] = ratio.split(':').sort((c, d) => (d - c)); // 4:3 || 3:4
49-
const w = Math.floor(parseInt(width || windowWidth, 10));
50-
const h = Math.floor(parseInt(height || windowHeight, 10));
49+
const w = Math.round(parseInt(width || windowWidth, 10));
50+
const h = Math.round(parseInt(height || windowHeight, 10));
5151

5252
const longest = h <= w ? h : w;
5353

5454
const sizesByPlatform = {
5555
native: {
5656
height: longest,
57-
width: Math.floor(longest * (a / b)),
57+
width: Math.round(longest * (a / b)),
5858
},
5959
default: {
6060
height: '100vh',
61-
width: `${Math.floor(100 * (a / b))}vh`,
61+
width: `${Math.round(100 * (a / b))}vh`,
6262
},
6363
};
6464

0 commit comments

Comments
 (0)