#1329 & #1331 (changing to native fullscreen)

- Fixed issue of scrolling up on a short story jumping a bit.
- Fixed the feed bar showing when scrolling between stories.
- Fixed the feed bar showing correctly when going into and out of fullscreen.
- Fixed the status bar background.
- Cleaned up temporary code.
- (This was all harder than expected.)
This commit is contained in:
David Sinclair 2020-06-28 17:09:50 -07:00
parent a20ecf642f
commit e8bfbc97b9
3 changed files with 43 additions and 45 deletions

View file

@ -33,6 +33,7 @@
@interface StoryDetailViewController ()
@property (nonatomic, strong) NSString *fullStoryHTML;
@property (nonatomic) BOOL isBarHideSwiping;
@end
@ -296,6 +297,8 @@
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[self.navigationController.barHideOnSwipeGestureRecognizer removeTarget:self action:@selector(barHideSwipe:)];
if (!appDelegate.showingSafariViewController &&
appDelegate.navigationController.visibleViewController != (UIViewController *)appDelegate.shareViewController &&
appDelegate.navigationController.visibleViewController != (UIViewController *)appDelegate.trainerViewController &&
@ -317,6 +320,8 @@
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController.barHideOnSwipeGestureRecognizer addTarget:self action:@selector(barHideSwipe:)];
if (!self.isPhoneOrCompact) {
[appDelegate.feedDetailViewController.view endEditing:YES];
}
@ -616,8 +621,14 @@
BOOL navigationBarHidden = self.navigationController.navigationBarHidden;
BOOL shouldHideStatusBar = [preferences boolForKey:@"story_hide_status_bar"];
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
BOOL shouldOffsetFeedGradient = NO; //UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && !UIInterfaceOrientationIsLandscape(orientation) && navigationBarHidden && !shouldHideStatusBar;
CGFloat yOffset = shouldOffsetFeedGradient ? appDelegate.storyPageControl.statusBarBackgroundView.bounds.size.height - 1 : -1;
BOOL shouldOffsetFeedGradient = !self.isBarHideSwiping && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && !UIInterfaceOrientationIsLandscape(orientation) && navigationBarHidden && !shouldHideStatusBar;
CGFloat offset = 0;
if (shouldOffsetFeedGradient) {
offset = appDelegate.storyPageControl.statusBarBackgroundView.bounds.size.height;
}
CGFloat yOffset = offset - 1;
NSString *feedIdStr = [NSString stringWithFormat:@"%@",
[self.activeStory
objectForKey:@"story_feed_id"]];
@ -634,8 +645,6 @@
self.feedTitleGradient.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.feedTitleGradient.tag = FEED_TITLE_GRADIENT_TAG; // Not attached yet. Remove old gradients, first.
NSLog(@"⚠️ nav hidden: %@, should offset: %@, frame: %@, feedTitleGradient: %@", navigationBarHidden ? @"yes" : @"no", shouldOffsetFeedGradient ? @"yes" : @"no", NSStringFromCGRect(self.webView.scrollView.frame), @(yOffset)); // log
for (UIView *subview in self.webView.subviews) {
if (subview.tag == FEED_TITLE_GRADIENT_TAG) {
[subview removeFromSuperview];
@ -653,7 +662,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 /*&& shouldHideStatusBar*/) {
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:^{
@ -1318,6 +1327,9 @@
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if ([keyPath isEqual:@"contentOffset"]) {
BOOL isHorizontal = appDelegate.storyPageControl.isHorizontal;
BOOL isNavBarHidden = self.navigationController.navigationBarHidden;
if (self.webView.scrollView.contentOffset.y < (-1 * self.feedTitleGradient.frame.size.height + 1 + self.webView.scrollView.scrollIndicatorInsets.top)) {
// Pulling
if (!pullingScrollview) {
@ -1339,11 +1351,14 @@
if (pullingScrollview) {
pullingScrollview = NO;
[self.feedTitleGradient.layer setShadowOpacity:0];
[self.webView insertSubview:self.feedTitleGradient aboveSubview:self.webView.scrollView];
self.feedTitleGradient.frame = CGRectMake(0, -1,
self.feedTitleGradient.frame.size.width,
self.feedTitleGradient.frame.size.height);
if (!isNavBarHidden) {
[self.webView insertSubview:self.feedTitleGradient aboveSubview:self.webView.scrollView];
self.feedTitleGradient.frame = CGRectMake(0, -1,
self.feedTitleGradient.frame.size.width,
self.feedTitleGradient.frame.size.height);
}
for (id subview in self.webView.scrollView.subviews) {
UIImageView *imgView = [subview isKindOfClass:[UIImageView class]] ?
@ -1362,16 +1377,11 @@
int viewportHeight = self.view.frame.size.height;
int topPosition = self.webView.scrollView.contentOffset.y;
int safeBottomMargin = 0;
int minimumTopPositionWhenHidden = -1;
if (@available(iOS 11.0, *)) {
CGFloat bottomInset = appDelegate.storyPageControl.view.safeAreaInsets.bottom;
safeBottomMargin = -1 * bottomInset / 2;
if (bottomInset != 0) {
minimumTopPositionWhenHidden = 0;
}
}
int bottomPosition = webpageHeight - topPosition - viewportHeight;
@ -1384,16 +1394,6 @@
hasScrolled = YES;
}
BOOL isHorizontal = appDelegate.storyPageControl.isHorizontal;
BOOL isNavBarHidden = self.navigationController.navigationBarHidden;
// if (!isHorizontal && appDelegate.storyPageControl.previousPage.pageIndex < 0) {
// [appDelegate.storyPageControl setNavigationBarHidden:NO];
// } else if (isHorizontal && topPosition <= minimumTopPositionWhenHidden && isNavBarHidden) {
// [appDelegate.storyPageControl setNavigationBarHidden:NO];
// } else if (!isNavBarHidden && self.canHideNavigationBar) {
// [appDelegate.storyPageControl setNavigationBarHidden:YES];
// }
if (!isNavBarHidden && self.canHideNavigationBar && !nearTop && appDelegate.storyPageControl.autoscrollActive) {
[appDelegate.storyPageControl setNavigationBarHidden:YES];
}
@ -1417,28 +1417,18 @@
appDelegate.storyPageControl.traverseView.alpha = 1;
// NSLog(@" ---> Bottom position: %d", bottomPosition);
if (bottomPosition >= 0 || !isHorizontal) {
// appDelegate.storyPageControl.traverseView.frame = CGRectMake(tvf.origin.x,
// self.webView.scrollView.frame.size.height - tvf.size.height - safeBottomMargin,
// tvf.size.width, tvf.size.height);
appDelegate.storyPageControl.traverseBottomConstraint.constant = safeBottomMargin;
} else {
// appDelegate.storyPageControl.traverseView.frame = CGRectMake(tvf.origin.x,
// (webpageHeight - topPosition) - tvf.size.height - safeBottomMargin,
// tvf.size.width, tvf.size.height);
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)) {
// Pin to bottom of viewport, regardless of scrollview
appDelegate.storyPageControl.traversePinned = YES;
appDelegate.storyPageControl.traverseFloating = NO;
// appDelegate.storyPageControl.traverseView.frame = CGRectMake(tvf.origin.x,
// self.webView.scrollView.frame.size.height - tvf.size.height - safeBottomMargin,
// tvf.size.width, tvf.size.height);
[appDelegate.storyPageControl.view layoutIfNeeded];
appDelegate.storyPageControl.traverseBottomConstraint.constant = safeBottomMargin;
@ -1458,9 +1448,6 @@
[UIView animateWithDuration:.3 delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
// appDelegate.storyPageControl.traverseView.frame = CGRectMake(tvf.origin.x,
// (webpageHeight - topPosition) - tvf.size.height - safeBottomMargin,
// tvf.size.width, tvf.size.height);
[appDelegate.storyPageControl.view layoutIfNeeded];
} completion:^(BOOL finished) {
appDelegate.storyPageControl.traversePinned = NO;
@ -1471,9 +1458,6 @@
appDelegate.storyPageControl.traverseFloating = YES;
appDelegate.storyPageControl.traverseView.alpha = 1;
appDelegate.storyPageControl.traverseBottomConstraint.constant = viewportHeight - (webpageHeight - topPosition) + safeBottomMargin;
// appDelegate.storyPageControl.traverseView.frame = CGRectMake(tvf.origin.x,
// (webpageHeight - topPosition) - tvf.size.height - safeBottomMargin,
// tvf.size.width, tvf.size.height);
}
[self storeScrollPosition:YES];
@ -2236,7 +2220,22 @@
return [super canPerformAction:action withSender:sender];
}
# pragma mark
- (void)barHideSwipe:(UISwipeGestureRecognizer *)recognizer {
if (recognizer.state == UIGestureRecognizerStateEnded) {
self.isBarHideSwiping = NO;
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
BOOL shouldHideStatusBar = [preferences boolForKey:@"story_hide_status_bar"];
if (!shouldHideStatusBar) {
[self drawFeedGradient];
}
} else {
self.isBarHideSwiping = YES;
}
}
# pragma mark -
# pragma mark Subscribing to blurblog
- (void)subscribeToBlurblog {

View file

@ -97,6 +97,7 @@
- (void)resizeScrollView;
- (void)applyNewIndex:(NSInteger)newIndex pageController:(StoryDetailViewController *)pageController;
- (void)layoutForInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
- (void)updateStatusBarState;
- (void)setNavigationBarHidden:(BOOL)hide;
- (void)setNavigationBarHidden:(BOOL)hide alsoTraverse:(BOOL)alsoTraverse;
- (void)adjustDragBar:(UIInterfaceOrientation)orientation;

View file

@ -478,9 +478,7 @@
BOOL shouldHideStatusBar = [preferences boolForKey:@"story_hide_status_bar"];
BOOL isNavBarHidden = self.navigationController.navigationBarHidden;
self.statusBarBackgroundView.hidden = YES; shouldHideStatusBar || !isNavBarHidden || !appDelegate.isPortrait;
NSLog(@"⚠️ updateStatusBarState: %@", isNavBarHidden ? @"nav hidden" : @"nav shown"); // log
self.statusBarBackgroundView.hidden = shouldHideStatusBar || !isNavBarHidden || !appDelegate.isPortrait;
}
- (BOOL)prefersStatusBarHidden {
@ -1592,7 +1590,7 @@
self.statusBarBackgroundView = [[UIView alloc] initWithFrame:statusRect];
self.statusBarBackgroundView.backgroundColor = self.navigationController.navigationBar.barTintColor;
[self.view addSubview:self.statusBarBackgroundView];
[self.navigationController.view addSubview:self.statusBarBackgroundView];
self.statusBarBackgroundView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin;
[self updateStatusBarState];