Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hiding determinate progress dialogs doesn't stop animation threads #39

Open
nathancassano opened this issue Jun 13, 2019 · 0 comments
Open

Comments

@nathancassano
Copy link

nathancassano commented Jun 13, 2019

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant