iOS: #1137 (full screen reading)

This commit is contained in:
David Sinclair 2018-12-24 14:39:28 -08:00
parent 148fc31f54
commit cd101bfc41

View file

@ -1890,25 +1890,44 @@ shouldStartLoadWithRequest:(NSURLRequest *)request
} }
} }
CGFloat sign = hide ? -1.0 : 1.0; if (oldOffset.y < 0.0) {
CGFloat totalAdjustment = sign * (navHeight + statusAdjustment); oldOffset.y = 0.0;
CGPoint newOffset = CGPointMake(oldOffset.x, oldOffset.y + totalAdjustment); }
UIView *webContent = self.webView.scrollView.subviews.firstObject;
CGRect webFrame = webContent.frame;
CGRect adjustedFrame = webFrame;
if (hide) { CGFloat sign = hide ? -1.0 : 1.0;
adjustedFrame = CGRectMake(webFrame.origin.x, webFrame.origin.y + totalAdjustment, webFrame.size.width, webFrame.size.height + totalAdjustment); CGFloat absoluteAdjustment = navHeight + statusAdjustment;
CGFloat totalAdjustment = sign * absoluteAdjustment;
CGPoint newOffset = CGPointMake(oldOffset.x, oldOffset.y + totalAdjustment);
BOOL wantTopMargin = oldOffset.y == 0.0;
if (wantTopMargin && hide) {
NSString *marginString = [NSString stringWithFormat:@"%@px", @(absoluteAdjustment)];
NSString *jsString = [NSString stringWithFormat:@"document.getElementById('NB-header-container').style.marginTop = '%@';",
marginString];
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
self.webView.scrollView.contentOffset = oldOffset;
} }
[UIView animateWithDuration:0.2 animations:^{ [UIView animateWithDuration:0.2 animations:^{
[self setNeedsStatusBarAppearanceUpdate]; [self setNeedsStatusBarAppearanceUpdate];
if (hide) {
// webContent.frame = adjustedFrame;
}
self.webView.scrollView.contentOffset = newOffset; self.webView.scrollView.contentOffset = newOffset;
}
completion:^(BOOL finished) {
if (!hide) {
NSString *jsString = [NSString stringWithFormat:@"document.getElementById('NB-header-container').style.marginTop;"];
NSString *topMargin = [self.webView stringByEvaluatingJavaScriptFromString:jsString];
if (![topMargin isEqualToString:@"0px"]) {
jsString = [NSString stringWithFormat:@"document.getElementById('NB-header-container').style.marginTop = '0px';"];
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
self.webView.scrollView.contentOffset = oldOffset;
}
}
}]; }];
} }