Skip to content

configureWebView is called multiple times for no apparent reason (always after reload of a content of the webview) #40

Closed
@vol24pl

Description

@vol24pl

ViewController#1 with captcha

        reCaptcha.rx.validate(on: view).subscribe(onNext: { [weak self] (token: String) in
            guard let `self` = self else { return }
            self.viewModel.captchaToken = token
            self.dismiss(animated: true)
        }) >>> bag

        reCaptcha.configureWebView { [weak self] webView in
            guard let `self` = self else { return }
            if self.viewModel.captchaToken == nil {
                self.viewModel.openReCaptcha(source: self, webView: webView) //open new VC#2 modally
            }
        }

ViewController#2 with webView

    override func viewDidLoad() {
        super.viewDidLoad()
        setupWebView()
    }

    private func setupWebView() {
        webContainerView.addSubview(webView)
        webView.frame = webContainerView.bounds
        webView.scrollView.isScrollEnabled = false
    }

STR:

  1. Open VC#1
  2. Wait for configureWebView to trigger. It will open VC#2
  3. Don't fill ReCaptcha challange, just dismiss() this VC#2
  4. Wait for about 10 minutes with VC#1 on the screen (I tested it twice with stopwatch at it was 10 mintues +/- 10 seconds both times!)

Expected: Nothing happened
Result: After 10 idle minutes configureWebView closure is oppened again from case .showReCaptcha. It will open VC#2, but there will be now webView this time.

Additional problem:
This line is a workaround:

if self.viewModel.captchaToken == nil { 
    //code 
}

as configureWebView is triggered also right after validation closure is done...

also this code

// Ensures `configureWebView` won't get called multiple times in a short period
            DispatchQueue.main.debounce(interval: 1)

will work only if not debugging. When paused in debug, more than 1 second will pass and there will be more than one consecutive call (just not within one second).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions