TSMessages icon indicating copy to clipboard operation
TSMessages copied to clipboard

Fix bug: User tap on notif banner with callback cannot dismiss it

Open Kjuly opened this issue 10 years ago • 4 comments

It's for the issue mentioned in #179.

Kjuly avatar Nov 18 '14 02:11 Kjuly

Could you please briefly explain what you've changed and why?

KrauseFx avatar Nov 18 '14 09:11 KrauseFx

When i set callback for the message like below:

[TSMessage showNotificationInViewController:yourViewController
                                              title:@"title"
                                           subtitle:@"subtitle"
                                              image:nil
                                               type:TSMessageNotificationTypeSuccess
                                           duration:TSMessageNotificationDurationAutomatic
                                           callback:^{
                                               // here do whatever u want after user tapped the banner
                                           }
                                        buttonTitle:nil
                                     buttonCallback:nil
                                         atPosition:TSMessageNotificationPositionTop
                               canBeDismissedByUser:YES];

the tap action that generated by canBeDismissedByUser:YES will be overrode by callback's (which means, it'll invoke -handleTap instead of -fadeMeOut when user tapped on message), that'll leads the notification banner cannot dismiss. Because -handleTap has not implement fade out action.

if (dismissingEnabled) {
    UISwipeGestureRecognizer *gestureRec = [[UISwipeGestureRecognizer alloc] initWithTarget:self
                                                                                     action:@selector(fadeMeOut)];
    [gestureRec setDirection:(self.messagePosition == TSMessageNotificationPositionTop ?
                                          UISwipeGestureRecognizerDirectionUp :
                                          UISwipeGestureRecognizerDirectionDown)];
    [self addGestureRecognizer:gestureRec];

    UITapGestureRecognizer *tapRec = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                                             action:@selector(fadeMeOut)];
    [self addGestureRecognizer:tapRec];
}

if (self.callback) {
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
    tapGesture.delegate = self;
    [self addGestureRecognizer:tapGesture];
}

Here, just invoke the callback block, no action to fade out the banner.

- (void)handleTap:(UITapGestureRecognizer *)tapGesture
{
    if (tapGesture.state == UIGestureRecognizerStateRecognized)
    {
        if (self.callback)
        {
            self.callback();
        }
    }
}

Kjuly avatar Nov 18 '14 11:11 Kjuly

YES, User tap on notif banner with callback cannot dismiss it, i encounter this issue too, please update pods, thanks very much~

lukewcn avatar Dec 21 '14 10:12 lukewcn

Same issue for me, sorry for the duplicate (#201)

kevinrenskers avatar Dec 22 '14 15:12 kevinrenskers