Skip to content

Commit feb4076

Browse files
committed
fix(QrcodeStream): iOS 15 won't render camera
When a camera stream is loaded, we assign the stream to a `video` element via `video.srcObject`. At this point the element is hidden with `v-show="false"` aka. `display: none`. We do that because at this point the videos dimensions are not known yet. We have to wait for the `loadeddata` event first. Only after that event we display the video element. Otherwise the elements size awkwardly flickers. However, it appears since iOS 15 all iOS browsers won't properly render the video element if the `video.srcObject` was assigned *while* the element was hidden with `display: none`. Using `visibility: hidden` instead seems to have fixed the problem though. Issue: #264 #266
1 parent 35f718f commit feb4076

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/components/QrcodeStream.vue

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
-->
88
<video
99
ref="video"
10-
v-show="shouldScan"
10+
:class="{ 'qrcode-stream-camera--hidden': !shouldScan }"
1111
class="qrcode-stream-camera"
1212
autoplay
1313
muted
@@ -181,19 +181,6 @@ export default {
181181
}
182182
},
183183
184-
onLocate(location) {
185-
if (this.trackRepaintFunction === undefined || location === null) {
186-
this.clearCanvas(this.$refs.trackingLayer);
187-
} else {
188-
const video = this.$refs.video;
189-
const canvas = this.$refs.trackingLayer;
190-
191-
if (video !== undefined && canvas !== undefined) {
192-
this.repaintTrackingLayer(video, canvas, location);
193-
}
194-
}
195-
},
196-
197184
onLocate(detectedCodes) {
198185
const canvas = this.$refs.trackingLayer;
199186
const video = this.$refs.video;
@@ -318,4 +305,20 @@ export default {
318305
display: block;
319306
object-fit: cover;
320307
}
308+
/* When a camera stream is loaded, we assign the stream to the `video`
309+
* element via `video.srcObject`. At this point the element used to be
310+
* hidden with `v-show="false"` aka. `display: none`. We do that because
311+
* at this point the videos dimensions are not known yet. We have to
312+
* wait for the `loadeddata` event first. Only after that event we
313+
* display the video element. Otherwise the elements size awkwardly flickers.
314+
*
315+
* However, it appears in iOS 15 all iOS browsers won't properly render
316+
* the video element if the `video.srcObject` was assigned *while* the
317+
* element was hidden with `display: none`. Using `visibility: hidden`
318+
* instead seems to have fixed the problem though.
319+
*/
320+
.qrcode-stream-camera--hidden {
321+
visibility: hidden;
322+
position: absolute;
323+
}
321324
</style>

0 commit comments

Comments
 (0)