Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

More info in the Opacity of the WebView section #7

Closed
Jacobra93 opened this issue Dec 10, 2020 · 22 comments
Closed

More info in the Opacity of the WebView section #7

Jacobra93 opened this issue Dec 10, 2020 · 22 comments

Comments

@Jacobra93
Copy link

I do not see the scanner open up when the method is fired. I think this is because the webview is blocking it, because I can see that background: 'transparent'; is applied but I guess it's not enough. I have tried applying background: 'transparent'; to other layers, like ion-app and ion-content, to no avail.

Any tips or examples of other plugins getting the webview transparent?

I am trying to use this in an Ionic Capacitor app. The scanner doesn't show up on Android or iOS.

@Jacobra93
Copy link
Author

I got it to work by adding:

Android, on the body tag:
opacity: 0;
background: none;

iOS, on the html tag:
opacity: 0;

@tafelnl
Copy link
Member

tafelnl commented Dec 10, 2020

Thanks for sharing!

@tafelnl tafelnl closed this as completed Dec 10, 2020
@lewdea
Copy link

lewdea commented Dec 11, 2020

I got it to work by adding:

Android, on the body tag:
opacity: 0;
background: none;

iOS, on the html tag:
opacity: 0;

If the root Html tag is set to "opacity: 0", then how can we implement custom UI on camera view?

@tafelnl
Copy link
Member

tafelnl commented Dec 11, 2020

@lewdea Fair point. Changing the opacity should not be necessary. Most of the time you should just change the background of one of more divs to none. You can try opening up the app with chrome://inspect/#devices for example and inspect every div (top to bottom) to hide their background.

@Jacobra93
Copy link
Author

@lewdea Good point. Were you able to get it working without using the opacity? I would like to utilize custom UI on the camera view so I guess I'll have to figure something else out.
@tafelnl I tried putting transparent on multiple levels in an Ionic app and nothing seemed to make the camera view show up, but I will try to play around with it some more.

@tafelnl
Copy link
Member

tafelnl commented Dec 14, 2020

What you could do to discover what divs are responsible for it, is the following:

Inspect your webapp in your browser. Add some very noticeable background color to <html>. Then delete the most upper root div and see if you can see the background color of <html>. You do? Nice. Undo the deletion and remove the child of that div. Etc etc. This way you can gradually debug and discover what divs are responsible for overlaying the barcode scanner.

@lewdea
Copy link

lewdea commented Dec 15, 2020

@Jacobra93 I got it working by setting body tag background to transparent too. There is no need to set every element's style. My app is built with ionic-vue and capacitor.
BarcodeScanner.hideBackground(); document.body.style.background = "transparent"; result.value = await BarcodeScanner.startScan();

@SalahAdDin
Copy link

What you could do to discover what divs are responsible for it, is the following:

Inspect your webapp in your browser. Add some very noticeable background color to <html>. Then delete the most upper root div and see if you can see the background color of <html>. You do? Nice. Undo the deletion and remove the child of that div. Etc etc. This way you can gradually debug and discover what divs are responsible for overlaying the barcode scanner.

I got the IonTabs component is hiding it, so, how can i handle it? Also, if we want to create a custom UI, how can we do that?

@tafelnl
Copy link
Member

tafelnl commented Mar 3, 2021

You should probably use the native Ionic way of hiding such components (which I do not know anything about unfortunately). You could also try and hide it with JavaScript.

Custom UI can be created in any way you like. An example can be found here: https://github.com/capacitor-community/barcode-scanner/tree/main/examples/scan-area-layout

@SalahAdDin
Copy link

SalahAdDin commented Mar 3, 2021

@tafelnl is there no other way to do this without handling background by ourselves? cardIo scanner put the camera over the browser markup as far as i could understand.

Maybe like this one: https://bitbucket.org/golbros/capacitor-qrscanner/src/master/

It is specially a matter since:
ProblemWithQRScanner

We can find another example here.

@tafelnl
Copy link
Member

tafelnl commented Mar 3, 2021

I am not sure what you are trying to accomplish. Your screenvideo looks good to me. Could you elaborate?

@SalahAdDin
Copy link

SalahAdDin commented Mar 3, 2021

Every time i have to reload the app, the scanner screen is showed, it must not be like that; but when i open the scanner, well, i couldn't handle the IonTabs component opacity yet.

I mean, i'm not opening the scanner, I'M loading/reloading the application.

@tafelnl
Copy link
Member

tafelnl commented Mar 4, 2021

I am trying my best to understand @SalahAdDin . But I am still not sure what you mean. What exactly do you mean by reloading? And what exactly happens that you think should not happen?

@SalahAdDin
Copy link

I made my template like this:

    <div id="scanner-ui" class="scanner-ui">
      <div class="sample-background">
        <!-- this background simulates the camera view -->
      </div>
      <div class="container">
        <div class="barcode-scanner--area--container">
          <div class="relative">
            <p>Kameranızı bir barkoda doğrultun</p>
          </div>
          <div class="square surround-cover">
            <div class="barcode-scanner--area--outer surround-cover">
              <div class="barcode-scanner--area--inner"></div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div id="root"></div>

.scanner-ui has display: none by default.

In React i get both one and i switch them when it is required.

Thanks.

@tpharaoh
Copy link

@lewdea I am having a similar issue with vuejs, do you mind posting a snippet?

@tpharaoh
Copy link

Thanks @lewdea I tried this based on your idea above and it essentially worked

const startScan = async () => {
        document.body.style.opacity="0.2";
      document.body.style.background = "transparent";
      
       BarcodeScanner.hideBackground(); // make background of WebView transparent

      const result = await BarcodeScanner.startScan(); // start scanning and wait for a result

      // if the result has content
      if (result.hasContent) {
          document.body.style.background = "";
          document.body.style.opacity="1";
        console.log(result.content); // log the raw scanned content
      }
    }

@tpharaoh
Copy link

@SalahAdDin did you succeed with this plugin and your design?

Our app has a background, and as other posters that meant I needed the background='transparent' and opacity

I would have liked to have just a portion of the screen with the camera...

Its OK, client doesn't require it, but I just had a vision :)

@SalahAdDin
Copy link

We handle it by changing the body display attribute while the scanner is on.

This was referenced May 25, 2021
@renatojobal
Copy link

For someone still wondering how to achieve that on an ionic app:
There should be a file ionicapp/src/theme/variables.css. Here you could set the background to transparent on the items .md body { and .ios body {. For example:
image

The opacity is set by the last two digits on an hexadecimal color. So using 00 at the end will be full transparent.

@betosimo
Copy link

on ionic, insted of transparent I put a display none on body, like this on global styles:
body.scanner-active {
--background: transparent;
--ion-background-color: transparent;
display: none;
}
works, but how to get out? theres no cancel button and the slide to left dont work either

@JanMisker
Copy link

@betosimo with display:none you basically remove/hide your entire app. A cancel button is then also hidden, and swipe gesture probably doesn't work because there is nothing to swipe on.
What you would have to do is make everything transparent except your cancel/back button.

@selcukbeyhan
Copy link

on ionic, insted of transparent I put a display none on body, like this on global styles: body.scanner-active { --background: transparent; --ion-background-color: transparent; display: none; } works, but how to get out? theres no cancel button and the slide to left dont work either

this worked for me too :)

What you can do is:

  • if the scan is successful, you set the background back to its original value --> this is what I do
  • you can have a timeout to stop the scan if the scan is not successful for some seconds.

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

No branches or pull requests

9 participants