Closed
Description
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:
- Open VC#1
- Wait for
configureWebView
to trigger. It will open VC#2 - Don't fill ReCaptcha challange, just
dismiss()
this VC#2 - 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).