Skip to content

Commit

Permalink
Merge pull request #1941 from artsy/orta-scrolls_to_top
Browse files Browse the repository at this point in the history
Use the ARTopMenuViewController to turn on/off scrolls to top on views
  • Loading branch information
alloy committed Oct 19, 2016
2 parents 90cf0e1 + d0312a1 commit 6faa7fd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 6 additions & 1 deletion Artsy/View_Controllers/Util/ARBrowseViewController.m
Expand Up @@ -29,7 +29,7 @@ - (void)setupTitleLabel
/////////////////


@interface ARBrowseViewController () <UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>
@interface ARBrowseViewController () <UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, ARMenuAwareViewController>
@property (nonatomic, strong, readonly) NSArray *menuLinks;
@end

Expand All @@ -47,6 +47,11 @@ - (void)viewDidLoad
[super viewDidLoad];
}

- (UIScrollView *)menuAwareScrollView
{
return self.collectionView;
}

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
Expand Down
15 changes: 13 additions & 2 deletions Artsy/Views/Utilities/ARTabContentView.m
Expand Up @@ -3,6 +3,7 @@
#import "ARDispatchManager.h"
#import "ARNavigationController.h"
#import "UIView+HitTestExpansion.h"
#import "ARMenuAwareViewController.h"

#import <ObjectiveSugar/ObjectiveSugar.h>

Expand Down Expand Up @@ -143,7 +144,7 @@ - (void)forceSetCurrentViewIndex:(NSInteger)index animated:(BOOL)animated
BOOL isARNavigationController = [self.currentNavigationController isKindOfClass:ARNavigationController.class];

// If selecting search button, toggle search VC
if ([self.dataSource searchButtonAtIndex:index] && isARNavigationController) {
if (isARNavigationController && [self.dataSource searchButtonAtIndex:index]) {
[(ARNavigationController *)self.currentNavigationController toggleSearch];
return;
}
Expand All @@ -168,10 +169,15 @@ - (void)forceSetCurrentViewIndex:(NSInteger)index animated:(BOOL)animated
nextViewInitialFrame.origin.x = direction * CGRectGetWidth(self.superview.bounds);
oldViewEndFrame.origin.x = -direction * CGRectGetWidth(self.superview.bounds);

__block UIViewController *oldViewController = self.currentNavigationController;
__block UINavigationController *oldViewController = self.currentNavigationController;
_previousViewIndex = self.currentViewIndex;
_currentViewIndex = index;

// Ensure there is only one scrollview that has `scrollsToTop`
if (isARNavigationController && [oldViewController.topViewController conformsToProtocol:@protocol(ARMenuAwareViewController)]) {
[(id)oldViewController.topViewController menuAwareScrollView].scrollsToTop = NO;
}

// Get the next View Controller, add to self
_currentNavigationController = [self navigationControllerForIndex:index];
self.currentNavigationController.view.frame = nextViewInitialFrame;
Expand Down Expand Up @@ -206,6 +212,11 @@ - (void)forceSetCurrentViewIndex:(NSInteger)index animated:(BOOL)animated
[self addSubview:self.currentNavigationController.view];
[self.currentNavigationController endAppearanceTransition];

// Ensure there is only one scrollview that has `scrollsToTop`
if (isARNavigationController && [self.currentNavigationController.topViewController conformsToProtocol:@protocol(ARMenuAwareViewController)]) {
[(id)self.currentNavigationController.topViewController menuAwareScrollView].scrollsToTop = YES;
}

animationBlock();
completionBlock(YES);
}
Expand Down

0 comments on commit 6faa7fd

Please sign in to comment.