Skip to content

Commit

Permalink
#1350 (fullscreen vertical scrolling) & #1338 (fullscreen improvements)
Browse files Browse the repository at this point in the history
- Several changes to improve the fullscreen experience, especially in vertical paging mode.
  • Loading branch information
Dejal committed Jul 31, 2020
1 parent 4df24a0 commit 9aaa39f
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 54 deletions.
46 changes: 10 additions & 36 deletions clients/ios/Classes/StoryDetailViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
@interface StoryDetailViewController ()

@property (nonatomic, strong) NSString *fullStoryHTML;
@property (nonatomic) BOOL isBarHideSwiping;

@end

Expand Down Expand Up @@ -297,8 +296,6 @@ - (void)viewDidUnload {
- (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 &&
Expand All @@ -320,8 +317,6 @@ - (void)viewWillDisappear:(BOOL)animated {
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

[self.navigationController.barHideOnSwipeGestureRecognizer addTarget:self action:@selector(barHideSwipe:)];

if (!self.isPhoneOrCompact) {
[appDelegate.feedDetailViewController.view endEditing:YES];
}
Expand Down Expand Up @@ -628,23 +623,17 @@ - (void)drawStory:(BOOL)force withOrientation:(UIInterfaceOrientation)orientatio
}

- (void)drawFeedGradient {
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
BOOL navigationBarHidden = self.navigationController.navigationBarHidden;
BOOL shouldHideStatusBar = [preferences boolForKey:@"story_hide_status_bar"];
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
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;
BOOL shouldHideStatusBar = appDelegate.storyPageControl.shouldHideStatusBar;
CGFloat yOffset = -1;
NSString *feedIdStr = [NSString stringWithFormat:@"%@",
[self.activeStory
objectForKey:@"story_feed_id"]];
NSDictionary *feed = [appDelegate getFeed:feedIdStr];

if (appDelegate.storyPageControl.currentlyTogglingNavigationBar && !appDelegate.storyPageControl.isNavigationBarHidden) {
yOffset -= 25;
}

if (self.feedTitleGradient) {
[self.feedTitleGradient removeFromSuperview];
self.feedTitleGradient = nil;
Expand Down Expand Up @@ -673,11 +662,11 @@ - (void)drawFeedGradient {
[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) {
feedTitleGradient.alpha = self.navigationController.navigationBarHidden ? 1 : 0;
if (appDelegate.storyPageControl.view.safeAreaInsets.top > 0.0 && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && shouldHideStatusBar) {
feedTitleGradient.alpha = appDelegate.storyPageControl.isNavigationBarHidden ? 1 : 0;

[UIView animateWithDuration:0.3 animations:^{
feedTitleGradient.alpha = self.navigationController.navigationBarHidden ? 0 : 1;
feedTitleGradient.alpha = appDelegate.storyPageControl.isNavigationBarHidden ? 0 : 1;
}];
}
}
Expand Down Expand Up @@ -1339,7 +1328,7 @@ - (NSString *)getReplies:(NSArray *)replies forUserId:(NSString *)commentUserId
- (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;
BOOL isNavBarHidden = appDelegate.storyPageControl.isNavigationBarHidden;

if (self.webView.scrollView.contentOffset.y < (-1 * self.feedTitleGradient.frame.size.height + 1 + self.webView.scrollView.scrollIndicatorInsets.top)) {
// Pulling
Expand Down Expand Up @@ -2237,21 +2226,6 @@ - (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
return [super canPerformAction:action withSender:sender];
}

- (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

Expand Down
3 changes: 3 additions & 0 deletions clients/ios/Classes/StoryPageControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
@property (nonatomic) StoryDetailViewController *previousPage;
@property (nonatomic, strong) IBOutlet UIScrollView *scrollView;
@property (nonatomic, strong) IBOutlet UIPageControl *pageControl;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *scrollViewTopConstraint;

@property (weak, nonatomic) IBOutlet UIView *autoscrollView;
@property (weak, nonatomic) IBOutlet UIImageView *autoscrollBackgroundImageView;
Expand Down Expand Up @@ -88,6 +89,8 @@
@property (nonatomic, strong) NBNotifier *notifier;
@property (nonatomic) NSInteger scrollingToPage;
@property (nonatomic, strong) id standardInteractivePopGestureDelegate;
@property (nonatomic, readonly) BOOL shouldHideStatusBar;
@property (nonatomic, readonly) BOOL isNavigationBarHidden;
@property (nonatomic, readonly) BOOL allowFullscreen;
@property (nonatomic) BOOL forceNavigationBarShown;
@property (nonatomic) BOOL currentlyTogglingNavigationBar;
Expand Down
60 changes: 49 additions & 11 deletions clients/ios/Classes/StoryPageControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
@interface StoryPageControl ()

@property (nonatomic) CGFloat statusBarHeight;
@property (nonatomic) BOOL wasNavigationBarHidden;
@property (nonatomic, strong) NSTimer *autoscrollTimer;
@property (nonatomic, strong) NSTimer *autoscrollViewTimer;
@property (nonatomic, strong) NSString *restoringStoryId;
Expand Down Expand Up @@ -284,6 +285,8 @@ - (void)viewWillAppear:(BOOL)animated {
BOOL swipeEnabled = [[userPreferences stringForKey:@"story_detail_swipe_left_edge"]
isEqualToString:@"pop_to_story_list"];;
self.navigationController.hidesBarsOnSwipe = self.allowFullscreen;
[self.navigationController.barHideOnSwipeGestureRecognizer addTarget:self action:@selector(barHideSwipe:)];

self.navigationController.interactivePopGestureRecognizer.enabled = swipeEnabled;
self.navigationController.interactivePopGestureRecognizer.delegate = self;

Expand Down Expand Up @@ -398,6 +401,8 @@ - (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];

self.navigationItem.leftBarButtonItem = nil;

[self.navigationController.barHideOnSwipeGestureRecognizer removeTarget:self action:@selector(barHideSwipe:)];
}

- (void)viewWillDisappear:(BOOL)animated {
Expand Down Expand Up @@ -468,27 +473,38 @@ - (void)layoutForInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientati

- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];

if (self.isNavigationBarHidden && !self.shouldHideStatusBar) {
self.scrollViewTopConstraint.constant = self.statusBarHeight;
} else {
self.scrollViewTopConstraint.constant = 0;
}

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
[self layoutForInterfaceOrientation:orientation];
[self adjustDragBar:orientation];
}

- (void)updateStatusBarState {
- (BOOL)shouldHideStatusBar {
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
BOOL shouldHideStatusBar = [preferences boolForKey:@"story_hide_status_bar"];
BOOL isNavBarHidden = self.navigationController.navigationBarHidden;

self.statusBarBackgroundView.hidden = shouldHideStatusBar || !isNavBarHidden || !appDelegate.isPortrait;
return [preferences boolForKey:@"story_hide_status_bar"];
}

- (BOOL)prefersStatusBarHidden {
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
BOOL shouldHideStatusBar = [preferences boolForKey:@"story_hide_status_bar"];
BOOL isNavBarHidden = self.navigationController.navigationBarHidden;
- (BOOL)isNavigationBarHidden {
return self.navigationController.navigationBarHidden;
}

- (void)updateStatusBarState {
BOOL isNavBarHidden = self.isNavigationBarHidden;

self.statusBarBackgroundView.hidden = self.shouldHideStatusBar || !isNavBarHidden || !appDelegate.isPortrait;
}

- (BOOL)prefersStatusBarHidden {
[self updateStatusBarState];

return shouldHideStatusBar && isNavBarHidden;
return self.shouldHideStatusBar && self.isNavigationBarHidden;
}

- (BOOL)allowFullscreen {
Expand All @@ -511,6 +527,7 @@ - (void)setNavigationBarHidden:(BOOL)hide alsoTraverse:(BOOL)alsoTraverse {
}

self.currentlyTogglingNavigationBar = YES;
self.wasNavigationBarHidden = hide;

[self.navigationController setNavigationBarHidden:hide animated:YES];

Expand Down Expand Up @@ -640,6 +657,22 @@ - (BOOL)isHorizontal {
return [[[NSUserDefaults standardUserDefaults] objectForKey:@"scroll_stories_horizontally"] boolValue];
}

- (void)barHideSwipe:(UIPanGestureRecognizer *)recognizer {
BOOL isBarHidden = self.isNavigationBarHidden;

if (recognizer.state == UIGestureRecognizerStateEnded && isBarHidden != self.wasNavigationBarHidden) {
self.wasNavigationBarHidden = isBarHidden;

if (!appDelegate.storyPageControl.shouldHideStatusBar) {
[currentPage drawFeedGradient];
}

if (!self.isHorizontal) {
[self reorientPages];
}
}
}

- (void)resetPages {
self.navigationItem.titleView = nil;

Expand Down Expand Up @@ -890,6 +923,11 @@ - (void)applyNewIndex:(NSInteger)newIndex
}
pageFrame.size.height = CGRectGetHeight(self.scrollView.bounds);
pageFrame.size.width = CGRectGetWidth(self.scrollView.bounds);

if (self.currentlyTogglingNavigationBar && !self.isNavigationBarHidden) {
pageFrame.size.height -= 20.0;
}

pageController.view.hidden = NO;
pageController.view.frame = pageFrame;
} else {
Expand Down Expand Up @@ -1697,8 +1735,8 @@ - (void)autoscroll:(NSTimer *)timer {
- (void)tappedStory {
if (self.autoscrollAvailable) {
[self showAutoscrollBriefly:YES];
} else {
[self setNavigationBarHidden: !self.navigationController.navigationBarHidden];
} else if (self.allowFullscreen) {
[self setNavigationBarHidden: !self.isNavigationBarHidden];
}
}

Expand Down
5 changes: 3 additions & 2 deletions clients/ios/Classes/StoryPageControl.xib
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="15705" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16097.2" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina5_9" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15706"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand All @@ -28,6 +28,7 @@
<outlet property="prevNextBackgroundImageView" destination="71" id="S3e-tC-Pbu"/>
<outlet property="scrollBottomConstraint" destination="AOS-qV-fjZ" id="JD4-zE-OTv"/>
<outlet property="scrollView" destination="5" id="15"/>
<outlet property="scrollViewTopConstraint" destination="sgh-qa-2V3" id="Z8v-Gi-IqF"/>
<outlet property="textStorySendBackgroundImageView" destination="80" id="1hz-Zr-85e"/>
<outlet property="traverseBottomConstraint" destination="rgF-mh-lia" id="ucW-KZ-fN6"/>
<outlet property="traverseView" destination="75" id="76"/>
Expand Down
2 changes: 1 addition & 1 deletion clients/ios/NewsBlur.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2799,7 +2799,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1120;
LastUpgradeCheck = 1150;
LastUpgradeCheck = 1160;
ORGANIZATIONNAME = NewsBlur;
TargetAttributes = {
1749390F1C251BFE003D98AA = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1150"
LastUpgradeVersion = "1160"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1150"
LastUpgradeVersion = "1160"
wasCreatedForAppExtension = "YES"
version = "2.0">
<BuildAction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1150"
LastUpgradeVersion = "1160"
wasCreatedForAppExtension = "YES"
version = "2.0">
<BuildAction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1150"
LastUpgradeVersion = "1160"
wasCreatedForAppExtension = "YES"
version = "1.3">
<BuildAction
Expand Down

0 comments on commit 9aaa39f

Please sign in to comment.