Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cordova: Scanner appears in full screen #947

Open
davidjandrey-sv opened this issue Aug 30, 2024 · 1 comment
Open

Cordova: Scanner appears in full screen #947

davidjandrey-sv opened this issue Aug 30, 2024 · 1 comment

Comments

@davidjandrey-sv
Copy link

davidjandrey-sv commented Aug 30, 2024

Description
When using this feature in a Cordova native app on iOS, the scanner isn't (just) embedded in the DOM as on web, but with it appears a fullscreen overlay with an X in the top left and a mute button in the top right, that doesn't seem to contain scanner functionality. Once that view is closed via the X button, the DOM-embedded scanner is frozen.

We don't want that to happen, we just want it to be integrated into our webpage, just like it works for us in Chrome, Firefox and Safari.
I'm not sure whether this is a bug or a configuration issue, so here's the relevant code snipped from our side:

const configSetup: Html5QrcodeFullConfig = {
    verbose: false,
    formatsToSupport: [
        Html5QrcodeSupportedFormats.QR_CODE,
        Html5QrcodeSupportedFormats.EAN_8,
        Html5QrcodeSupportedFormats.EAN_13,
    ],
}

const configUI: Html5QrcodeCameraScanConfig = {
    fps: 10,
    videoConstraints: {
        height: { min: 720, ideal: 1920, max: 2560 },
        width: { min: 480, ideal: 1080, max: 1440 }, // no idea why this has to be the wrong way around
        facingMode: "environment",
    },
    qrbox: (w, h) => {
        const size = Math.min(w, h) * 0.9
        return {
            width: Math.max(size, 50),
            height: Math.max(size, 50),
        }
    },
}

const scanner = new Html5Qrcode(elementId, configSetup)
await scanner.start(
    { facingMode: "environment" },
    configUI,
    (text, result) => {
        onResult(text, result.result.format?.formatName)
    },
    () => {}
)

(Also for some reason width and height are swapped for the scanner view in DOM)

iOS native (actual behavior):
image

iOS Safari (expected behavior):
image

@Michae1Weiss
Copy link

Hi,
The issue you're experiencing is due to how <video> tags are handled in Cordova apps on iOS. By default, iOS opens media content using its native media viewer, which causes the fullscreen overlay you're seeing.

Solution

To prevent this and allow inline media playback (so the scanner remains embedded in the DOM as expected), you can modify your config.xml file in your your Cordova project by adding the following line:

<preference name="AllowInlineMediaPlayback" value="true"/>

This setting enables media content to be displayed inline, without triggering the iOS default media viewer.

See Cordova documentation:
https://cordova.apache.org/docs/en/12.x/config_ref/index.html#preference

Testing Environment

I tested this solution on an iPad 10th Gen.

Versions:

  • Cordova CLI: 12.0.0
  • iOS Platform: 7.1.1
  • Xcode: 15.4
  • OS: macOS Sonoma 14.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants