Bgerstle has uploaded a new change for review. https://gerrit.wikimedia.org/r/197268
Change subject: implement RTL support for gallery ...................................................................... implement RTL support for gallery - Flip gallery images (swipe to the left to progress) - Text & close button flip to the right Bug: T91313 Change-Id: Ice8c14e2f1c87bd64c66e4b2ccc959c2380ab522 --- M Wikipedia.xcodeproj/project.pbxproj A wikipedia/Categories/NSParagraphStyle+WMFNaturalAlignmentStyle.h A wikipedia/Categories/NSParagraphStyle+WMFNaturalAlignmentStyle.m M wikipedia/View Controllers/Image Gallery/WMFImageGalleryCollectionViewCell.m M wikipedia/View Controllers/Image Gallery/WMFImageGalleryDetailOverlayView.h M wikipedia/View Controllers/Image Gallery/WMFImageGalleryDetailOverlayView.m M wikipedia/View Controllers/Image Gallery/WMFImageGalleryDetailOverlayView.xib M wikipedia/View Controllers/Image Gallery/WMFImageGalleryViewController.h M wikipedia/View Controllers/Image Gallery/WMFImageGalleryViewController.m M wikipedia/View Controllers/WebView/WebViewController+ImageGalleryPresentation.m 10 files changed, 188 insertions(+), 86 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/ios/wikipedia refs/changes/68/197268/1 diff --git a/Wikipedia.xcodeproj/project.pbxproj b/Wikipedia.xcodeproj/project.pbxproj index e35b6ba..1a989ca 100644 --- a/Wikipedia.xcodeproj/project.pbxproj +++ b/Wikipedia.xcodeproj/project.pbxproj @@ -231,6 +231,7 @@ BC0FED751AAA026C002488D7 /* NSArray+BKIndexTests.m in Sources */ = {isa = PBXBuildFile; fileRef = BCB58F7B1A8D0C8E00465627 /* NSArray+BKIndexTests.m */; }; BC0FED761AAA026C002488D7 /* NSString+WMFHTMLParsingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C983151B1AA5205700E25EE1 /* NSString+WMFHTMLParsingTests.m */; }; BC0FED771AAA026C002488D7 /* WMFImageURLParsingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = BCBDE0AB1AA76EAC006BD29A /* WMFImageURLParsingTests.m */; }; + BC23759A1AB78D8A00B0BAA8 /* NSParagraphStyle+WMFNaturalAlignmentStyle.m in Sources */ = {isa = PBXBuildFile; fileRef = BC2375991AB78D8A00B0BAA8 /* NSParagraphStyle+WMFNaturalAlignmentStyle.m */; }; BC2CBB8E1AA10F400079A313 /* UIView+WMFFrameUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = BC2CBB8D1AA10F400079A313 /* UIView+WMFFrameUtils.m */; }; BC50C37F1A83C784006DC7AF /* WMFNetworkUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = BC50C37E1A83C784006DC7AF /* WMFNetworkUtilities.m */; }; BC50C3871A83CBDA006DC7AF /* MWKImageInfoResponseSerializer.m in Sources */ = {isa = PBXBuildFile; fileRef = BC50C3861A83CBDA006DC7AF /* MWKImageInfoResponseSerializer.m */; }; @@ -721,6 +722,8 @@ 17A2F22335C5256576CEDBDD /* Pods-WikipediaUnitTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WikipediaUnitTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-WikipediaUnitTests/Pods-WikipediaUnitTests.release.xcconfig"; sourceTree = "<group>"; }; 357504E50DA104E39C6ACFEB /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = "<group>"; }; 8CE61C6963F825760822A28A /* libPods-WikipediaUnitTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-WikipediaUnitTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + BC2375981AB78D8A00B0BAA8 /* NSParagraphStyle+WMFNaturalAlignmentStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSParagraphStyle+WMFNaturalAlignmentStyle.h"; sourceTree = "<group>"; }; + BC2375991AB78D8A00B0BAA8 /* NSParagraphStyle+WMFNaturalAlignmentStyle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSParagraphStyle+WMFNaturalAlignmentStyle.m"; sourceTree = "<group>"; }; BC2CBB8C1AA10F400079A313 /* UIView+WMFFrameUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+WMFFrameUtils.h"; sourceTree = "<group>"; }; BC2CBB8D1AA10F400079A313 /* UIView+WMFFrameUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+WMFFrameUtils.m"; sourceTree = "<group>"; }; BC4273521A7C736800068882 /* WikipediaUnitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = WikipediaUnitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -1815,6 +1818,8 @@ 0EA4402D1AA6281200B09DBA /* NSDateFormatter+WMFExtensions.m */, BCA96E751AAA35EE009A61FA /* UIView+WMFDefaultNib.h */, BCA96E761AAA35EE009A61FA /* UIView+WMFDefaultNib.m */, + BC2375981AB78D8A00B0BAA8 /* NSParagraphStyle+WMFNaturalAlignmentStyle.h */, + BC2375991AB78D8A00B0BAA8 /* NSParagraphStyle+WMFNaturalAlignmentStyle.m */, ); path = Categories; sourceTree = "<group>"; @@ -2918,6 +2923,7 @@ 040892641935ABBD004CF254 /* UIViewController+StatusBarHeight.m in Sources */, 04142A8F184F974E006EF779 /* NSDate-Utilities.m in Sources */, 0487048C19F8262600B7D307 /* SearchResultFetcher.m in Sources */, + BC23759A1AB78D8A00B0BAA8 /* NSParagraphStyle+WMFNaturalAlignmentStyle.m in Sources */, 04090A3B187FB7D000577EDF /* UIView+Debugging.m in Sources */, BCC185D81A9E5628005378F8 /* UILabel+WMFStyling.m in Sources */, BCB669B11A83F6C400C7B1FE /* MWKRecentSearchList.m in Sources */, diff --git a/wikipedia/Categories/NSParagraphStyle+WMFNaturalAlignmentStyle.h b/wikipedia/Categories/NSParagraphStyle+WMFNaturalAlignmentStyle.h new file mode 100644 index 0000000..c92d4d1 --- /dev/null +++ b/wikipedia/Categories/NSParagraphStyle+WMFNaturalAlignmentStyle.h @@ -0,0 +1,16 @@ +// +// NSParagraphStyle+WMFNaturalAlignmentStyle.h +// Wikipedia +// +// Created by Brian Gerstle on 3/16/15. +// Copyright (c) 2015 Wikimedia Foundation. All rights reserved. +// + +#import <UIKit/UIKit.h> + +@interface NSParagraphStyle (WMFNaturalAlignmentStyle) + +/// Provides a backwards-compatible way to have "natural" text alignment of labels & buttons. ++ (NSParagraphStyle*)wmf_naturalAlignmentStyle; + +@end diff --git a/wikipedia/Categories/NSParagraphStyle+WMFNaturalAlignmentStyle.m b/wikipedia/Categories/NSParagraphStyle+WMFNaturalAlignmentStyle.m new file mode 100644 index 0000000..7e5c325 --- /dev/null +++ b/wikipedia/Categories/NSParagraphStyle+WMFNaturalAlignmentStyle.m @@ -0,0 +1,24 @@ +// +// NSParagraphStyle+WMFNaturalAlignmentStyle.m +// Wikipedia +// +// Created by Brian Gerstle on 3/16/15. +// Copyright (c) 2015 Wikimedia Foundation. All rights reserved. +// + +#import "NSParagraphStyle+WMFNaturalAlignmentStyle.h" + +@implementation NSParagraphStyle (WMFNaturalAlignmentStyle) + ++ (NSParagraphStyle*)wmf_naturalAlignmentStyle { + NSParameterAssert([NSThread isMainThread]); + static NSParagraphStyle* naturalAlignmentStyle = nil; + if (!naturalAlignmentStyle) { + NSMutableParagraphStyle* style = [NSMutableParagraphStyle new]; + style.alignment = NSTextAlignmentNatural; + naturalAlignmentStyle = [style copy]; + } + return naturalAlignmentStyle; +} + +@end diff --git a/wikipedia/View Controllers/Image Gallery/WMFImageGalleryCollectionViewCell.m b/wikipedia/View Controllers/Image Gallery/WMFImageGalleryCollectionViewCell.m index d909419..2f424b1 100644 --- a/wikipedia/View Controllers/Image Gallery/WMFImageGalleryCollectionViewCell.m +++ b/wikipedia/View Controllers/Image Gallery/WMFImageGalleryCollectionViewCell.m @@ -50,9 +50,7 @@ _imageContainerView = imageContainerView; UIImageView* imageView = [[UIImageView alloc] init]; - // images that are transparent should have a white background, as most use black text (e.g. formulas & graphs) - imageView.backgroundColor = [UIColor whiteColor]; - imageView.contentMode = UIViewContentModeScaleAspectFit; + imageView.contentMode = UIViewContentModeScaleAspectFit; [self.imageContainerView addSubview:imageView]; _imageView = imageView; @@ -91,8 +89,8 @@ - (void)prepareForReuse { [super prepareForReuse]; - self.detailOverlayView.imageDescriptionLabel.text = nil; - [self.detailOverlayView.ownerButton setAttributedTitle:nil forState:UIControlStateNormal]; + [self.detailOverlayView setImageDescription:nil]; + [self.detailOverlayView setLicense:nil owner:nil]; self.gradientView.hidden = NO; self.detailOverlayView.hidden = NO; self.detailOverlayView.ownerTapCallback = nil; @@ -206,6 +204,8 @@ return; } self.imageView.image = image; + // background color is set here to prevent "white flashes" while setting image + self.imageView.backgroundColor = image ? [UIColor whiteColor] : [UIColor clearColor]; [self setNeedsLayout]; } diff --git a/wikipedia/View Controllers/Image Gallery/WMFImageGalleryDetailOverlayView.h b/wikipedia/View Controllers/Image Gallery/WMFImageGalleryDetailOverlayView.h index e1a0ae5..69ca1bb 100644 --- a/wikipedia/View Controllers/Image Gallery/WMFImageGalleryDetailOverlayView.h +++ b/wikipedia/View Controllers/Image Gallery/WMFImageGalleryDetailOverlayView.h @@ -7,13 +7,17 @@ // #import <UIKit/UIKit.h> +#import "MWKLicense.h" @interface WMFImageGalleryDetailOverlayView : UIView - +@property (nonatomic, copy) NSString* imageDescription; @property (nonatomic, copy) dispatch_block_t ownerTapCallback; -- (UILabel*) imageDescriptionLabel; -- (UIButton*)ownerButton; +// use above setters instead of setting title/text attributes directly +@property (nonatomic, weak, readonly) UILabel* imageDescriptionLabel; +@property (nonatomic, weak, readonly) UIButton* ownerButton; + +- (void)setLicense:(MWKLicense*)license owner:(NSString*)owner; /// Set all child view alphas to @c alpha. This is preferred to hiding & showing them. - (void)setGroupAlpha:(float)alpha; diff --git a/wikipedia/View Controllers/Image Gallery/WMFImageGalleryDetailOverlayView.m b/wikipedia/View Controllers/Image Gallery/WMFImageGalleryDetailOverlayView.m index ad1f0ed..63346cc 100644 --- a/wikipedia/View Controllers/Image Gallery/WMFImageGalleryDetailOverlayView.m +++ b/wikipedia/View Controllers/Image Gallery/WMFImageGalleryDetailOverlayView.m @@ -11,6 +11,12 @@ #import "UIFont+WMFStyle.h" #import "WikiGlyph_Chars.h" #import "UILabel+WMFStyling.h" +#import "MWKLicense+ToGlyph.h" +#import "NSParagraphStyle+WMFNaturalAlignmentStyle.h" + +static double const WMFImageGalleryLicenseFontSize = 19.0; +static double const WMFImageGalleryLicenseBaselineOffset = -1.5; +static double const WMFImageGalleryOwnerFontSize = 11.f; @interface WMFImageGalleryDetailOverlayView () @property (nonatomic, weak) IBOutlet UILabel* imageDescriptionLabel; @@ -19,6 +25,39 @@ - (IBAction)didTapOwnerButton; @end + + +static NSAttributedString* ConcatOwnerAndLicense(NSString* owner, MWKLicense* license){ + if (!owner && !license) { + return nil; + } + NSMutableAttributedString* result = [NSMutableAttributedString new]; + NSString* licenseGlyph = [license toGlyph] ? : WIKIGLYPH_CITE; + if (licenseGlyph) { + // hand-tuning glyph size & baseline offset until all glyphs are positioned & padded in a uniform way + [result appendAttributedString: + [[NSAttributedString alloc] + initWithString:licenseGlyph + attributes:@{NSFontAttributeName: [UIFont wmf_glyphFontOfSize:WMFImageGalleryLicenseFontSize], + NSForegroundColorAttributeName: [UIColor whiteColor], + NSBaselineOffsetAttributeName: @(WMFImageGalleryLicenseBaselineOffset)}]]; + } + + + NSAttributedString* attributedOwnerAndSeparator = + [[NSAttributedString alloc] + initWithString:[@" " stringByAppendingString:owner] + attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:WMFImageGalleryOwnerFontSize], + NSForegroundColorAttributeName: [UIColor whiteColor]}]; + + [result appendAttributedString:attributedOwnerAndSeparator]; + + [result addAttribute:NSParagraphStyleAttributeName + value:[NSParagraphStyle wmf_naturalAlignmentStyle] + range:NSMakeRange(0, result.length)]; + + return result; +} @implementation WMFImageGalleryDetailOverlayView @@ -46,10 +85,24 @@ self.ownerButton.alpha = alpha; } -- (void)setGroupHidden:(BOOL)hidden { - self.hidden = hidden; - self.imageDescriptionLabel.hidden = hidden; - self.ownerButton.hidden = hidden; +- (NSString*)imageDescription { + return self.imageDescriptionLabel.attributedText.string; +} + +- (void)setImageDescription:(NSString*)imageDescription { + if (!imageDescription) { + self.imageDescriptionLabel.attributedText = nil; + } else { + self.imageDescriptionLabel.attributedText = + [[NSAttributedString alloc] initWithString:imageDescription + attributes:@{ + NSParagraphStyleAttributeName: [NSParagraphStyle wmf_naturalAlignmentStyle] + }]; + } +} + +- (void)setLicense:(MWKLicense*)license owner:(NSString*)owner { + [self.ownerButton setAttributedTitle:ConcatOwnerAndLicense(owner, license) forState:UIControlStateNormal]; } @end diff --git a/wikipedia/View Controllers/Image Gallery/WMFImageGalleryDetailOverlayView.xib b/wikipedia/View Controllers/Image Gallery/WMFImageGalleryDetailOverlayView.xib index fab6aa7..90d3706 100644 --- a/wikipedia/View Controllers/Image Gallery/WMFImageGalleryDetailOverlayView.xib +++ b/wikipedia/View Controllers/Image Gallery/WMFImageGalleryDetailOverlayView.xib @@ -1,8 +1,8 @@ <?xml version="1.0" encoding="UTF-8" standalone="no"?> -<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6254" systemVersion="14C109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES"> +<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6751" systemVersion="14C1510" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES"> <dependencies> <deployment identifier="iOS"/> - <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/> + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6736"/> </dependencies> <objects> <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/> @@ -18,7 +18,7 @@ <nil key="highlightedColor"/> </label> <button opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="1000" contentHorizontalAlignment="fill" contentVerticalAlignment="fill" lineBreakMode="tailTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="l6E-b6-poB"> - <rect key="frame" x="20" y="228" width="398" height="26"/> + <rect key="frame" x="20" y="228" width="30" height="26"/> <constraints> <constraint firstAttribute="height" constant="26" id="i4d-bC-Kui"/> </constraints> @@ -44,6 +44,12 @@ <constraint firstAttribute="trailing" secondItem="I6f-Vm-XuX" secondAttribute="trailing" constant="20" symbolic="YES" id="tll-y7-tNL"/> </constraints> <freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/> + <variation key="default"> + <mask key="constraints"> + <exclude reference="jVU-lo-Wm4"/> + <exclude reference="plD-UM-3Zz"/> + </mask> + </variation> <connections> <outlet property="imageDescriptionLabel" destination="I6f-Vm-XuX" id="fUv-oF-GNJ"/> <outlet property="ownerButton" destination="l6E-b6-poB" id="y4l-ZK-1vr"/> diff --git a/wikipedia/View Controllers/Image Gallery/WMFImageGalleryViewController.h b/wikipedia/View Controllers/Image Gallery/WMFImageGalleryViewController.h index 444e431..3952dd6 100644 --- a/wikipedia/View Controllers/Image Gallery/WMFImageGalleryViewController.h +++ b/wikipedia/View Controllers/Image Gallery/WMFImageGalleryViewController.h @@ -26,6 +26,8 @@ */ - (instancetype)initWithArticle:(MWKArticle*)article; +- (void)setVisibleImage:(MWKImage*)visibleImage animated:(BOOL)animated; + - (void)setVisibleImageIndex:(NSUInteger)visibleImageIndex animated:(BOOL)animated; @end diff --git a/wikipedia/View Controllers/Image Gallery/WMFImageGalleryViewController.m b/wikipedia/View Controllers/Image Gallery/WMFImageGalleryViewController.m index 9825300..c1e343a 100644 --- a/wikipedia/View Controllers/Image Gallery/WMFImageGalleryViewController.m +++ b/wikipedia/View Controllers/Image Gallery/WMFImageGalleryViewController.m @@ -49,10 +49,7 @@ #define ImgGalleryLog(...) #endif -static double const WMFImageGalleryTopGradientHeight = 150.0; -static double const WMFImageGalleryLicenseFontSize = 19.0; -static double const WMFImageGalleryLicenseBaselineOffset = -1.5; -static double const WMFImageGalleryOwnerFontSize = 11.f; +static double const WMFImageGalleryTopGradientHeight = 150.0; NSDictionary* WMFIndexImageInfo(NSArray* imageInfo){ return [imageInfo bk_index:^id < NSCopying > (MWKImageInfo* info) { @@ -64,7 +61,6 @@ <UIGestureRecognizerDelegate, UICollectionViewDelegateFlowLayout> @property (nonatomic) BOOL didApplyInitialVisibleImageIndex; -@property (nonatomic) NSUInteger preRotationVisibleImageIndex; @property (nonatomic, getter = isChromeHidden) BOOL chromeHidden; @property (nonatomic, weak, readonly) UICollectionViewFlowLayout* collectionViewFlowLayout; @@ -89,37 +85,6 @@ - (MWKDataStore*)dataStore; @end - -static NSAttributedString* ConcatOwnerAndLicense(NSString* owner, MWKLicense* license){ - if (!owner && !license) { - return [[NSAttributedString alloc] initWithString:@"" attributes:nil]; - } - NSMutableAttributedString* result = [NSMutableAttributedString new]; - NSString* licenseGlyph = [license toGlyph] ? : WIKIGLYPH_CITE; - if (licenseGlyph) { - // hand-tuning glyph size & baseline offset until all glyphs are positioned & padded in a uniform way - [result appendAttributedString: - [[NSAttributedString alloc] - initWithString:licenseGlyph - attributes:@{NSFontAttributeName: [UIFont wmf_glyphFontOfSize:WMFImageGalleryLicenseFontSize], - NSForegroundColorAttributeName: [UIColor whiteColor], - NSBaselineOffsetAttributeName: @(WMFImageGalleryLicenseBaselineOffset)}]]; - } - - NSString* ownerOrFallback = owner ? - [owner stringByTrimmingCharactersInSet : [NSCharacterSet whitespaceAndNewlineCharacterSet]] - : MWLocalizedString(@"image-gallery-unknown-owner", nil); - - NSAttributedString* attributedOwnerAndSeparator = - [[NSAttributedString alloc] - initWithString:[@" " stringByAppendingString:ownerOrFallback] - attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:WMFImageGalleryOwnerFontSize], - NSForegroundColorAttributeName: [UIColor whiteColor]}]; - - [result appendAttributedString:attributedOwnerAndSeparator]; - - return result; -} static NSString* const WMFImageGalleryCollectionViewCellReuseId = @"WMFImageGalleryCollectionViewCellReuseId"; @@ -160,7 +125,9 @@ - (NSArray*)uniqueArticleImages { if (!_uniqueArticleImages) { - _uniqueArticleImages = [self.article.images uniqueLargestVariants]; + _uniqueArticleImages = [WikipediaAppUtils isDeviceLanguageRTL] ? + [[[self.article.images uniqueLargestVariants] reverseObjectEnumerator] allObjects] + : [self.article.images uniqueLargestVariants]; } return _uniqueArticleImages; } @@ -246,7 +213,6 @@ duration:(NSTimeInterval)duration { [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; NSUInteger const currentImageIndex = [self mostVisibleItemIndex]; - ImgGalleryLog(@"Will scroll to %lu after rotation animation finishes.", currentImageIndex); [UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowAnimatedContent @@ -266,8 +232,10 @@ */ if (!self.didApplyInitialVisibleImageIndex && self.collectionView.visibleCells.count) { [self applyVisibleImageIndex:NO]; - // only set the flag *after* the visible index has been updated, to make sure UICollectionViewDelegate - // callbacks don't override it + /* + only set the flag *after* the visible index has been updated, to make sure UICollectionViewDelegate callbacks + don't override it + */ self.didApplyInitialVisibleImageIndex = YES; } } @@ -300,15 +268,9 @@ }]; UIButton* closeButton = [[UIButton alloc] initWithFrame:CGRectZero]; - // the title must be set first! closeButton.titleLabel.font = [UIFont wmf_glyphFontOfSize:22.f]; [closeButton setTitle:WIKIGLYPH_X forState:UIControlStateNormal]; - - // manually layout closeButton so we can programmatically increase it's hit size - [closeButton wmf_setFrameOrigin:CGPointMake(18.f, 12.f)]; - [closeButton wmf_sizeToFitLabelContents]; - [closeButton wmf_expandWidth:15.f height:15.f]; // apply visual effects [closeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; @@ -322,6 +284,32 @@ [self.view addSubview:closeButton]; _closeButton = closeButton; + + [self.closeButton mas_makeConstraints:^(MASConstraintMaker* make) { + // size is doubled to increase hit area + float const sizeScaleFactor = 2.f; + CGSize const glyphIntrinsicSize = [self.closeButton.titleLabel intrinsicContentSize]; + CGSize const glyphScaledSize = CGSizeMake(glyphIntrinsicSize.width * sizeScaleFactor, + glyphIntrinsicSize.height * sizeScaleFactor); + make.size.mas_equalTo(glyphScaledSize); + + // these offsets account for padding in the glyph + // TODO: centralize/standardize glyph offsets + float const glyphHorizPadding = glyphIntrinsicSize.width * 0.25; + float const glyphVertPadding = glyphIntrinsicSize.height * 0.25; + + /* + align "x" with 20pt leading offset, same as cell's image description. need to account for extra-hit-area + padding as well as the glyph's intrinsic padding + */ + make.leading.equalTo(self.view.mas_leading).with.offset(20.f + - glyphIntrinsicSize.width / 2.f + - glyphHorizPadding); + // top of "x" is 10 pts from the top of the view + make.top.equalTo(self.view.mas_top).with.offset(10.f + - glyphIntrinsicSize.height / 2.f + - glyphVertPadding); + }]; UITapGestureRecognizer* chromeTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapView:)]; @@ -422,6 +410,25 @@ [self setVisibleImageIndex:visibleImageIndex animated:NO]; } +- (void)setVisibleImage:(MWKImage*)visibleImage animated:(BOOL)animated { + NSInteger selectedImageIndex = [self.uniqueArticleImages indexOfObjectPassingTest:^BOOL (MWKImage* image, + NSUInteger idx, + BOOL* stop) { + if ([image isEqualToImage:visibleImage] || [image isVariantOfImage:visibleImage]) { + *stop = YES; + return YES; + } + return NO; + }]; + + if (selectedImageIndex == NSNotFound) { + NSLog(@"WARNING: falling back to showing the first image."); + selectedImageIndex = 0; + } + + self.visibleImageIndex = selectedImageIndex; +} + #pragma mark - UIGestureRecognizerDelegate - (BOOL) gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer @@ -459,12 +466,15 @@ [self updateDetailVisibilityForCell:cell withInfo:infoForImage]; if (infoForImage) { - cell.detailOverlayView.imageDescriptionLabel.text = + cell.detailOverlayView.imageDescription = [infoForImage.imageDescription stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]]; - NSAttributedString* ownerAndLicense = ConcatOwnerAndLicense(infoForImage.owner, infoForImage.license); - [cell.detailOverlayView.ownerButton setAttributedTitle:ownerAndLicense forState:UIControlStateNormal]; + NSString* ownerOrFallback = infoForImage.owner ? + [infoForImage.owner stringByTrimmingCharactersInSet : [NSCharacterSet whitespaceAndNewlineCharacterSet]] + : MWLocalizedString(@"image-gallery-unknown-owner", nil); + + [cell.detailOverlayView setLicense:infoForImage.license owner:ownerOrFallback]; cell.detailOverlayView.ownerTapCallback = ^{ [[UIApplication sharedApplication] openURL:infoForImage.license.URL]; diff --git a/wikipedia/View Controllers/WebView/WebViewController+ImageGalleryPresentation.m b/wikipedia/View Controllers/WebView/WebViewController+ImageGalleryPresentation.m index d9dd018..7d52209 100644 --- a/wikipedia/View Controllers/WebView/WebViewController+ImageGalleryPresentation.m +++ b/wikipedia/View Controllers/WebView/WebViewController+ImageGalleryPresentation.m @@ -16,31 +16,12 @@ [self cancelArticleLoading]; [self cancelSearchLoading]; - NSArray* images = [session.currentArticle.images uniqueLargestVariants]; - - // !!!: hack until we fix race condition between images loading and tap - if (!images || images.count == 0) { + if (!session.currentArticle.images || session.currentArticle.images.count == 0) { return; } - NSInteger selectedImageIndex = - [images indexOfObjectPassingTest: - ^BOOL (MWKImage* image, NSUInteger idx, BOOL* stop) { - if ([image isEqualToImage:selectedImage] || [image isVariantOfImage:selectedImage]) { - *stop = YES; - return YES; - } - return NO; - }]; - - if (selectedImageIndex == NSNotFound) { - NSLog(@"WARNING: falling back to showing the first image."); - selectedImageIndex = 0; - } - - WMFImageGalleryViewController* gallery = - [[WMFImageGalleryViewController alloc] initWithArticle:article]; - gallery.visibleImageIndex = selectedImageIndex; + WMFImageGalleryViewController* gallery = [[WMFImageGalleryViewController alloc] initWithArticle:article]; + [gallery setVisibleImage:selectedImage animated:NO]; [self presentViewController:gallery animated:YES completion:nil]; } -- To view, visit https://gerrit.wikimedia.org/r/197268 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ice8c14e2f1c87bd64c66e4b2ccc959c2380ab522 Gerrit-PatchSet: 1 Gerrit-Project: apps/ios/wikipedia Gerrit-Branch: master Gerrit-Owner: Bgerstle <bgers...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits