iOS web browser with a focus on security and privacy

WVC: fix layout issue after focusing url bar then viewing tabs

When viewDidLayoutSubviews is called during transition from keyboard
up to back down, self.view.safeAreaInsets.bottom is 0, which
viewDidLayoutSubviews uses to place the toolbar at the very bottom
of the screen.

Once the keyboard is actually down, viewSafeAreaInsetsDidChange is
then called slightly after which adjusts safeAreaInsets.bottom to
something bigger.

viewSafeAreaInsetsDidChange can't just call viewDidLayoutSubviews
though, because showingTabs is still true. So work around this by
caching any non-zero safeAreaInsets.bottom and use it when the
keyboard is still up but transitioning down (when it would be zero).

+17 -6
+17 -6
Endless/WebViewController.m
··· 37 37 UILabel *tabCount; 38 38 int keyboardHeight; 39 39 BOOL keyboardShowing; 40 + float safeAreaBottom; 40 41 41 42 UIButton *backButton; 42 43 UILongPressGestureRecognizer *historyRecognizer; ··· 86 87 self.darkInterface = [userDefaults boolForKey:@"dark_interface"]; 87 88 88 89 keyboardHeight = 0; 90 + safeAreaBottom = 0; 89 91 90 92 tabToolbarHairline = [[UIView alloc] init]; 91 93 [toolbar addSubview:tabToolbarHairline]; ··· 360 362 }]; 361 363 } 362 364 365 + - (void)viewSafeAreaInsetsDidChange 366 + { 367 + [super viewSafeAreaInsetsDidChange]; 368 + 369 + if (self.view.safeAreaInsets.bottom != 0) 370 + safeAreaBottom = self.view.safeAreaInsets.bottom; 371 + } 372 + 363 373 - (void)viewDidLayoutSubviews 364 374 { 365 - float statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height; 375 + UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; 376 + float statusBarHeight = (UIInterfaceOrientationIsLandscape(orientation) ? 0 : [[UIApplication sharedApplication] statusBarFrame].size.height); 366 377 367 378 /* views are transforming and we may calculate things incorrectly here, so just ignore this request */ 368 379 if (showingTabs) ··· 374 385 375 386 /* keep tabScroller the size of the root frame minus the toolbar */ 376 387 if (self.toolbarOnBottom) { 377 - toolbar.frame = tabToolbar.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.bounds.size.height - TOOLBAR_HEIGHT - (keyboardHeight ? 0 : self.view.safeAreaInsets.bottom), self.view.bounds.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, TOOLBAR_HEIGHT); 388 + toolbar.frame = tabToolbar.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.bounds.size.height - TOOLBAR_HEIGHT - (keyboardHeight ? 0 : safeAreaBottom), self.view.bounds.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, TOOLBAR_HEIGHT); 378 389 379 390 progressBar.frame = CGRectMake(0, 0, toolbar.bounds.size.width, 2); 380 391 tabToolbarHairline.frame = CGRectMake(0, 0, toolbar.bounds.size.width, 1); 381 392 382 - tabScroller.frame = CGRectMake(self.view.safeAreaInsets.left, 0, self.view.bounds.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.bounds.size.height - TOOLBAR_HEIGHT - self.view.safeAreaInsets.bottom); 393 + tabScroller.frame = CGRectMake(self.view.safeAreaInsets.left, 0, self.view.bounds.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.bounds.size.height - TOOLBAR_HEIGHT - (keyboardHeight ? 0 : safeAreaBottom)); 383 394 384 - tabChooser.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.bounds.size.height - TOOLBAR_HEIGHT - 20 - self.view.safeAreaInsets.bottom, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, 20); 395 + tabChooser.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.bounds.size.height - TOOLBAR_HEIGHT - 20 - (keyboardHeight ? 0 : safeAreaBottom), self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, 20); 385 396 } 386 397 else { 387 - toolbar.frame = tabToolbar.frame = CGRectMake(0, self.view.safeAreaInsets.left, self.view.bounds.size.width - self.view.safeAreaInsets.left + self.view.safeAreaInsets.right, TOOLBAR_HEIGHT); 398 + toolbar.frame = tabToolbar.frame = CGRectMake(0, 0, self.view.bounds.size.width - self.view.safeAreaInsets.left + self.view.safeAreaInsets.right, TOOLBAR_HEIGHT); 388 399 progressBar.frame = CGRectMake(0, TOOLBAR_HEIGHT - 2, toolbar.frame.size.width, 2); 389 400 tabToolbarHairline.frame = CGRectMake(0, TOOLBAR_HEIGHT - 0.5, toolbar.frame.size.width, 0.5); 390 401 391 402 tabScroller.frame = CGRectMake(0, TOOLBAR_HEIGHT, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT); 392 403 393 - tabChooser.frame = CGRectMake(0, self.view.bounds.size.height - 20 - 20, tabScroller.bounds.size.width, 20); 404 + tabChooser.frame = CGRectMake(0, self.view.bounds.size.height - 20 - (keyboardHeight ? 0 : safeAreaBottom), tabScroller.bounds.size.width, 20); 394 405 } 395 406 396 407 if (self.darkInterface) {