From 275b3c4a735a265d738a9ae8496162a6c204620c Mon Sep 17 00:00:00 2001 From: David Sinclair Date: Tue, 26 May 2020 14:13:46 -0700 Subject: [PATCH] #1306 (status bar during fullscreen) - When the status bar is shown and nav bar hidden, now shows the feed gradient. - Fixed incorrect scrolling when going to a story that shows the bar. - Fixed the status bar background not showing up. - Fixed the traversal buttons sliding down on first appearance. --- clients/ios/Classes/NewsBlurAppDelegate.m | 2 +- clients/ios/Classes/StoryDetailViewController.m | 15 ++++++++++++--- clients/ios/Classes/StoryPageControl.m | 13 +++++++++---- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/clients/ios/Classes/NewsBlurAppDelegate.m b/clients/ios/Classes/NewsBlurAppDelegate.m index bd0ba71e4..23742e50c 100644 --- a/clients/ios/Classes/NewsBlurAppDelegate.m +++ b/clients/ios/Classes/NewsBlurAppDelegate.m @@ -3314,7 +3314,7 @@ [gradientView addSubview:titleImageView]; } else { gradientView = [NewsBlurAppDelegate - makeGradientView:CGRectMake(0, -1, rect.size.width, 10) + makeGradientView:CGRectMake(0, rect.origin.y, rect.size.width, 10) // hard coding the 1024 as a hack for window.frame.size.width startColor:[feed objectForKey:@"favicon_fade"] endColor:[feed objectForKey:@"favicon_color"] diff --git a/clients/ios/Classes/StoryDetailViewController.m b/clients/ios/Classes/StoryDetailViewController.m index f4950b876..4e25df71f 100644 --- a/clients/ios/Classes/StoryDetailViewController.m +++ b/clients/ios/Classes/StoryDetailViewController.m @@ -602,6 +602,11 @@ } - (void)drawFeedGradient { + NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults]; + BOOL shouldHideStatusBar = [preferences boolForKey:@"story_hide_status_bar"]; + UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; + BOOL shouldOffsetFeedGradient = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && !UIInterfaceOrientationIsLandscape(orientation) && self.navigationController.navigationBarHidden && !shouldHideStatusBar; + CGFloat yOffset = shouldOffsetFeedGradient ? appDelegate.storyPageControl.statusBarBackgroundView.bounds.size.height - 1 : -1; NSString *feedIdStr = [NSString stringWithFormat:@"%@", [self.activeStory objectForKey:@"story_feed_id"]]; @@ -614,7 +619,7 @@ self.feedTitleGradient = [appDelegate makeFeedTitleGradient:feed - withRect:CGRectMake(0, -1, CGRectGetWidth(self.view.bounds), 21)]; // 1024 hack for self.webView.frame.size.width + withRect:CGRectMake(0, yOffset, CGRectGetWidth(self.view.bounds), 21)]; // 1024 hack for self.webView.frame.size.width self.feedTitleGradient.autoresizingMask = UIViewAutoresizingFlexibleWidth; self.feedTitleGradient.tag = FEED_TITLE_GRADIENT_TAG; // Not attached yet. Remove old gradients, first. @@ -635,7 +640,7 @@ [self.webView insertSubview:feedTitleGradient aboveSubview:self.webView.scrollView]; if (@available(iOS 11.0, *)) { - if (self.view.safeAreaInsets.top > 0.0 && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + if (self.view.safeAreaInsets.top > 0.0 && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && shouldHideStatusBar) { feedTitleGradient.alpha = self.navigationController.navigationBarHidden ? 1 : 0; [UIView animateWithDuration:0.3 animations:^{ @@ -1404,7 +1409,11 @@ // appDelegate.storyPageControl.traverseView.frame = CGRectMake(tvf.origin.x, // (webpageHeight - topPosition) - tvf.size.height - safeBottomMargin, // tvf.size.width, tvf.size.height); - appDelegate.storyPageControl.traverseBottomConstraint.constant = viewportHeight - (webpageHeight - topPosition) + safeBottomMargin; + if (webpageHeight > 0) { + appDelegate.storyPageControl.traverseBottomConstraint.constant = viewportHeight - (webpageHeight - topPosition) + safeBottomMargin; + } else { + appDelegate.storyPageControl.traverseBottomConstraint.constant = safeBottomMargin; + } // appDelegate.storyPageControl.traverseBottomConstraint.constant = safeBottomMargin; } } else if (!singlePage && (atTop && !atBottom)) { diff --git a/clients/ios/Classes/StoryPageControl.m b/clients/ios/Classes/StoryPageControl.m index ab51fb500..ad98d016c 100644 --- a/clients/ios/Classes/StoryPageControl.m +++ b/clients/ios/Classes/StoryPageControl.m @@ -228,6 +228,8 @@ [self.view addConstraint:self.notifier.topOffsetConstraint]; [self.notifier hideNow]; + self.traverseBottomConstraint.constant = 50; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects: originalStoryButton, @@ -235,8 +237,6 @@ fontSettingsButton, nil]; } - [self updateTheme]; - [self.scrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil]; @@ -266,6 +266,8 @@ - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; + [self updateTheme]; + [self updateAutoscrollButtons]; [self updateTraverseBackground]; [self setNextPreviousButtons]; @@ -500,7 +502,7 @@ NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults]; BOOL swipeEnabled = [[userPreferences stringForKey:@"story_detail_swipe_left_edge"] - isEqualToString:@"pop_to_story_list"];; + isEqualToString:@"pop_to_story_list"]; self.navigationController.interactivePopGestureRecognizer.enabled = swipeEnabled; if (hide) { @@ -1239,7 +1241,10 @@ } self.scrollView.scrollsToTop = NO; - NSInteger topPosition = currentPage.webView.scrollView.contentOffset.y; + NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults]; + BOOL shouldHideStatusBar = [preferences boolForKey:@"story_hide_status_bar"]; + NSInteger statusBarOffset = shouldHideStatusBar ? 0 : self.statusBarHeight; + NSInteger topPosition = currentPage.webView.scrollView.contentOffset.y + statusBarOffset; BOOL canHide = currentPage.canHideNavigationBar && topPosition >= 0; if (!canHide && self.isHorizontal && self.navigationController.navigationBarHidden) {