From 56c8a961eb1573091ea6da511a6aa24efd6a03c5 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 8 May 2018 11:26:32 -0400 Subject: [PATCH] fixing major navigation operation defect. dispatch after instead of nstimer --- .../AlertHandling/MVMCoreTopAlertOperation.m | 44 ++++--------------- .../MVMCoreNavigationOperation.m | 8 +++- 2 files changed, 16 insertions(+), 36 deletions(-) diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreTopAlertOperation.m b/MVMCore/MVMCore/AlertHandling/MVMCoreTopAlertOperation.m index a4cbfb8..222a56e 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreTopAlertOperation.m +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreTopAlertOperation.m @@ -16,22 +16,16 @@ __block BOOL _paused; __block BOOL _displayed; __block BOOL _animating; - __block NSTimer *_dismissTimer; } @property (readwrite, getter=isPaused) BOOL paused; - @property (readwrite, getter=isDisplayed) BOOL displayed; - @property (readwrite, getter=isAnimating) BOOL animating; -@property (strong, nonatomic) NSTimer *dismissTimer; - // For thread safety @property (strong, nonatomic) dispatch_queue_t pausedQueue; @property (strong, nonatomic) dispatch_queue_t displayedQueue; @property (strong, nonatomic) dispatch_queue_t animatingQueue; -@property (strong, nonatomic) dispatch_queue_t timerQueue; @end @@ -44,7 +38,6 @@ self.pausedQueue = dispatch_queue_create("paused", DISPATCH_QUEUE_CONCURRENT); self.displayedQueue = dispatch_queue_create("displayed", DISPATCH_QUEUE_CONCURRENT); self.animatingQueue = dispatch_queue_create("animating", DISPATCH_QUEUE_CONCURRENT); - self.timerQueue = dispatch_queue_create("timer", DISPATCH_QUEUE_CONCURRENT); } return self; } @@ -102,20 +95,6 @@ }); } -- (NSTimer *)dismissTimer { - __block NSTimer *timer; - dispatch_sync(self.timerQueue, ^{ - timer = _dismissTimer; - }); - return timer; -} - -- (void)setDismissTimer:(NSTimer *)dismissTimer { - dispatch_barrier_async(self.timerQueue, ^{ - _dismissTimer = dismissTimer; - }); -} - - (void)main { // Always check for cancellation before launching the task. @@ -156,7 +135,14 @@ } else { dismissTime = TopAlertDismissTime; } - self.dismissTimer = [NSTimer scheduledTimerWithTimeInterval:dismissTime target:self selector:@selector(timerFinished) userInfo:nil repeats:NO]; + + __weak typeof(self) weakSelf = self; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(dismissTime * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + if (weakSelf.isFinished || [weakSelf checkAndHandleForCancellation]) { + return; + } + [weakSelf dismissAlertView:YES]; + }); } }]; } @@ -166,19 +152,9 @@ } } -- (void)timerFinished { - [self dismissAlertView:YES]; -} - - (void)cancel { [super cancel]; - // Kill the dismiss timer. - if (self.dismissTimer) { - [self.dismissTimer invalidate]; - self.dismissTimer = nil; - } - // Do nothing if animating. if (!self.isAnimating) { @@ -191,9 +167,7 @@ } - (void)dismissAlertView:(BOOL)andFinish { - - self.dismissTimer = nil; - + if (self.isDisplayed && !self.isAnimating) { // Dismisses. diff --git a/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationOperation.m b/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationOperation.m index e53f5b2..a1fda67 100644 --- a/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationOperation.m +++ b/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationOperation.m @@ -134,6 +134,8 @@ { if (self.navigationObject.navigationController.viewControllers.count > 1) { [self.navigationObject.navigationController popViewControllerAnimated:self.navigationObject.animated]; + } else { + [self markAsFinished]; } } break; @@ -182,7 +184,11 @@ break; case NavigationTypePopToRoot: { - [self.navigationObject.navigationController popToRootViewControllerAnimated:self.navigationObject.animated]; + if (self.navigationObject.navigationController.viewControllers.count > 1) { + [self.navigationObject.navigationController popToRootViewControllerAnimated:self.navigationObject.animated]; + } else { + [self markAsFinished]; + } } break; default: