diff --git a/clients/ios/Classes/FeedDetailTableCell.m b/clients/ios/Classes/FeedDetailTableCell.m index 690f57fde..26205f8c7 100644 --- a/clients/ios/Classes/FeedDetailTableCell.m +++ b/clients/ios/Classes/FeedDetailTableCell.m @@ -166,6 +166,10 @@ static UIFont *indicatorFont = nil; @synthesize appDelegate; - (void)drawRect:(CGRect)r { + if (!cell) { + return; + } + int riverPadding = 0; if (cell.isRiverOrSocial) { riverPadding = 20; diff --git a/clients/ios/Classes/FeedDetailViewController.m b/clients/ios/Classes/FeedDetailViewController.m index 5d8448296..ba689189e 100644 --- a/clients/ios/Classes/FeedDetailViewController.m +++ b/clients/ios/Classes/FeedDetailViewController.m @@ -299,7 +299,7 @@ // set right avatar title image spacerBarButton.width = 0; spacer2BarButton.width = 0; - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + if (!self.isPhoneOrCompact) { spacerBarButton.width = -6; spacer2BarButton.width = 10; } @@ -330,7 +330,7 @@ } // set center title - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && + if (self.isPhoneOrCompact && !self.navigationItem.titleView) { self.navigationItem.titleView = [appDelegate makeFeedTitle:storiesCollection.activeFeed]; } @@ -357,7 +357,7 @@ feedMarkReadButton.enabled = YES; } - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + if (self.isPhoneOrCompact) { [self fadeSelectedCell:NO]; } @@ -365,7 +365,7 @@ [appDelegate hideShareView:YES]; if (!isDashboardModule && - UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && + !self.isPhoneOrCompact && (appDelegate.masterContainerViewController.storyTitlesOnLeft || !UIInterfaceOrientationIsPortrait(orientation)) && !self.isMovingFromParentViewController && @@ -392,7 +392,7 @@ - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; - if (appDelegate.inStoryDetail && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + if (appDelegate.inStoryDetail && self.isPhoneOrCompact) { appDelegate.inStoryDetail = NO; // [appDelegate.storyPageControl resetPages]; [self checkScroll]; @@ -409,7 +409,7 @@ [self.storyTitlesTable reloadData]; } - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + if (self.isPhoneOrCompact) { [self fadeSelectedCell:YES]; } @@ -436,7 +436,7 @@ [MBProgressHUD hideHUDForView:self.view animated:YES]; } - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && + if (!self.isPhoneOrCompact && self.isMovingToParentViewController && (appDelegate.masterContainerViewController.storyTitlesOnLeft || !UIInterfaceOrientationIsPortrait(orientation))) { @@ -472,7 +472,7 @@ } - (void)setUserAvatarLayout:(UIInterfaceOrientation)orientation { - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && storiesCollection.isSocialView) { + if (self.isPhoneOrCompact && storiesCollection.isSocialView) { if (UIInterfaceOrientationIsPortrait(orientation)) { NBBarButtonItem *avatar = (NBBarButtonItem *)titleImageBarButton.customView; CGRect buttonFrame = avatar.frame; @@ -487,6 +487,10 @@ } } +- (BOOL)isPhoneOrCompact { + return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone || self.appDelegate.isCompactWidth; +} + #pragma mark - #pragma mark Initialization @@ -1076,7 +1080,7 @@ self.pageFinished = NO; [self renderStories:confirmedNewStories]; - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + if (!self.isPhoneOrCompact) { [appDelegate.storyPageControl resizeScrollView]; [appDelegate.storyPageControl setStoryFromScroll:YES]; } @@ -1133,7 +1137,7 @@ [self testForTryFeed]; } - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + if (!self.isPhoneOrCompact) { [appDelegate.masterContainerViewController syncNextPreviousButtons]; } @@ -1224,7 +1228,7 @@ UIImageView *fleuron = [[UIImageView alloc] initWithImage:img]; UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad + if (!self.isPhoneOrCompact && !appDelegate.masterContainerViewController.storyTitlesOnLeft && UIInterfaceOrientationIsPortrait(orientation)) { height = height - kTableViewShortRowDifference; @@ -1368,7 +1372,7 @@ cell.isShort = NO; UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && + if (!self.isPhoneOrCompact && !self.isDashboardModule && !appDelegate.masterContainerViewController.storyTitlesOnLeft && UIInterfaceOrientationIsPortrait(orientation)) { @@ -1384,7 +1388,7 @@ cell.isRiverOrSocial = YES; } - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && !self.isDashboardModule) { + if (!self.isPhoneOrCompact && !self.isDashboardModule) { NSInteger rowIndex = [storiesCollection locationOfActiveStory]; if (rowIndex == indexPath.row) { [tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; @@ -1411,7 +1415,7 @@ } - (void)setTitleForBackButton { - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + if (self.isPhoneOrCompact) { NSString *feedTitle; if (storiesCollection.isRiverView) { if ([storiesCollection.activeFolder isEqualToString:@"river_blurblogs"]) { @@ -1474,7 +1478,7 @@ FeedDetailTableCell *cell = (FeedDetailTableCell*) [tableView cellForRowAtIndexPath:indexPath]; NSInteger storyIndex = [storiesCollection indexFromLocation:indexPath.row]; NSDictionary *story = [[storiesCollection activeFeedStories] objectAtIndex:storyIndex]; - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && + if (!self.isPhoneOrCompact && appDelegate.activeStory && [[story objectForKey:@"story_hash"] isEqualToString:[appDelegate.activeStory objectForKey:@"story_hash"]]) { @@ -1482,7 +1486,7 @@ } [self loadStory:cell atRow:indexPath.row]; } - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + if (!self.isPhoneOrCompact) { [appDelegate.dashboardViewController.storiesModule.view endEditing:YES]; } } @@ -1580,7 +1584,7 @@ heightForRowAtIndexPath:(NSIndexPath *)indexPath { - (BOOL)isShortTitles { UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; - return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && + return !self.isPhoneOrCompact && !appDelegate.masterContainerViewController.storyTitlesOnLeft && UIInterfaceOrientationIsPortrait(orientation) && !self.isDashboardModule; @@ -1830,7 +1834,7 @@ didEndSwipingSwipingWithState:(MCSwipeTableViewCellState)state self.popoverController = nil; void (^pop)(void) = ^{ - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + if (!self.isPhoneOrCompact) { [appDelegate.navigationController popToRootViewControllerAnimated:YES]; [appDelegate.masterContainerViewController transitionFromFeedDetail]; } else { @@ -1902,7 +1906,7 @@ didEndSwipingSwipingWithState:(MCSwipeTableViewCellState)state return; } - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + if (!self.isPhoneOrCompact) { [appDelegate.masterContainerViewController showFeedDetailMenuPopover:self.settingsBarButton]; } else { if (self.popoverController == nil) { @@ -1987,7 +1991,7 @@ didEndSwipingSwipingWithState:(MCSwipeTableViewCellState)state [appDelegate renameFeed:newTitle]; } [self.view setNeedsDisplay]; - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + if (!self.isPhoneOrCompact) { appDelegate.storyPageControl.navigationItem.titleView = [appDelegate makeFeedTitle:storiesCollection.activeFeed]; } else { self.navigationItem.titleView = [appDelegate makeFeedTitle:storiesCollection.activeFeed]; diff --git a/clients/ios/Classes/NBContainerViewController.h b/clients/ios/Classes/NBContainerViewController.h index a8df0219a..b81007416 100644 --- a/clients/ios/Classes/NBContainerViewController.h +++ b/clients/ios/Classes/NBContainerViewController.h @@ -12,7 +12,7 @@ @class NewsBlurAppDelegate; @interface NBContainerViewController : UIViewController - { + { NewsBlurAppDelegate *appDelegate; BOOL interactiveOriginalTransition; diff --git a/clients/ios/Classes/NBContainerViewController.m b/clients/ios/Classes/NBContainerViewController.m index 45618a572..503ccca5a 100644 --- a/clients/ios/Classes/NBContainerViewController.m +++ b/clients/ios/Classes/NBContainerViewController.m @@ -178,6 +178,10 @@ - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + [self checkSize:self.view.bounds.size]; + } + [self layoutDashboardScreen]; } @@ -194,10 +198,13 @@ [[NSNotificationCenter defaultCenter] removeObserver:self]; } - - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator { [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + [self checkSize:size]; + } + [coordinator animateAlongsideTransition:^(id _Nonnull context) { UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; self.rotatingToOrientation = orientation; @@ -243,7 +250,37 @@ self.reorientBackgroundTask = UIBackgroundTaskInvalid; } +- (void)checkSize:(CGSize)size { + BOOL wasCompact = self.appDelegate.isCompactWidth; + BOOL isCompact = size.width < 700.0; + + if (!isCompact && wasCompact == isCompact) { + return; + } + + self.appDelegate.compactWidth = isCompact ? size.width : 0.0; + + self.masterNavigationController.view.frame = CGRectMake(0, 0, self.masterWidth, self.view.bounds.size.height); + + if (!isCompact) { + if (self.masterNavigationController.topViewController == self.storyPageControl) { + [self.masterNavigationController popToViewController:self.feedDetailViewController animated:NO]; + } + + if (self.storyNavigationController.topViewController != self.storyPageControl) { + [self.storyNavigationController pushViewController:self.storyPageControl animated:NO]; + self.storyPageControl.isAnimatedIntoPlace = NO; + } + + [self.storyPageControl hidePages]; + } +} + - (NSInteger)masterWidth { + if (self.appDelegate.isCompactWidth) { + return self.appDelegate.compactWidth; + } + UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; if (UIInterfaceOrientationIsLandscape(orientation)) { return NB_DEFAULT_MASTER_WIDTH_LANDSCAPE; @@ -253,175 +290,96 @@ # pragma mark Modals and Popovers -- (void)showUserProfilePopover:(id)sender { - if (popoverController.isPopoverVisible) { - [popoverController dismissPopoverAnimated:NO]; - popoverController = nil; - return; +- (void)showPopoverWithViewController:(UIViewController *)viewController contentSize:(CGSize)contentSize barButtonItem:(UIBarButtonItem *)barButtonItem { + [self showPopoverWithViewController:viewController contentSize:contentSize barButtonItem:barButtonItem sourceView:nil sourceRect:CGRectZero]; +} + +- (void)showPopoverWithViewController:(UIViewController *)viewController contentSize:(CGSize)contentSize sourceView:(UIView *)sourceView sourceRect:(CGRect)sourceRect { + [self showPopoverWithViewController:viewController contentSize:contentSize barButtonItem:nil sourceView:sourceView sourceRect:sourceRect]; +} + +- (void)showPopoverWithViewController:(UIViewController *)viewController contentSize:(CGSize)contentSize barButtonItem:(UIBarButtonItem *)barButtonItem sourceView:(UIView *)sourceView sourceRect:(CGRect)sourceRect { + if (self.masterNavigationController.presentedViewController) { + [self.masterNavigationController.presentedViewController dismissViewControllerAnimated:YES completion:nil]; } - popoverController = [[UIPopoverController alloc] - initWithContentViewController:appDelegate.userProfileNavigationController]; + viewController.modalPresentationStyle = UIModalPresentationPopover; + viewController.preferredContentSize = contentSize; - [popoverController setDelegate:self]; - [popoverController setPopoverContentSize:CGSizeMake(320, 454)]; - [appDelegate.userProfileNavigationController view]; + UIPopoverPresentationController *popoverPresentationController = viewController.popoverPresentationController; + popoverPresentationController.delegate = self; + popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionAny; + + if (barButtonItem) { + popoverPresentationController.barButtonItem = barButtonItem; + } else { + popoverPresentationController.sourceView = sourceView; + popoverPresentationController.sourceRect = sourceRect; + } + + [self.masterNavigationController presentViewController:viewController animated:YES completion:nil]; +} + +- (void)showUserProfilePopover:(id)sender { if ([sender class] == [InteractionCell class] || [sender class] == [ActivityCell class]) { InteractionCell *cell = (InteractionCell *)sender; - [popoverController presentPopoverFromRect:cell.bounds - inView:cell - permittedArrowDirections:UIPopoverArrowDirectionAny - animated:YES]; + [self showPopoverWithViewController:self.appDelegate.userProfileNavigationController contentSize:CGSizeMake(320, 454) sourceView:cell sourceRect:cell.bounds]; } else if ([sender class] == [FeedTableCell class]) { - FeedTableCell *cell = (FeedTableCell *)sender; - - [popoverController presentPopoverFromRect:cell.bounds - inView:cell - permittedArrowDirections:UIPopoverArrowDirectionAny - animated:YES]; + FeedTableCell *cell = (FeedTableCell *)sender; + + [self showPopoverWithViewController:self.appDelegate.userProfileNavigationController contentSize:CGSizeMake(320, 454) sourceView:cell sourceRect:cell.bounds]; } else if ([sender class] == [UIBarButtonItem class]) { - [popoverController presentPopoverFromBarButtonItem:sender - permittedArrowDirections:UIPopoverArrowDirectionAny - animated:YES]; + [self showPopoverWithViewController:self.appDelegate.userProfileNavigationController contentSize:CGSizeMake(320, 454) barButtonItem:sender]; } else { CGRect frame = [sender CGRectValue]; - [popoverController presentPopoverFromRect:frame - inView:self.storyPageControl.view - permittedArrowDirections:UIPopoverArrowDirectionAny - animated:YES]; - } + [self showPopoverWithViewController:self.appDelegate.userProfileNavigationController contentSize:CGSizeMake(320, 454) sourceView:self.storyPageControl.view sourceRect:frame]; + } } - (void)showSitePopover:(id)sender { - if (popoverController.isPopoverVisible) { - [popoverController dismissPopoverAnimated:NO]; - popoverController = nil; - return; - } - - popoverController = [[UIPopoverController alloc] - initWithContentViewController:appDelegate.addSiteViewController]; - [popoverController setDelegate:self]; - [popoverController setPopoverContentSize:CGSizeMake(320, 355)]; - [popoverController presentPopoverFromBarButtonItem:sender - permittedArrowDirections:UIPopoverArrowDirectionAny - animated:YES]; + [self showPopoverWithViewController:self.appDelegate.addSiteViewController contentSize:CGSizeMake(320, 355) barButtonItem:sender]; } - - (void)showFeedMenuPopover:(id)sender { - if (popoverController.isPopoverVisible) { - [popoverController dismissPopoverAnimated:NO]; - popoverController = nil; - return; - } - - popoverController = [[UIPopoverController alloc] - initWithContentViewController:appDelegate.feedsMenuViewController]; - [popoverController setDelegate:self]; - [appDelegate.feedsMenuViewController view]; - NSInteger menuCount = [appDelegate.feedsMenuViewController.menuOptions count]; - [popoverController setPopoverContentSize:CGSizeMake(200, 38 * menuCount)]; - [popoverController presentPopoverFromBarButtonItem:sender - permittedArrowDirections:UIPopoverArrowDirectionAny - animated:YES]; + [self.appDelegate.feedsMenuViewController view]; + NSInteger menuCount = [self.appDelegate.feedsMenuViewController.menuOptions count]; + + [self showPopoverWithViewController:self.appDelegate.feedsMenuViewController contentSize:CGSizeMake(200, 38 * menuCount) barButtonItem:sender]; } - (void)showFeedDetailMenuPopover:(id)sender { - if (popoverController.isPopoverVisible) { - [popoverController dismissPopoverAnimated:NO]; - popoverController = nil; - return; - } - - popoverController = [[UIPopoverController alloc] - initWithContentViewController:appDelegate.feedDetailMenuViewController]; - [appDelegate.feedDetailMenuViewController buildMenuOptions]; - popoverController.delegate = self; - [appDelegate.feedDetailMenuViewController view]; - NSInteger menuCount = [appDelegate.feedDetailMenuViewController.menuOptions count] + 2; - [popoverController setPopoverContentSize:CGSizeMake(260, 38 * menuCount)]; - [popoverController presentPopoverFromBarButtonItem:sender - permittedArrowDirections:UIPopoverArrowDirectionAny - animated:YES]; + NSInteger menuCount = [self.appDelegate.feedDetailMenuViewController.menuOptions count] + 2; + + [self showPopoverWithViewController:self.appDelegate.feedDetailMenuViewController contentSize:CGSizeMake(260, 38 * menuCount) barButtonItem:sender]; } - (void)showFontSettingsPopover:(id)sender { - if (popoverController.isPopoverVisible) { - [popoverController dismissPopoverAnimated:NO]; - popoverController = nil; - return; - } - - popoverController = [[UIPopoverController alloc] - initWithContentViewController:appDelegate.fontSettingsNavigationController]; - - popoverController.delegate = self; - - - [popoverController setPopoverContentSize:CGSizeMake(240.0, 306.0)]; - // UIBarButtonItem *settingsButton = [[UIBarButtonItem alloc] - // initWithCustomView:sender]; - [popoverController presentPopoverFromBarButtonItem:sender - permittedArrowDirections:UIPopoverArrowDirectionAny - animated:YES]; + [self showPopoverWithViewController:self.appDelegate.fontSettingsNavigationController contentSize:CGSizeMake(240.0, 306.0) barButtonItem:sender]; } - (void)showTrainingPopover:(id)sender { - if (popoverController.isPopoverVisible) { - [popoverController dismissPopoverAnimated:NO]; - } - - popoverController = [[UIPopoverController alloc] - initWithContentViewController:appDelegate.trainerViewController]; - popoverController.delegate = self; - - [popoverController setPopoverContentSize:CGSizeMake(420, 382)]; if ([sender class] == [UIBarButtonItem class]) { - [popoverController presentPopoverFromBarButtonItem:sender - permittedArrowDirections:UIPopoverArrowDirectionAny - animated:NO]; + [self showPopoverWithViewController:self.appDelegate.trainerViewController contentSize:CGSizeMake(420, 382) barButtonItem:sender]; } else if ([sender class] == [FeedTableCell class]) { FeedTableCell *cell = (FeedTableCell *)sender; - [popoverController presentPopoverFromRect:cell.bounds - inView:cell - permittedArrowDirections:UIPopoverArrowDirectionAny - animated:YES]; + [self showPopoverWithViewController:self.appDelegate.trainerViewController contentSize:CGSizeMake(420, 382) sourceView:cell sourceRect:cell.bounds]; } else if ([sender class] == [FeedDetailTableCell class]) { FeedDetailTableCell *cell = (FeedDetailTableCell *)sender; - [popoverController presentPopoverFromRect:cell.bounds - inView:cell - permittedArrowDirections:UIPopoverArrowDirectionAny - animated:YES]; + [self showPopoverWithViewController:self.appDelegate.trainerViewController contentSize:CGSizeMake(420, 382) sourceView:cell sourceRect:cell.bounds]; } else { CGRect frame = [sender CGRectValue]; - [popoverController presentPopoverFromRect:frame - inView:self.storyPageControl.view - permittedArrowDirections:UIPopoverArrowDirectionAny - animated:YES]; + [self showPopoverWithViewController:self.appDelegate.trainerViewController contentSize:CGSizeMake(420, 382) sourceView:self.storyPageControl.view sourceRect:frame]; } } - (void)showUserTagsPopover:(id)sender { - if (popoverController.isPopoverVisible) { - [popoverController dismissPopoverAnimated:NO]; - } - - popoverController = [[UIPopoverController alloc] - initWithContentViewController:appDelegate.userTagsViewController]; - popoverController.delegate = self; - - [popoverController setPopoverContentSize:CGSizeMake(220, 382)]; [appDelegate.userTagsViewController view]; // Force viewDidLoad CGRect frame = [sender CGRectValue]; - [popoverController presentPopoverFromRect:frame - inView:self.storyPageControl.currentPage.view - permittedArrowDirections:UIPopoverArrowDirectionAny - animated:YES]; + [self showPopoverWithViewController:self.appDelegate.userTagsViewController contentSize:CGSizeMake(220, 382) sourceView:self.storyPageControl.view sourceRect:frame]; } - (void)showSendToPopover:(id)sender { @@ -443,6 +401,12 @@ [self.storyPageControl setNextPreviousButtons]; } +#pragma mark - UIPopoverPresentationControllerDelegate + +- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller { + return UIModalPresentationNone; +} + #pragma mark - Screen Transitions and Layout - (void)setupStoryTitlesPosition { diff --git a/clients/ios/Classes/NewsBlurAppDelegate.h b/clients/ios/Classes/NewsBlurAppDelegate.h index 14814d4ea..fb152482d 100644 --- a/clients/ios/Classes/NewsBlurAppDelegate.h +++ b/clients/ios/Classes/NewsBlurAppDelegate.h @@ -248,6 +248,8 @@ SFSafariViewControllerDelegate> { @property (nonatomic) NSMutableDictionary *activeCachedImages; @property (nonatomic, readwrite) BOOL hasQueuedReadStories; @property (nonatomic, readonly) BOOL showingSafariViewController; +@property (nonatomic, readonly) BOOL isCompactWidth; +@property (nonatomic) CGFloat compactWidth; @property (nonatomic, strong) void (^backgroundCompletionHandler)(UIBackgroundFetchResult); diff --git a/clients/ios/Classes/NewsBlurAppDelegate.m b/clients/ios/Classes/NewsBlurAppDelegate.m index 2602b3d0d..3f2a571c9 100644 --- a/clients/ios/Classes/NewsBlurAppDelegate.m +++ b/clients/ios/Classes/NewsBlurAppDelegate.m @@ -1007,6 +1007,10 @@ } } +- (BOOL)isCompactWidth { + return self.compactWidth > 0.0; +} + - (void)confirmLogout { UIAlertView *logoutConfirm = [[UIAlertView alloc] initWithTitle:@"Positive?" message:nil @@ -1334,7 +1338,7 @@ } - (void)loadStoryDetailView { - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone || self.isCompactWidth) { [navigationController pushViewController:storyPageControl animated:YES]; navigationController.navigationItem.hidesBackButton = YES; } @@ -1346,13 +1350,24 @@ [self.storyPageControl view]; [self.storyPageControl.view setNeedsLayout]; [self.storyPageControl.view layoutIfNeeded]; - [self.storyPageControl changePage:activeStoryLocation animated:animated]; - [self.storyPageControl animateIntoPlace:YES]; + + NSDictionary *params = @{@"location" : @(activeStoryLocation), @"animated" : @(animated)}; + + if (self.isCompactWidth) { + [self performSelector:@selector(deferredChangePage:) withObject:params afterDelay:0.0]; + } else { + [self deferredChangePage:params]; + } } [MBProgressHUD hideHUDForView:self.storyPageControl.view animated:YES]; } +- (void)deferredChangePage:(NSDictionary *)params { + [self.storyPageControl changePage:[params[@"location"] integerValue] animated:[params[@"animated"] boolValue]]; + [self.storyPageControl animateIntoPlace:YES]; +} + - (void)setTitle:(NSString *)title { UILabel *label = [[UILabel alloc] init]; [label setFont:[UIFont boldSystemFontOfSize:16.0]]; diff --git a/clients/ios/Classes/StoryDetailViewController.m b/clients/ios/Classes/StoryDetailViewController.m index 164a8690a..94c527c58 100644 --- a/clients/ios/Classes/StoryDetailViewController.m +++ b/clients/ios/Classes/StoryDetailViewController.m @@ -223,7 +223,7 @@ - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + if (!self.isPhoneOrCompact) { [appDelegate.feedDetailViewController.view endEditing:YES]; } [self storeScrollPosition:NO]; @@ -232,7 +232,7 @@ - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + if (!self.isPhoneOrCompact) { [appDelegate.feedDetailViewController.view endEditing:YES]; } @@ -281,6 +281,10 @@ NSLog(@"viewWillLayoutSubviews: %.2f", self.webView.scrollView.bounds.size.width); } +- (BOOL)isPhoneOrCompact { + return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone || self.appDelegate.isCompactWidth; +} + #pragma mark - #pragma mark Story setup @@ -348,11 +352,11 @@ NSString *contentWidthClass; NSLog(@"Drawing story: %@ / %d", [self.activeStory objectForKey:@"story_title"], contentWidth); - if (UIInterfaceOrientationIsLandscape(orientation) && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + if (UIInterfaceOrientationIsLandscape(orientation) && !self.isPhoneOrCompact) { contentWidthClass = @"NB-ipad-wide"; - } else if (!UIInterfaceOrientationIsLandscape(orientation) && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + } else if (!UIInterfaceOrientationIsLandscape(orientation) && !self.isPhoneOrCompact) { contentWidthClass = @"NB-ipad-narrow"; - } else if (UIInterfaceOrientationIsLandscape(orientation) && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + } else if (UIInterfaceOrientationIsLandscape(orientation) && self.isPhoneOrCompact) { contentWidthClass = @"NB-iphone-wide"; } else { contentWidthClass = @"NB-iphone"; @@ -917,7 +921,7 @@ locationHtml = [NSString stringWithFormat:@"
%@
", location]; } - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + if (!self.isPhoneOrCompact) { comment = [NSString stringWithFormat:@ "
" "
" @@ -1048,7 +1052,7 @@ NSString *reply; - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + if (!self.isPhoneOrCompact) { reply = [NSString stringWithFormat:@ "
" " " @@ -1484,7 +1488,7 @@ shouldStartLoadWithRequest:(NSURLRequest *)request - (void)showUserProfile:(NSString *)userId xCoordinate:(int)x yCoordinate:(int)y width:(int)width height:(int)height { CGRect frame = CGRectZero; - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + if (!self.isPhoneOrCompact) { // only adjust for the bar if user is scrolling if (appDelegate.storiesCollection.isRiverView || appDelegate.storiesCollection.isSocialView || @@ -1713,7 +1717,7 @@ shouldStartLoadWithRequest:(NSURLRequest *)request - (void)openTrainingDialog:(int)x yCoordinate:(int)y width:(int)width height:(int)height { CGRect frame = CGRectZero; - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + if (!self.isPhoneOrCompact) { // only adjust for the bar if user is scrolling if (appDelegate.storiesCollection.isRiverView || appDelegate.storiesCollection.isSocialView || @@ -2041,11 +2045,11 @@ shouldStartLoadWithRequest:(NSURLRequest *)request UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; NSString *contentWidthClass; - if (UIInterfaceOrientationIsLandscape(orientation) && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + if (UIInterfaceOrientationIsLandscape(orientation) && !self.isPhoneOrCompact) { contentWidthClass = @"NB-ipad-wide"; - } else if (!UIInterfaceOrientationIsLandscape(orientation) && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + } else if (!UIInterfaceOrientationIsLandscape(orientation) && !self.isPhoneOrCompact) { contentWidthClass = @"NB-ipad-narrow"; - } else if (UIInterfaceOrientationIsLandscape(orientation) && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + } else if (UIInterfaceOrientationIsLandscape(orientation) && self.isPhoneOrCompact) { contentWidthClass = @"NB-iphone-wide"; } else { contentWidthClass = @"NB-iphone"; diff --git a/clients/ios/Classes/StoryPageControl.m b/clients/ios/Classes/StoryPageControl.m index 8fdb79006..76aece586 100644 --- a/clients/ios/Classes/StoryPageControl.m +++ b/clients/ios/Classes/StoryPageControl.m @@ -188,7 +188,7 @@ [self.view addSubview:self.notifier]; [self.notifier hideNow]; - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects: originalStoryButton, separatorBarButton, @@ -213,7 +213,7 @@ isEqualToString:@"pop_to_story_list"];; self.navigationController.interactivePopGestureRecognizer.enabled = swipeEnabled; - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + if (self.isPhoneOrCompact) { if (!appDelegate.storiesCollection.isSocialView) { UIImage *titleImage; if (appDelegate.storiesCollection.isSocialRiverView && @@ -285,7 +285,7 @@ [super viewDidAppear:animated]; // set the subscribeButton flag - if (appDelegate.isTryFeedView && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + if (appDelegate.isTryFeedView && !self.isPhoneOrCompact) { self.subscribeButton.title = [NSString stringWithFormat:@"Follow %@", [appDelegate.storiesCollection.activeFeed objectForKey:@"username"]]; self.navigationItem.leftBarButtonItem = self.subscribeButton; @@ -350,7 +350,7 @@ // CGRect scrollViewFrame = self.scrollView.frame; // CGRect traverseViewFrame = self.traverseView.frame; - if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad || + if (self.isPhoneOrCompact || UIInterfaceOrientationIsLandscape(orientation)) { // scrollViewFrame.size.height = self.view.bounds.size.height; // self.bottomSize.hidden = YES; @@ -472,7 +472,7 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && + if (!self.isPhoneOrCompact && UIInterfaceOrientationIsPortrait(orientation)) { UITouch *theTouch = [touches anyObject]; CGPoint tappedPt = [theTouch locationInView:self.view]; @@ -492,7 +492,7 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && + if (!self.isPhoneOrCompact && UIInterfaceOrientationIsPortrait(orientation)) { if (self.inTouchMove) { self.inTouchMove = NO; @@ -501,6 +501,10 @@ } } +- (BOOL)isPhoneOrCompact { + return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone || self.appDelegate.isCompactWidth; +} + #pragma mark - #pragma mark Side scroll view @@ -684,7 +688,7 @@ ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && + if (!self.isPhoneOrCompact && [keyPath isEqual:@"contentOffset"] && self.isDraggingScrollview) { CGFloat pageWidth = self.scrollView.frame.size.width; @@ -694,7 +698,7 @@ if (![appDelegate.storiesCollection.activeFeedStories count]) return; NSInteger storyIndex = [appDelegate.storiesCollection indexFromLocation:nearestNumber]; - if (storyIndex != [appDelegate.storiesCollection indexOfActiveStory]) { + if (storyIndex != [appDelegate.storiesCollection indexOfActiveStory] && storyIndex != NSNotFound) { appDelegate.activeStory = [appDelegate.storiesCollection.activeFeedStories objectAtIndex:storyIndex]; [appDelegate changeActiveFeedDetailRow]; @@ -704,7 +708,7 @@ - (void)animateIntoPlace:(BOOL)animated { // Move view into position if no story is selected yet - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && + if (!self.isPhoneOrCompact && !self.isAnimatedIntoPlace) { CGRect frame = self.scrollView.frame; frame.origin.x = frame.size.width; @@ -789,7 +793,7 @@ previousPage.webView.scrollView.scrollsToTop = NO; currentPage.webView.scrollView.scrollsToTop = YES; currentPage.isRecentlyUnread = NO; - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + if (!self.isPhoneOrCompact) { appDelegate.feedDetailViewController.storyTitlesTable.scrollsToTop = NO; } self.scrollView.scrollsToTop = NO;