mutualmobile / MMProgressHUD

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

Flickering After Dismiss #26

Closed johnryan closed 10 years ago

johnryan commented 10 years ago

when using the 0.2.2 after dismissing the alert i see a bit of flickering on the view until i push the next view on to the navigation stack. Trying to get steps for reproduction.

johnryan commented 10 years ago

Just an update, it seems that if i try to chain them together, i.e. dismiss one alert and show one soon after (as the result of another async task), the screen either flickers, or the other progress HUD doesn't show at all.

larsacus commented 10 years ago

To clarify, when you say "view" in your first comment, are you talking about the view in your app's subview hierarchy, the progress hud background, or the progress hud itself?

johnryan commented 10 years ago

Sorry about that, I was referring to the dimming gray view applied to the window by the HUD. It just dims then returns to normal then dims again etc.

The flow is like this: URL request triggers loading HUD URL request finishes and dismisses HUD New URL request starts and TRIES to show the HUD. This starts the flickering until the second request completes and dismisses the HUD that never was fully presented.

Not sure if it is a threading issue or maybe that I tried to present a new HUD before the previous was finished dismissing.

larsacus commented 10 years ago

This should definitely be possible without flickering. If you nail down the issue, I'd love to entertain a pull request unless I get to it first.

:beer:

johnryan commented 10 years ago

sounds good, i'll look into it.

johnryan commented 10 years ago

I'm having a bit of trouble figuring this out...the methods seem to be firing in the right order...I attached a log of what is going on. I'll keep investigating but any help would be appreciated. Thanks.

Also here is the code i'm running:

[[MMProgressHUD sharedHUD] setOverlayMode:MMProgressHUDWindowOverlayModeLinear];
[MMProgressHUD setPresentationStyle:MMProgressHUDPresentationStyleExpand];
[MMProgressHUD showWithStatus:@"Loading..."];

//some stuff happens here...

[MMProgressHUD dismiss];
self.completionBlock();

then in the completionBlock

 [[MMProgressHUD sharedHUD] setOverlayMode:MMProgressHUDWindowOverlayModeLinear];
 [MMProgressHUD setPresentationStyle:MMProgressHUDPresentationStyleExpand];
 [MMProgressHUD showWithStatus:@"Logging In..."];

Annnd here are the logs that I get when setting MM_HUD_DEBUG to true

2014-05-20 15:23:59.285 TestApp[1233:60b] MMProgressHUDWindow [line 42]: Old Window: <UIWindow: 0x134d02980; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x1780598c0>; layer = <UIWindowLayer: 0x178037c60>>
2014-05-20 15:23:59.286 TestApp[1233:60b] MMProgressHUDWindow [line 42]: Old Window: <UIWindow: 0x134d02980; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x1780598c0>; layer = <UIWindowLayer: 0x178037c60>>
2014-05-20 15:23:59.288 TestApp[1233:60b] MMProgressHUDWindow [line 42]: Old Window: <UIWindow: 0x134d02980; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x1780598c0>; layer = <UIWindowLayer: 0x178037c60>>
2014-05-20 15:23:59.289 TestApp[1233:60b] MMProgressHUDWindow [line 42]: Old Window: <UIWindow: 0x134d02980; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x1780598c0>; layer = <UIWindowLayer: 0x178037c60>>
2014-05-20 15:23:59.289 TestApp[1233:60b] MMProgressHUDWindow [line 42]: Old Window: <UIWindow: 0x134d02980; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x1780598c0>; layer = <UIWindowLayer: 0x178037c60>>
2014-05-20 15:23:59.290 TestApp[1233:60b] MMProgressHUDWindow [line 42]: Old Window: <UIWindow: 0x134d02980; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x1780598c0>; layer = <UIWindowLayer: 0x178037c60>>
2014-05-20 15:23:59.291 TestApp[1233:60b] MMProgressHUDWindow [line 42]: Old Window: <UIWindow: 0x134d02980; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x1780598c0>; layer = <UIWindowLayer: 0x178037c60>>
2014-05-20 15:23:59.291 TestApp[1233:60b] MMProgressHUDWindow [line 42]: Old Window: <UIWindow: 0x134d02980; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x1780598c0>; layer = <UIWindowLayer: 0x178037c60>>
2014-05-20 15:23:59.292 TestApp[1233:60b] MMProgressHUDWindow [line 42]: Old Window: <UIWindow: 0x134d02980; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x1780598c0>; layer = <UIWindowLayer: 0x178037c60>>
2014-05-20 15:23:59.293 TestApp[1233:60b] MMProgressHUDWindow [line 42]: Old Window: <UIWindow: 0x134d02980; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x1780598c0>; layer = <UIWindowLayer: 0x178037c60>>
2014-05-20 15:23:59.293 TestApp[1233:60b] MMProgressHUDWindow [line 42]: Old Window: <UIWindow: 0x134d02980; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x1780598c0>; layer = <UIWindowLayer: 0x178037c60>>
2014-05-20 15:23:59.294 TestApp[1233:60b] MMProgressHUDWindow [line 42]: Old Window: <UIWindow: 0x134d02980; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x1780598c0>; layer = <UIWindowLayer: 0x178037c60>>
2014-05-20 15:23:59.304 TestApp[1233:60b] MMProgressHUD [line 609]: show animation started
2014-05-20 15:23:59.576 TestApp[1233:60b] MMProgressHUD [line 587]: Show animation ended: <MMHud: 0x134ecafc0; frame = (103 244; 115 81); autoresize = LM+RM+TM+BM; layer = <CALayer: 0x17042d740>>

2014-05-20 15:24:07.106 TestApp[1233:60b] MMProgressHUD [line 554]: Dismissing...
2014-05-20 15:24:07.107 TestApp[1233:60b] MMProgressHUD [line 653]: Dismiss animation started
2014-05-20 15:24:07.458 TestApp[1233:60b] MMProgressHUD [line 628]: Dismiss animation ended
2014-05-20 15:24:07.860 TestApp[1233:60b] MMProgressHUDWindow [line 77]: dealloc
2014-05-20 15:24:07.861 TestApp[1233:60b] MMProgressHUDViewController [line 113]: dealloc

2014-05-20 15:24:12.816 TestApp[1233:60b] MMProgressHUD [line 554]: Dismissing...
2014-05-20 15:24:12.817 TestApp[1233:60b] MMProgressHUD [line 653]: Dismiss animation started
2014-05-20 15:24:12.818 TestApp[1233:60b] MMProgressHUD [line 628]: Dismiss animation ended
2014-05-20 15:24:21.366 TestApp[1233:60b] MMProgressHUDWindow [line 42]: Old Window: <UIWindow: 0x134d02980; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x1780598c0>; layer = <UIWindowLayer: 0x178037c60>>
2014-05-20 15:24:21.367 TestApp[1233:60b] MMProgressHUDWindow [line 42]: Old Window: <UIWindow: 0x134d02980; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x1780598c0>; layer = <UIWindowLayer: 0x178037c60>>
2014-05-20 15:24:21.368 TestApp[1233:60b] MMProgressHUDWindow [line 42]: Old Window: <UIWindow: 0x134d02980; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x1780598c0>; layer = <UIWindowLayer: 0x178037c60>>
2014-05-20 15:24:21.368 TestApp[1233:60b] MMProgressHUDWindow [line 42]: Old Window: <UIWindow: 0x134d02980; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x1780598c0>; layer = <UIWindowLayer: 0x178037c60>>
2014-05-20 15:24:21.369 TestApp[1233:60b] MMProgressHUDWindow [line 42]: Old Window: <UIWindow: 0x134d02980; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x1780598c0>; layer = <UIWindowLayer: 0x178037c60>>
2014-05-20 15:24:21.369 TestApp[1233:60b] MMProgressHUDWindow [line 42]: Old Window: <UIWindow: 0x134d02980; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x1780598c0>; layer = <UIWindowLayer: 0x178037c60>>
2014-05-20 15:24:21.370 TestApp[1233:60b] MMProgressHUDWindow [line 42]: Old Window: <UIWindow: 0x134d02980; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x1780598c0>; layer = <UIWindowLayer: 0x178037c60>>
2014-05-20 15:24:21.370 TestApp[1233:60b] MMProgressHUDWindow [line 42]: Old Window: <UIWindow: 0x134d02980; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x1780598c0>; layer = <UIWindowLayer: 0x178037c60>>
2014-05-20 15:24:21.371 TestApp[1233:60b] MMProgressHUDWindow [line 42]: Old Window: <UIWindow: 0x134d02980; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x1780598c0>; layer = <UIWindowLayer: 0x178037c60>>
2014-05-20 15:24:21.371 TestApp[1233:60b] MMProgressHUDWindow [line 42]: Old Window: <UIWindow: 0x134d02980; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x1780598c0>; layer = <UIWindowLayer: 0x178037c60>>
2014-05-20 15:24:21.372 TestApp[1233:60b] MMProgressHUDWindow [line 42]: Old Window: <UIWindow: 0x134d02980; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x1780598c0>; layer = <UIWindowLayer: 0x178037c60>>
2014-05-20 15:24:21.372 TestApp[1233:60b] MMProgressHUDWindow [line 42]: Old Window: <UIWindow: 0x134d02980; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x1780598c0>; layer = <UIWindowLayer: 0x178037c60>>
2014-05-20 15:24:21.373 TestApp[1233:60b] MMProgressHUD [line 609]: show animation started
2014-05-20 15:24:21.634 TestApp[1233:60b] MMProgressHUD [line 587]: Show animation ended: <MMHud: 0x134ecafc0; frame = (103 243; 115 82); autoresize = LM+RM+TM+BM; layer = <CALayer: 0x17042d740>>
2014-05-20 15:24:29.618 TestApp[1233:60b] MMProgressHUD [line 554]: Dismissing...
2014-05-20 15:24:29.620 TestApp[1233:60b] MMProgressHUD [line 653]: Dismiss animation started
2014-05-20 15:24:29.661 TestApp[1233:60b] MMProgressHUDWindow [line 77]: dealloc
2014-05-20 15:24:29.668 TestApp[1233:60b] MMProgressHUDViewController [line 113]: dealloc
2014-05-20 15:24:29.668 TestApp[1233:60b] MMProgressHUD [line 628]: Dismiss animation ended

### THIS IS THE ANIMATION THAT NEVER SHOWS

2014-05-20 15:24:29.669 TestApp[1233:60b] MMProgressHUD [line 609]: show animation started
2014-05-20 15:24:29.670 TestApp[1233:60b] MMProgressHUD [line 587]: Show animation ended: <MMHud: 0x134ecafc0; frame = (103 243; 115 82); autoresize = LM+RM+TM+BM; layer = <CALayer: 0x17042d740>>
larsacus commented 10 years ago

Try it without setting the overlay mode and presentation style every time you call show

//setup somewhere initially
[[MMProgressHUD sharedHUD] setOverlayMode:MMProgressHUDWindowOverlayModeLinear];
[MMProgressHUD setPresentationStyle:MMProgressHUDPresentationStyleExpand];

//do some work, show HUD
[MMProgressHUD showWithStatus:@"Loading..."];

//some stuff happens here...

[MMProgressHUD dismiss];
self.completionBlock();

Then in the completionBlock:

 [MMProgressHUD showWithStatus:@"Logging In..."];

I might also suggest using MMProgressHUD's animation completion if you will be doing more HUD actions:

[[MMProgressHUD sharedHUD] setDismissAnimationCompletion:self.completionBlock];

If you don't really care about dismissing at all after your "Loading..." show call, then I would simply call the second showWithStatus:@"Logging In..." without calling dismiss. Taking all of this into account, all of your calls would now look like this:

[[MMProgressHUD sharedHUD] setOverlayMode:MMProgressHUDWindowOverlayModeLinear];
[MMProgressHUD setPresentationStyle:MMProgressHUDPresentationStyleExpand];
[MMProgressHUD showWithStatus:@"Loading..."];

//some stuff happens here, maybe asynchronously...

 [MMProgressHUD showWithStatus:@"Logging In..."];

//after login some time in the future, probably asynchronously:
if (loginSuccess) {
    [MMProgressHUD dismissWithSuccess:@"Logged in!"];
} else {
    [MMProgressHUD dismissWithError:@"Error logging in."];
}
johnryan commented 10 years ago

Not dismissing it did the trick. I'm going to do that for now but keep investigating. It looks like the queued animation code in MMProgressHUD+Animations should handle the case if there is a dismiss followed by a showWithStatus, so i'm not sure why that didn't work in the first place. Thanks for the help.

larsacus commented 10 years ago

You're right that the dismiss followed by an immediate show should work.

larsacus commented 10 years ago

This fix has finally been pushed up to cocoa pods in release 0.2.3 :beers: