Skip to content

Commit

Permalink
Reimplement forcing message dismissal as in #113
Browse files Browse the repository at this point in the history
Thanks for the contribution @azrle. I had to reimplement the functionality because of the extensive changes we made meanwhile when working on 1.0
  • Loading branch information
dennisreimann committed Feb 23, 2014
1 parent 898c82b commit 4220b1e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
1 change: 0 additions & 1 deletion TSMessages/Classes/TSMessage+Private.h
Expand Up @@ -12,7 +12,6 @@

@interface TSMessage (Private)
+ (NSMutableDictionary *)design;
- (void)dismissCurrentMessage;
- (void)dismissMessage:(TSMessageView *)messageView;
- (void)dismissMessage:(TSMessageView *)messageView completion:(void (^)())completion;
- (TSMessageView *)currentMessage;
Expand Down
11 changes: 10 additions & 1 deletion TSMessages/Classes/TSMessage.h
Expand Up @@ -99,13 +99,22 @@ typedef void (^TSMessageCallback)(TSMessageView *messageView);
+ (void)addCustomDesignFromFileWithName:(NSString *)fileName;

/** Dismisses the current message. If another message is in the queue,
it will be displayed automatically.
it will be displayed automatically after the current one is dismissed.
@return YES if the current message was successfully dismissed.
NO if there is no current message to be dismissed.
*/
+ (BOOL)dismissCurrentMessage;

/** Dismisses the current message even if it is not fully displayed, yet.
If another message is in the queue, it will be displayed automatically
after the current one is dismissed.
@return YES if the current message was successfully dismissed.
NO if there is no current message to be dismissed.
*/
+ (BOOL)dismissCurrentMessageForce:(BOOL)force;

/** Indicates whether a message is currently being displayed.
@return YES if a message is currently being displayed.
Expand Down
16 changes: 11 additions & 5 deletions TSMessages/Classes/TSMessage.m
Expand Up @@ -108,17 +108,23 @@ + (void)displayOrEnqueueMessage:(TSMessageView *)messageView
}
}

+ (BOOL)dismissCurrentMessage
+ (BOOL)dismissCurrentMessageForce:(BOOL)force
{
if (![TSMessage sharedMessage].currentMessage) return NO;
TSMessageView *currentMessage = [TSMessage sharedMessage].currentMessage;

dispatch_async(dispatch_get_main_queue(), ^{
[[TSMessage sharedMessage] dismissCurrentMessage];
});
if (!currentMessage) return NO;
if (!currentMessage.isMessageFullyDisplayed && !force) return NO;

[[TSMessage sharedMessage] dismissCurrentMessage];

return YES;
}

+ (BOOL)dismissCurrentMessage
{
return [self dismissCurrentMessageForce:NO];
}

+ (BOOL)isDisplayingMessage
{
return !![TSMessage sharedMessage].currentMessage;
Expand Down
2 changes: 1 addition & 1 deletion TSMessages/Views/TSMessageView+Private.h
Expand Up @@ -13,7 +13,7 @@
@property (nonatomic, readonly) NSString *title;
@property (nonatomic, readonly) NSString *subtitle;
@property (nonatomic, readonly) CGPoint centerForDisplay;
@property (nonatomic, assign, getter = isMessageFullyDisplayed) BOOL messageFullyDisplayed;
@property (nonatomic, assign, getter=isMessageFullyDisplayed) BOOL messageFullyDisplayed;

- (void)prepareForDisplay;
@end
6 changes: 3 additions & 3 deletions TSMessages/Views/TSMessageView.h
Expand Up @@ -21,9 +21,6 @@
/** The view controller this message is displayed in */
@property (nonatomic, weak) UIViewController *viewController;

/** Is the message currenlty fully displayed? Is set as soon as the message is really fully visible */
@property (nonatomic, readonly) BOOL isMessageFullyDisplayed;

/** The duration of the displayed message. If it is 0.0, it will automatically be calculated */
@property (nonatomic, assign) CGFloat duration;

Expand Down Expand Up @@ -52,4 +49,7 @@

/** Displays the message permanently. */
- (void)displayPermanently;

/** Is the message currently fully displayed? Is set as soon as the message is really fully visible */
- (BOOL)isMessageFullyDisplayed;
@end
2 changes: 1 addition & 1 deletion TSMessages/Views/TSMessageView.m
Expand Up @@ -25,7 +25,7 @@ @interface TSMessageView () <UIGestureRecognizerDelegate>
@property (nonatomic) UISwipeGestureRecognizer *swipeRecognizer;
@property (nonatomic) TSBlurView *backgroundBlurView;
@property (nonatomic, copy) TSMessageCallback buttonCallback;
@property (nonatomic, assign, getter = isMessageFullyDisplayed) BOOL messageFullyDisplayed;
@property (nonatomic, getter=isMessageFullyDisplayed) BOOL messageFullyDisplayed;
@end

@implementation TSMessageView
Expand Down

0 comments on commit 4220b1e

Please sign in to comment.