Event handler blocks rendering until completion

35 Views Asked by At

I made a Meteor/PhoneGap with Spacebars Android app and I want to show updates on the screen while it's doing work, but none of the UI changes I call in the event handler are actually shown. Here's what I mean:

I have a button on the screen for downloading a file. After the user taps the button I want a loading spinner to show, then hide after the download is complete. The behavior I'm seeing is the user clicks the button, then the app freezes up while downloading, then once download is complete the app unfreezes. Here's code for the download button's event handler:

'click [data-download-file]' (event, instance) {
        Spinner.open();
        cordova.plugins.fileDownloader.download(
            "https://myfile.com/file.txt",
            (success) => {
                Spinner.close();
            },
            (error) => {
                console.log(error);
                Spinner.close();
            }
        );
    }

Something about the cordova plugin is just blocking the rendering, because if I wrap the whole cordova call in a setTimeout() everything works as expected, but can't be a real solution. I know there has to be a correct way to do this.

0

There are 0 best solutions below