mutualmobile / MMProgressHUD

An easy-to-use HUD interface with personality.
MIT License
705 stars 131 forks source link

Allow skipping of confirmation while retaining cancel block #14

Open vincentjames501 opened 10 years ago

vincentjames501 commented 10 years ago

First off I'd like to say this is an amazing project.

Is there anyway to skip the confirmation piece and go straight to success on user tap gesture?

My use case is simple. Show a 'Recording' HUD and then when the users taps the HUD it dismisses. It seems to me like there should a property such as dismisses on touch. Is there any way to do this with it's current implementation?

Thoughts?

vincentjames501 commented 10 years ago

I forgot to mention that something like this works, but it would be nice to be baked in.

...
self.dismissRecordingHUDRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(stopRecording)];
    [[MMProgressHUD sharedHUD].hud addGestureRecognizer:self.dismissRecordingHUDRecognizer];
...

- (void)stopRecording {
    [[MMProgressHUD sharedHUD].hud removeGestureRecognizer:self.dismissRecordingHUDRecognizer];
    [MMProgressHUD dismissWithSuccess:@"Succes"];
}
larsacus commented 10 years ago

The most generic way to do this would be for MMProgressHUD to expose the tap gesture recognizer and allow you to hook into it yourself (just so long as you didn't specify a cancel block when you displayed MMProgressHUD):

[[MMProgressHUD sharedHUD] tapGestureRecognizer] addTarget:self
                                                    action:@selector(stopRecording:)];

...

- (void)stopRecording {
  UITapGestureRecognizer *tapGesture = [[[MMProgressHUD sharedHUD] tapGestureRecognizer];
  [tapGesture removeTarget:self action:@selector(stopRecording:)];

  [MMProgressHUD showWithStatus:@"Saving Recording..."];

  // Do stuff to save recording.
  [MMProgressHUD dismissWithSuccess:@"Success"];
}

I wouldn't want to add a specific property like skipConfirmation or requiresConfirmation in order to keep the implementation and internal states generic enough. If enough people ask for it then that's a different story.