hCaptcha / HCaptcha-ios-sdk

HCaptcha SDK for iOS
Other
56 stars 20 forks source link

Query: adding hCaptcha WkWebview to a container with a blur background #50

Closed e271828- closed 2 years ago

e271828- commented 2 years ago

Report: when adding the hCaptcha WkWebview to a container with a blur background the Webview is not loading sometimes.

Snippet:

hcaptcha?.configureWebView { [weak self] webview in
            webview.frame = self?.captchaContainerView.bounds ?? CGRect.zero
        }

        hcaptcha?.validate(on: captchaContainerView,
                           resetOnError: true,
                           completion: { [weak self] result in
            guard let self = self else {
                completionHandler(false, nil, ZError.default)
                return
            }

            self.captchaBackgroundView.zHide()
            self.captchaBackgroundView.removeFromSuperview()

            self.hcaptcha?.stop()
            if let data = try? result.dematerialize() {
                ZLog.i(data)
                completionHandler(true, data, nil)
            }
            else {
                completionHandler(false, nil, ZError.default)
            }
        })
CAMOBAP commented 2 years ago

In progress

CAMOBAP commented 2 years ago

I think I have reproduced the issue, but I'm not 100% sure

Here is what I did:

Screenshot from Debug View Hierarchy

runtime

Screenshot from Interface Builder

ui_builder

Result

The WebView looks gray

simulator

@e271828- can we somehow confirm that this is the issue which client observe? Maybe we can ask for some screenshots?

CAMOBAP commented 2 years ago

I have found that issue happens if we are trying to add WKWebView to subview of UIVisualEffectView or its child (red rectangle on the screenshot below)

As workaround we may use parent view of UIVisualEffectView, the green rectangle on the screenshot below

Screen Shot 2022-03-08 at 7 27 36 AM

`

P.S. Still researching the root of the issue, and workaround to allow placing WKWebView on top of UIVisualEffectView

CAMOBAP commented 2 years ago

Update

Per Apple's documentation:

After you add the visual effect view to the view hierarchy, add any subviews to the contentView property of the visual effect view. Do not add subviews directly to the visual effect view itself.

Also, the same issue described on SO https://stackoverflow.com/questions/46355872/warning-from-ios-do-not-add-subviews-directly-to-the-visual-effect-view-itself

So instead passing visualEffectView (instance of UIVisualEffectView), pass visualEffectView.contentView