Skip to content

Commit

Permalink
Fixed duplicated animation of same message
Browse files Browse the repository at this point in the history
  • Loading branch information
myell0w committed Jan 13, 2011
1 parent 6ef6d24 commit f191096
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions MTStatusBarOverlay.m
Original file line number Diff line number Diff line change
Expand Up @@ -537,16 +537,11 @@ - (void)postImmediateErrorMessage:(NSString *)message duration:(NSTimeInterval)d
}

- (void)postMessage:(NSString *)message type:(MTMessageType)messageType duration:(NSTimeInterval)duration animated:(BOOL)animated {
// don't show when message is empty
// don't duplicate animation if already displaying with text
// don't show if status bar is hidden
if (message == nil
|| (!self.reallyHidden && [self.visibleStatusLabel.text isEqualToString:message])
|| [UIApplication sharedApplication].statusBarHidden) {
// don't add to queue when message is empty
if (message == nil) {
return;
}


NSDictionary *messageDictionaryRepresentation = [NSDictionary dictionaryWithObjectsAndKeys:message, kMTStatusBarOverlayMessageKey,
[NSNumber numberWithInt:messageType], kMTStatusBarOverlayMessageTypeKey,
[NSNumber numberWithDouble:duration], kMTStatusBarOverlayDurationKey,
Expand Down Expand Up @@ -587,11 +582,10 @@ - (void)showNextMessage {
return;
}
}

// there is a next message, overlay is active
self.active = YES;


NSDictionary *nextMessageDictionary = nil;

// read out next message
Expand All @@ -603,7 +597,31 @@ - (void)showNextMessage {
MTMessageType messageType = (MTMessageType)[[nextMessageDictionary valueForKey:kMTStatusBarOverlayMessageTypeKey] intValue];
NSTimeInterval duration = (NSTimeInterval)[[nextMessageDictionary valueForKey:kMTStatusBarOverlayDurationKey] doubleValue];
BOOL animated = [[nextMessageDictionary valueForKey:kMTStatusBarOverlayAnimationKey] boolValue];


// don't show anything if status bar is hidden (queue gets cleared)
if([UIApplication sharedApplication].statusBarHidden) {
@synchronized(self.messageQueue) {
[self.messageQueue removeAllObjects];
}

self.active = NO;

return;
}

// don't duplicate animation if already displaying with text
if (!self.reallyHidden && [self.visibleStatusLabel.text isEqualToString:message]) {
// remove unneccesary message
@synchronized(self.messageQueue) {
[self.messageQueue removeLastObject];
}

// show the next message w/o delay
[self showNextMessage];

return;
}

// cancel previous hide- and clear requests
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(hide) object:nil];
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(clearHistory) object:nil];
Expand Down

0 comments on commit f191096

Please sign in to comment.