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

Make the next toast hiding the current one #50

Closed
tosrn opened this issue Aug 23, 2015 · 5 comments
Closed

Make the next toast hiding the current one #50

tosrn opened this issue Aug 23, 2015 · 5 comments

Comments

@tosrn
Copy link

tosrn commented Aug 23, 2015

Hello,

great plugin! I'm having some (noob) trouble with multiple toasts though (on Android).

I would like the next toast to erase / replace the previous one if it's still being shown. I tried using window.plugins.toast.hide(); before showing the new toast but it hides the previous AND next one (basicaly nothing appears)

Am I missing something?

@EddyVerbruggen
Copy link
Owner

Can you show the code which hides and shows the toast?

@tosrn
Copy link
Author

tosrn commented Aug 23, 2015

Sure, thanks for the fast answer!

(I'm also using this controller to play an audio file)

 $scope.play = function(src,message) {
        var media = new Media(src, function onSuccess() {
               // release the media resource once finished playing
               media.release();
            },
            function onError(e){
                console.log("error playing sound: " + JSON.stringify(e));
            });
         media.play();
         // TOAST
         window.plugins.toast.hide();
        $cordovaToast.show(message, 'long', 'bottom').then(function(success) {
            console.log("The toast was shown");
        }, function (error) {
            console.log("The toast was not shown due to " + error);
        });     
    };

@EddyVerbruggen
Copy link
Owner

I'm guessing you need to put that showLongBottom('txt') call in the successcallback of the hide function, since those Cordova functions are asynchronous:

..hide(function() {
  // ..show here
});

@tosrn
Copy link
Author

tosrn commented Aug 23, 2015

Sorry didn't managed to make it work.

Is that what you meant?

$cordovaToast.hide().then(function(success) {
          $cordovaToast.show(message, 'long', 'bottom');
        });

@EddyVerbruggen
Copy link
Owner

I don't think ngCordova supports the hide function, so try this (didn't test this code, just typed it here):

window.plugins.toast.hide(function() {
  // you're now in the succes callback handler of the 'hide' function
  $cordovaToast.show(message, 'long', 'bottom');
});

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

2 participants