Shopify / shopify-app-bridge

https://shopify.dev/docs/api/app-bridge
82 stars 9 forks source link

Scanner API opens multiple barcode camera windows if you use the back button without scanning a barcode #345

Open DylanHenderson opened 1 month ago

DylanHenderson commented 1 month ago

Describe the bug

Using this API: https://shopify.dev/docs/api/app-bridge-library/apis/scanner

In the mobile app if you trigger opening the scanner, say with a button press, but do not scan a barcode. And you click the back button at the top left of the screen to close the scanner, the next time the app opens the scanner, 2 scanners will open. This continues, if you close those 2 by pressing back and open another, 3 will open. Scanning a barcode the app behaves as expected

To Reproduce

Steps to reproduce the behaviour:

  1. Run a simple app for example:
import { Button } from '@shopify/polaris';

export default function TestForm() {
    return (
        <div>
            <Button
                onClick={async () => {
                    try {
                        const payload = await shopify.scanner.capture();
                        console.log('Scanner success', payload);
                    } catch (error) {
                        console.log('Scanner error', error);

                    }
                }}
            >press me</Button>
        </div>
    );
}
  1. click the "press me" button to see the scanner open.
  2. Do not scan a barcode, just click back at the top left to close the scanner.
  3. click the "press me" button again
  4. you'll see 2 scanning windows open, scanning a barcode only closes 1 of them, pressing back only closes one of them.

Expected behavior

Clicking back should close the scanner as opposed to be what seems like minimizing it. Expected behavior is to not have multiple scan windows open, always one.

The app quickly becomes unusable after closing the barcode scanner a few times which is too common of an operation to ignore.

Contextual information

Packages and versions

"@shopify/app-bridge": "^3.7.10",
"@shopify/app-bridge-react": "^4.1.1",

Platform