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 _paused;
|
||||||
__block BOOL _displayed;
|
__block BOOL _displayed;
|
||||||
__block BOOL _animating;
|
__block BOOL _animating;
|
||||||
__block NSTimer *_dismissTimer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@property (readwrite, getter=isPaused) BOOL paused;
|
@property (readwrite, getter=isPaused) BOOL paused;
|
||||||
|
|
||||||
@property (readwrite, getter=isDisplayed) BOOL displayed;
|
@property (readwrite, getter=isDisplayed) BOOL displayed;
|
||||||
|
|
||||||
@property (readwrite, getter=isAnimating) BOOL animating;
|
@property (readwrite, getter=isAnimating) BOOL animating;
|
||||||
|
|
||||||
@property (strong, nonatomic) NSTimer *dismissTimer;
|
|
||||||
|
|
||||||
// For thread safety
|
// For thread safety
|
||||||
@property (strong, nonatomic) dispatch_queue_t pausedQueue;
|
@property (strong, nonatomic) dispatch_queue_t pausedQueue;
|
||||||
@property (strong, nonatomic) dispatch_queue_t displayedQueue;
|
@property (strong, nonatomic) dispatch_queue_t displayedQueue;
|
||||||
@property (strong, nonatomic) dispatch_queue_t animatingQueue;
|
@property (strong, nonatomic) dispatch_queue_t animatingQueue;
|
||||||
@property (strong, nonatomic) dispatch_queue_t timerQueue;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@ -44,7 +38,6 @@
|
|||||||
self.pausedQueue = dispatch_queue_create("paused", DISPATCH_QUEUE_CONCURRENT);
|
self.pausedQueue = dispatch_queue_create("paused", DISPATCH_QUEUE_CONCURRENT);
|
||||||
self.displayedQueue = dispatch_queue_create("displayed", DISPATCH_QUEUE_CONCURRENT);
|
self.displayedQueue = dispatch_queue_create("displayed", DISPATCH_QUEUE_CONCURRENT);
|
||||||
self.animatingQueue = dispatch_queue_create("animating", DISPATCH_QUEUE_CONCURRENT);
|
self.animatingQueue = dispatch_queue_create("animating", DISPATCH_QUEUE_CONCURRENT);
|
||||||
self.timerQueue = dispatch_queue_create("timer", DISPATCH_QUEUE_CONCURRENT);
|
|
||||||
}
|
}
|
||||||
return self;
|
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 {
|
- (void)main {
|
||||||
|
|
||||||
// Always check for cancellation before launching the task.
|
// Always check for cancellation before launching the task.
|
||||||
@ -156,7 +135,14 @@
|
|||||||
} else {
|
} else {
|
||||||
dismissTime = TopAlertDismissTime;
|
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 {
|
- (void)cancel {
|
||||||
[super cancel];
|
[super cancel];
|
||||||
|
|
||||||
// Kill the dismiss timer.
|
|
||||||
if (self.dismissTimer) {
|
|
||||||
[self.dismissTimer invalidate];
|
|
||||||
self.dismissTimer = nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do nothing if animating.
|
// Do nothing if animating.
|
||||||
if (!self.isAnimating) {
|
if (!self.isAnimating) {
|
||||||
|
|
||||||
@ -191,9 +167,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)dismissAlertView:(BOOL)andFinish {
|
- (void)dismissAlertView:(BOOL)andFinish {
|
||||||
|
|
||||||
self.dismissTimer = nil;
|
|
||||||
|
|
||||||
if (self.isDisplayed && !self.isAnimating) {
|
if (self.isDisplayed && !self.isAnimating) {
|
||||||
|
|
||||||
// Dismisses.
|
// Dismisses.
|
||||||
|
|||||||
@ -134,6 +134,8 @@
|
|||||||
{
|
{
|
||||||
if (self.navigationObject.navigationController.viewControllers.count > 1) {
|
if (self.navigationObject.navigationController.viewControllers.count > 1) {
|
||||||
[self.navigationObject.navigationController popViewControllerAnimated:self.navigationObject.animated];
|
[self.navigationObject.navigationController popViewControllerAnimated:self.navigationObject.animated];
|
||||||
|
} else {
|
||||||
|
[self markAsFinished];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -182,7 +184,11 @@
|
|||||||
break;
|
break;
|
||||||
case NavigationTypePopToRoot:
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user