cruffenach / CRToast

A modern iOS toast view that can fit your notification needs
MIT License
4.17k stars 463 forks source link

Hooking addNotification #158

Closed jadar closed 9 years ago

jadar commented 9 years ago

I want to make a notification that would inform the user with an activity indicator when that application is loading data. When the data is done loading, presenting a success notification would automatically dismiss all notifications with the "loading" identifier.

I'm thinking the best way to go about this would be to subclass CRToastManager; but CRToastManager only exposes class methods. Would it be a good idea to implementing a subclassing design similar to UIGestureRecognizer–where there is a Subclass header which declares the "protected" methods?

dmiedema commented 9 years ago

So I've been thinking about this some and I'm not sure a subclassing pattern like that used in UIGestureRecognizer makes sense. With gesture recognizers you usually have multiple since there are multiple types of gestures that can be done and different contexts for each gesture. I'm not sure the same pattern applies to something like a toast notification manager.

As it stands right now, in master you can set notification identifiers and dismiss all notifications with an identifier. You could create an intermediate layer in between what your class calls and CRToast so that when you send a success notification it automatically dismisses all loading notifications.

For example,

@implementation ToastManager: NSObject {
+ (void)showSuccessNotification(message: String) {
    [CRToastManager dismissAllNotificationsWithIdentifier:@"Loading.ToastIdentifier" animated:YES];
    [CRToastManager showNotificationWithMessage:@"Loaded!"];
}
@end

(just kind of typed that in so there are probably typos/syntax errors)

jadar commented 9 years ago

Yes, that solution work out alright.