Skip to content

Commit

Permalink
Fix loading experience
Browse files Browse the repository at this point in the history
  • Loading branch information
hoyelo committed Jun 5, 2024
1 parent c1660c2 commit 6141792
Showing 1 changed file with 13 additions and 28 deletions.
41 changes: 13 additions & 28 deletions AffirmSDK/AffirmBaseWebViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ @implementation AffirmBaseWebViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];

WKWebViewConfiguration *configuration = [WKWebViewConfiguration new];
configuration.preferences.javaScriptCanOpenWindowsAutomatically = YES;
Expand All @@ -37,7 +38,6 @@ - (void)viewDidLoad
webView.multipleTouchEnabled = NO;
webView.navigationDelegate = self;
webView.UIDelegate = self;
[webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
[self.view addSubview:webView];
self.webView = webView;

Expand All @@ -64,43 +64,28 @@ - (void)viewWillDisappear:(BOOL)animated
}
}

- (void)dealloc
- (void)loadErrorPage:(NSError *)error
{
if (self.webView) {
[self.webView removeObserver:self
forKeyPath:@"estimatedProgress"
context:nil];
}
[[AffirmLogger sharedInstance] trackEvent:@"Web load failed"
parameters:@{@"error_description": error.localizedDescription}];
}

- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary<NSString *,id> *)change
context:(void *)context
- (void)dismiss
{
if ([keyPath isEqualToString:@"estimatedProgress"]) {
if ([[change valueForKey:@"new"] floatValue] >= 1.0) {
[self.activityIndicatorView stopAnimating];
} else {
[self.activityIndicatorView startAnimating];
}
} else {
[super observeValueForKeyPath:keyPath
ofObject:object
change:change
context:context];
}
[self dismissViewControllerAnimated:YES completion:nil];
}

- (void)loadErrorPage:(NSError *)error
#pragma mark - WKUIDelegate
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation
{
[[AffirmLogger sharedInstance] trackEvent:@"Web load failed"
parameters:@{@"error_description": error.localizedDescription}];
[self.activityIndicatorView startAnimating];
webView.hidden = YES;
}

- (void)dismiss
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
{
[self dismissViewControllerAnimated:YES completion:nil];
[self.activityIndicatorView stopAnimating];
webView.hidden = NO;
}

#pragma mark - WKNavigationDelegate
Expand Down

0 comments on commit 6141792

Please sign in to comment.