barcode-scanner icon indicating copy to clipboard operation
barcode-scanner copied to clipboard

(iOS) showBackground set webview to white instead of previous color

Open florianguillaumin opened this issue 3 years ago • 1 comments

Describe the bug When showBackground is called, the webview is set to white.

The webview backgroundColor can be set in capacitor.config.js with a custom color.

showBackground should revert to the previous backgroundColor instead of white.

Code Reference

// @capacitor-community/barcode-scanner/ios/Plugin/Plugin.swift
private func showBackground() {
        DispatchQueue.main.async {
            let javascript = "document.documentElement.style.backgroundColor = ''"

            self.bridge?.webView!.evaluateJavaScript(javascript) { (result, error) in
                self.bridge?.webView!.isOpaque = true
                self.bridge?.webView!.backgroundColor = UIColor.white
                self.bridge?.webView!.scrollView.backgroundColor = UIColor.white
            }
        }
    }
// @capacitor/ios/Capacitor/Capacitor/CAPBridgeViewController.swift
// line 294
if let backgroundColor = configuration.backgroundColor {
            aWebView.backgroundColor = backgroundColor
            aWebView.scrollView.backgroundColor = backgroundColor
} else {
    // Use the system background colors if background is not set by user
    aWebView.backgroundColor = UIColor.systemBackground
    aWebView.scrollView.backgroundColor = UIColor.systemBackground
}

Version Barcode-scanner: 3.0.0 Capacitor-ios: 4.1.0

Additional context There is an open bug on Capacitor when using a custom color. isOpaque needs to be set to false

florianguillaumin avatar Aug 29 '22 11:08 florianguillaumin

I already now about this issue, but thank you for opening it as an issue.

Would it be possible for you to create a PR of your changes for Android and iOS?

thegnuu avatar Sep 09 '22 07:09 thegnuu

Hi @thegnuu, I've created PR #201 to address the iOS issue raised here.

andrewchilds avatar Mar 08 '23 18:03 andrewchilds

Merged ;) But I missed to close the issue.

thegnuu avatar May 08 '23 15:05 thegnuu