-
Notifications
You must be signed in to change notification settings - Fork 378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose a data-source-oriented API for PhotosViewController #226
Conversation
This makes using the photo viewer with a single photo _almost_ as simple as it was before.
This eliminates the bug where some delegate methods weren’t called for the first photo
@@ -1,20 +1,14 @@ | |||
// | |||
// NYTPhotosDataSource.m | |||
// NYTPhotoViewerArrayDataSource.m | |||
// NYTPhotoViewer | |||
// | |||
// Created by Brian Capps on 2/11/15. | |||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a copyright statement here. Not sure what the protocol is for open source.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The license (which was reviewed by the legal team a while back, I think) includes a copyright so I'll add one here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in db4ccb5
// NYTPhotoViewer | ||
// | ||
// Created by Brian Capps on 2/11/15. | ||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copyright?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in db4ccb5
Example/NYTViewController.m
Outdated
|
||
[self presentViewController:photosViewController animated:YES completion:nil]; | ||
|
||
[self updateImagesOnPhotosViewController:photosViewController afterDelayWithPhotos:self.photos]; | ||
[self updateImagesOnPhotosViewController:photosViewController afterDelayWithDataSource:self.dataSource]; | ||
// [self switchDataSourceOnPhotosViewController:photosViewController afterDelayWithDataSource:self.dataSource]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps provide a little explanation here. Is your intention that only one of these two lines be uncommented or should we simply uncomment line 41 to see the data source switch after a delay. It works both ways, but it would be nice to know your intention. Or maybe use an if statement to make it more clear:
BOOL switchDataSource = false
[self updateImagesOnPhotosViewController:photosViewController afterDelayWithDataSource:self.dataSource];
if (switchDataSource) {
[self switchDataSourceOnPhotosViewController:photosViewController afterDelayWithDataSource:self.dataSource];
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to demonstrate both the possibility of updating a single photo, and the possibility of completely changing out the data source.
The complete-data-source-change is surprising, though, if you're not expecting it. I wanted that to be optional.
I like the BOOL
suggestion and will implement it shortly.
Example/NYTViewController.m
Outdated
if (!photo.image && !photo.imageData) { | ||
photo.image = [UIImage imageNamed:@"NYTimesBuilding"]; | ||
[photosViewController updateImageForPhoto:photo]; | ||
photo.attributedCaptionSummary = [[NSAttributedString alloc] initWithString:@"Photo which previously had a loading spinner (reopen the photo viewer and scroll to here to see it)" attributes:@{NSForegroundColorAttributeName: [UIColor whiteColor], NSFontAttributeName: [UIFont preferredFontForTextStyle:UIFontTextStyleBody]}]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps change the caption to... "Photo which previously had a loading spinner (to see the spinner, reopen the photo viewer and scroll to this photo)"
Example/NYTViewController.m
Outdated
@@ -140,24 +107,24 @@ - (UIView *)photosViewController:(NYTPhotosViewController *)photosViewController | |||
} | |||
|
|||
- (CGFloat)photosViewController:(NYTPhotosViewController *)photosViewController maximumZoomScaleForPhoto:(id <NYTPhoto>)photo { | |||
if ([photo isEqual:self.photos[NYTViewControllerPhotoIndexCustomMaxZoomScale]]) { | |||
if ([photo isEqual:self.dataSource.photos[NYTViewControllerPhotoIndexCustomMaxZoomScale]]) { | |||
return 10.0f; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps change the custom scale to 0.5f because 10.0f is hard to tell that it is different when you zoom because the original image is so large to begin with. Using 0.5f it is clear that the scaling is different.
*/ | ||
- (instancetype)initWithPhotos:(NSArray <id <NYTPhoto>> * _Nullable)photos initialPhoto:(id <NYTPhoto> _Nullable)initialPhoto delegate:(nullable id <NYTPhotosViewControllerDelegate>)delegate NS_DESIGNATED_INITIALIZER; | ||
- (instancetype)initWithDataSource:(id <NYTPhotoViewerDataSource>)dataSource initialPhoto:(id <NYTPhoto> _Nullable)initialPhoto delegate:(nullable id <NYTPhotosViewControllerDelegate>)delegate NS_DESIGNATED_INITIALIZER; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't _Nullable and nullable equivalent? Is there a reason not to be consistent? I guess this was already here but it might be nice to make the usage consistent and settle on one style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes, they are. Good catch. I think the initial code was written before nullable
was added, and only _Nullable
was available. Then I just blindly copied it here when adding this declaration.
The swift example does not compile because of "Use Legacy Swift Language Version (SWIFT_VERSION) is required to be configured correctly for targets which use Swift." Not sure if this is covered by another issue to bring it update to date. |
@cdzombak Looks good! Just a few fairly minor comments. Let me know when you've addressed these (or not) and I'll give it a final review. |
#223 would update the project to Swift 3 (though after that, the Swift project will need to be updated with the API changes in this PR). |
@craighowarth I believe I've addressed each of your comments. |
👍 |
The current NYTPhotoViewer API accepts a collection of photos and creates an internal, mutable data source. Clients may call one method to update a photo currently in the data source. This comes with some problems and complexity, most notably: It's not possible to add or remove photos, and adding imperative add/remove/reorder photo API would further increase complexity of
PhotosViewController
, which probably shouldn't be responsible for managing a collection of data. (see #139 #140 #141).Future improvements could include separating data source requests for caption and photo data, should we decide that would be helpful.
This should also make #162 easier (or maybe it's now possible?).
I've also fixed the problematic behavior where delegate methods were never called for the first photo.
closes #163
closes #214