fixing major navigation operation defect.
dispatch after instead of nstimer
This commit is contained in:
parent
d91e8a8365
commit
56c8a961eb
@ -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.
|
||||
|
||||
@ -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:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user