From 3f7f1874bfb5ca970ec74cee13231dfe8fccaa46 Mon Sep 17 00:00:00 2001 From: "v.mikhaylenko" Date: Thu, 16 Jul 2015 15:27:09 +0300 Subject: [PATCH] [ios] Added fade in/out to dialogs. --- .../AlertController/MWMAlertViewController.h | 19 ++++++----- .../AlertController/MWMAlertViewController.mm | 34 +++++++++++++++---- .../Classes/CustomAlert/BaseAlert/MWMAlert.mm | 6 ++-- 3 files changed, 41 insertions(+), 18 deletions(-) diff --git a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h index 6c8c6a1386..a759a69fcb 100644 --- a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h +++ b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h @@ -12,11 +12,13 @@ #include "routing/router.hpp" #include "storage/storage.hpp" +typedef void (^CloseAlertCompletion)(); + @interface MWMAlertViewController : UIViewController -@property (weak, nonatomic, readonly) UIViewController * ownerViewController; +@property (nonnull, weak, nonatomic, readonly) UIViewController * ownerViewController; -- (instancetype)initWithViewController:(UIViewController *)viewController; +- (nonnull instancetype)initWithViewController:(nonnull UIViewController *)viewController; - (void)presentAlert:(routing::IRouter::ResultCode)type; - (void)presentDownloaderAlertWithCountries:(vector const &)countries routes:(vector const &)routes; - (void)presentCrossCountryAlertWithCountries:(vector const &)countries routes:(vector const &)routes; @@ -28,12 +30,11 @@ - (void)presentLocationAlert; - (void)presentLocationServiceNotSupportedAlert; - (void)presentNoConnectionAlert; -- (void)presentnoWiFiAlertWithName:(NSString *)name downloadBlock:(RightButtonAction)block; +- (void)presentnoWiFiAlertWithName:(nonnull NSString *)name downloadBlock:(nullable RightButtonAction)block; +- (void)closeAlertWithCompletion:(nullable CloseAlertCompletion)completion; -- (void)closeAlert; - -- (instancetype)init __attribute__((unavailable("-init isn't available, call -initWithViewController: instead!"))); -+ (instancetype)new __attribute__((unavailable("+new isn't available, call -initWithViewController: instead!"))); -- (instancetype)initWithCoder:(NSCoder *)aDecoder __attribute__((unavailable("-initWithCoder: isn't available, call -initWithViewController: instead!"))); -- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil __attribute__((unavailable("-initWithNibName:bundle: isn't available, call -initWithViewController: instead!"))); +- (nonnull instancetype)init __attribute__((unavailable("-init isn't available, call -initWithViewController: instead!"))); ++ (nonnull instancetype)new __attribute__((unavailable("+new isn't available, call -initWithViewController: instead!"))); +- (nonnull instancetype)initWithCoder:(nonnull NSCoder *)aDecoder __attribute__((unavailable("-initWithCoder: isn't available, call -initWithViewController: instead!"))); +- (nonnull instancetype)initWithNibName:(nullable NSString *)nibNameOrNil bundle:(nullable NSBundle *)nibBundleOrNil __attribute__((unavailable("-initWithNibName:bundle: isn't available, call -initWithViewController: instead!"))); @end diff --git a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm index 640fef12a4..ab0b9ed214 100644 --- a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm +++ b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm @@ -15,13 +15,13 @@ static NSString * const kAlertControllerNibIdentifier = @"MWMAlertViewController @interface MWMAlertViewController () -@property (weak, nonatomic, readwrite) UIViewController * ownerViewController; +@property (nonnull ,weak, nonatomic, readwrite) UIViewController * ownerViewController; @end @implementation MWMAlertViewController -- (instancetype)initWithViewController:(UIViewController *)viewController +- (nonnull instancetype)initWithViewController:(nonnull UIViewController *)viewController { self = [super initWithNibName:kAlertControllerNibIdentifier bundle:nil]; if (self) @@ -86,7 +86,7 @@ static NSString * const kAlertControllerNibIdentifier = @"MWMAlertViewController [self displayAlert:MWMAlert.noConnectionAlert]; } -- (void)presentnoWiFiAlertWithName:(NSString *)name downloadBlock:(RightButtonAction)block +- (void)presentnoWiFiAlertWithName:(nonnull NSString *)name downloadBlock:(nullable RightButtonAction)block { [self displayAlert:[MWMAlert noWiFiAlertWithName:name downloadBlock:block]]; } @@ -125,6 +125,10 @@ static NSString * const kAlertControllerNibIdentifier = @"MWMAlertViewController { alert.alertController = self; [self.ownerViewController addChildViewController:self]; + self.view.alpha = 0.; + alert.alpha = 0.; + CGFloat const scale = 1.1; + alert.transform = CGAffineTransformMakeScale(scale, scale); self.view.center = self.ownerViewController.view.center; [self.ownerViewController.view addSubview:self.view]; UIWindow * window = [[[UIApplication sharedApplication] delegate] window]; @@ -133,13 +137,29 @@ static NSString * const kAlertControllerNibIdentifier = @"MWMAlertViewController [self.view addSubview:alert]; alert.bounds = self.view.bounds; alert.center = self.view.center; + [UIView animateWithDuration:.15 animations:^ + { + self.view.alpha = 1.; + alert.alpha = 1.; + alert.transform = CGAffineTransformIdentity; + }]; } -- (void)closeAlert +- (void)closeAlertWithCompletion:(nullable CloseAlertCompletion)completion { - self.ownerViewController.view.userInteractionEnabled = YES; - [self.view removeFromSuperview]; - [self removeFromParentViewController]; + MWMAlert * alert = self.view.subviews.firstObject; + [UIView animateWithDuration:.15 animations:^ + { + alert.alpha = 0.; + self.view.alpha = 0.; + } + completion:^(BOOL finished) + { + if (completion) + completion(); + [self.view removeFromSuperview]; + [self removeFromParentViewController]; + }]; } - (void)openSettings diff --git a/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm b/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm index 0b5181cc93..f1706e6620 100644 --- a/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm +++ b/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm @@ -105,8 +105,10 @@ - (void)close { - [self removeFromSuperview]; - [self.alertController closeAlert]; + [self.alertController closeAlertWithCompletion:^ + { + [self removeFromSuperview]; + }]; } - (void)setNeedsCloseAlertAfterEnterBackground