Skip to content

Commit

Permalink
Merge pull request #24 from mallorypaine/min-display-time
Browse files Browse the repository at this point in the history
Add minimumDisplayTime property
  • Loading branch information
JonasGessner committed Apr 14, 2015
2 parents 839beec + 2262053 commit 6e9ff19
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions JGProgressHUD/JGProgressHUD/JGProgressHUD.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,13 @@ typedef NS_ENUM(NSUInteger, JGProgressHUDInteractionType) {
- (void)setProgress:(float)progress animated:(BOOL)animated;


/**
Specify a minimum time that the HUD will be on-screen. Useful to prevent the HUD from flashing quickly on the screen when network operations complete more quickly than expected.
@b Default: 0.0.
*/
@property (nonatomic, assign) NSTimeInterval minimumDisplayTime;

/////////////
// Showing //
/////////////
Expand Down
14 changes: 14 additions & 0 deletions JGProgressHUD/JGProgressHUD/JGProgressHUD.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ @interface JGProgressHUD () {
BOOL _dismissAfterTransitionFinished;
BOOL _dismissAfterTransitionFinishedWithAnimation;

CFAbsoluteTime _displayTime;

JGProgressHUDIndicatorView *_indicatorViewAfterTransitioning;
}

Expand Down Expand Up @@ -336,6 +338,7 @@ - (void)cleanUpAfterPresentation {
self.hidden = NO;

_transitioning = NO;
_displayTime = CFAbsoluteTimeGetCurrent();

if (_indicatorViewAfterTransitioning) {
self.indicatorView = _indicatorViewAfterTransitioning;
Expand Down Expand Up @@ -397,6 +400,8 @@ - (void)showInRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated {

_transitioning = YES;

_displayTime = 0;

if ([self.delegate respondsToSelector:@selector(progressHUD:willPresentInView:)]) {
[self.delegate progressHUD:self willPresentInView:view];
}
Expand Down Expand Up @@ -443,6 +448,15 @@ - (void)dismissAnimated:(BOOL)animated {
return;
}

if (self.minimumDisplayTime > 0 && _displayTime > 0) {
CFAbsoluteTime displayedTime = CFAbsoluteTimeGetCurrent() - _displayTime;
if (displayedTime < self.minimumDisplayTime) {
NSTimeInterval delay = self.minimumDisplayTime - displayedTime;
[self dismissAfterDelay:delay animated:animated];
return;
}
}

_transitioning = YES;

if ([self.delegate respondsToSelector:@selector(progressHUD:willDismissFromView:)]) {
Expand Down

0 comments on commit 6e9ff19

Please sign in to comment.