diff --git a/FRP/FRPGalleryViewController.m b/FRP/FRPGalleryViewController.m index 32bdfaa..0644ada 100644 --- a/FRP/FRPGalleryViewController.m +++ b/FRP/FRPGalleryViewController.m @@ -16,10 +16,11 @@ // Utilities #import "FRPGalleryFlowLayout.h" #import "FRPPhotoImporter.h" +#import static NSString *CellIdentifier = @"Cell"; -@interface FRPGalleryViewController () +@interface FRPGalleryViewController () @property (nonatomic, strong) NSArray *photosArray; @@ -55,6 +56,22 @@ static NSString *CellIdentifier = @"Cell"; [self.collectionView reloadData]; }]; + RACDelegateProxy *viewControllerDelegate = [[RACDelegateProxy alloc] initWithProtocol:@protocol(FRPFullSizePhotoViewControllerDelegate)]; + + [[viewControllerDelegate rac_signalForSelector:@selector(userDidScroll:toPhotoAtIndex:) fromProtocol:@protocol(FRPFullSizePhotoViewControllerDelegate)] subscribeNext:^(RACTuple *value) { + @strongify(self); + [self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:[value.second integerValue] inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:NO]; + }]; + + RACDelegateProxy *collectionViewDelegate = [[RACDelegateProxy alloc] initWithProtocol:@protocol(UICollectionViewDelegate)]; + [[collectionViewDelegate rac_signalForSelector:@selector(collectionView:didSelectItemAtIndexPath:)] subscribeNext:^(RACTuple *arguments) { + @strongify(self); + FRPFullSizePhotoViewController *viewController = [[FRPFullSizePhotoViewController alloc] initWithPhotoModels:self.photosArray currentPhotoIndex:[(NSIndexPath *)arguments.second item]]; + viewController.delegate = (id)viewControllerDelegate; + [self.navigationController pushViewController:viewController animated:YES]; + }]; + self.collectionView.delegate = (id)collectionViewDelegate; + // Load data [self loadPopularPhotos]; } @@ -83,19 +100,5 @@ static NSString *CellIdentifier = @"Cell"; return cell; } -#pragma mark - UICollectionViewDelegate Methods - -// Note: Can't use rac_signalForSelector: here w/o implementing this method. --(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { - FRPFullSizePhotoViewController *viewController = [[FRPFullSizePhotoViewController alloc] initWithPhotoModels:self.photosArray currentPhotoIndex:indexPath.item]; - viewController.delegate = self; - [self.navigationController pushViewController:viewController animated:YES]; -} - -#pragma mark - FRPFullSizePhotoViewControllerDelegate Methods - --(void)userDidScroll:(FRPFullSizePhotoViewController *)viewController toPhotoAtIndex:(NSInteger)index { - [self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:index inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:NO]; -} @end diff --git a/Podfile b/Podfile index e396e78..a82a40d 100644 --- a/Podfile +++ b/Podfile @@ -2,7 +2,7 @@ platform :ios, "7.0" target "FRP" do -pod 'ReactiveCocoa', '2.1' +pod 'ReactiveCocoa', '2.1.3' pod 'libextobjc', '0.3' pod '500px-iOS-api', '1.0.4' pod 'SVProgressHUD', '0.9' diff --git a/Podfile.lock b/Podfile.lock index b59566e..5027f34 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -85,25 +85,25 @@ PODS: - libextobjc/RuntimeExtensions (0.3) - libextobjc/UmbrellaHeader (0.3) - libffi (3.0.13) - - ReactiveCocoa (2.1): + - ReactiveCocoa (2.1.3): - ReactiveCocoa/Core - ReactiveCocoa/no-arc - - ReactiveCocoa/Core (2.1): + - ReactiveCocoa/Core (2.1.3): - ReactiveCocoa/no-arc - - ReactiveCocoa/no-arc (2.1) + - ReactiveCocoa/no-arc (2.1.3) - SVProgressHUD (0.9) DEPENDENCIES: - 500px-iOS-api (= 1.0.4) - libextobjc (= 0.3) - - ReactiveCocoa (= 2.1) + - ReactiveCocoa (= 2.1.3) - SVProgressHUD (= 0.9) SPEC CHECKSUMS: 500px-iOS-api: fde71ddd4a05f06b94b8ec7c29bbcd2e589b7e70 libextobjc: 820a79dbbbc498611e04fffd07d2d52a5588e7ac libffi: 64ef39353e747bb2b25e1026afd96a157bf9231c - ReactiveCocoa: b686fa735c28c2dc7311fbd2f0895b4d4ae07360 + ReactiveCocoa: 0142b823f4737effe6100f9fbb0a43bdcb629aae SVProgressHUD: 03d4845ec8e64591726428a08236c6a5489d45f8 COCOAPODS: 0.26.2