cordova-progressIndicator
cordova-progressIndicator copied to clipboard
Hiding determinate progress dialogs doesn't stop animation threads
When a determinate progress dialog is closed before it ends and another determinate dialog is opened then the two threads fight to control the progress meter.
Proposed Patch:
diff --git a/src/ios/ProgressIndicator.h b/src/ios/ProgressIndicator.h
index 8f7c28a..2270937 100644
--- a/src/ios/ProgressIndicator.h
+++ b/src/ios/ProgressIndicator.h
@@ -4,7 +4,7 @@
@interface ProgressIndicator: CDVPlugin {
}
-@property (nonatomic, assign) MBProgressHUD* progressIndicator;
+@property (nonatomic, weak) MBProgressHUD* progressIndicator;
-@end
\ No newline at end of file
+@end
diff --git a/src/ios/ProgressIndicator.m b/src/ios/ProgressIndicator.m
index 550b53a..17475ad 100644
--- a/src/ios/ProgressIndicator.m
+++ b/src/ios/ProgressIndicator.m
@@ -399,19 +399,24 @@ - (void)showMultiple:(CDVInvokedUrlCommand*)command {
- (void)hide:(CDVInvokedUrlCommand*)command
{
- if (!self.progressIndicator) {
- CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
- return;
- }
- [self.progressIndicator hide:YES];
+ if (!self.progressIndicator) {
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ return;
+ }
+
+ if ( self.progressIndicator.taskInProgress == YES )
+ self.progressIndicator.taskInProgress = NO;
+ else
+ [self.progressIndicator hide:YES];
+
self.progressIndicator = nil;
+
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@""];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
-
/**
* PROGRESS TASK EVENT
*/
@@ -420,11 +425,15 @@ - (void)progressTask:(NSNumber *)increment{
// get increment value
int _increment = [increment intValue];
+
+ MBProgressHUD* progressIndicator = self.progressIndicator;
float progress = 0.0f;
while (progress < 1.0f) {
+ if ( progressIndicator.taskInProgress == NO ) break;
+
progress += 0.01f;
- self.progressIndicator.progress = progress;
+ progressIndicator.progress = progress;
// increment in microseconds (100000mms = 1s)
usleep(_increment);