From d0312a172548d04d6b5513ad6b4116b25151053c Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Wed, 19 Oct 2016 14:55:48 +0100 Subject: [PATCH] [Infra] Support toggling off `scrollsToTop` when a topMenuVC has become inactive in the tab system --- .../Util/ARBrowseViewController.m | 7 ++++++- Artsy/Views/Utilities/ARTabContentView.m | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Artsy/View_Controllers/Util/ARBrowseViewController.m b/Artsy/View_Controllers/Util/ARBrowseViewController.m index 689075165a3..6843a94d93d 100644 --- a/Artsy/View_Controllers/Util/ARBrowseViewController.m +++ b/Artsy/View_Controllers/Util/ARBrowseViewController.m @@ -29,7 +29,7 @@ - (void)setupTitleLabel ///////////////// -@interface ARBrowseViewController () +@interface ARBrowseViewController () @property (nonatomic, strong, readonly) NSArray *menuLinks; @end @@ -47,6 +47,11 @@ - (void)viewDidLoad [super viewDidLoad]; } +- (UIScrollView *)menuAwareScrollView +{ + return self.collectionView; +} + - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; diff --git a/Artsy/Views/Utilities/ARTabContentView.m b/Artsy/Views/Utilities/ARTabContentView.m index 3245ed5f9f4..95e7703709c 100644 --- a/Artsy/Views/Utilities/ARTabContentView.m +++ b/Artsy/Views/Utilities/ARTabContentView.m @@ -3,6 +3,7 @@ #import "ARDispatchManager.h" #import "ARNavigationController.h" #import "UIView+HitTestExpansion.h" +#import "ARMenuAwareViewController.h" #import @@ -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; } @@ -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; @@ -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); }