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

Android Toast callback on touch #93

Open
2 of 7 tasks
lucapale opened this issue Aug 1, 2016 · 3 comments
Open
2 of 7 tasks

Android Toast callback on touch #93

lucapale opened this issue Aug 1, 2016 · 3 comments

Comments

@lucapale
Copy link

lucapale commented Aug 1, 2016

Expected behavior

Receive args.event data on Android like it works on iOS

Actual behavior

I receive only args = "OK"

I'm seeing this behaviour on

  • iOS device
  • iOS sim
  • Android device
  • Android sim

Hardware models

iPhone 5 (works) - Samsung SM-T355 (Android 5.1.1)

OS versions

(Android 5.1.1)

I'm not a dummy, so I've checked these

  • It happens on a fresh Cordova CLI project as well.
  • I'm waiting for deviceready to fire.
  • My JavaScript has no errors (window.onerror catches nothing).

So how can we reproduce this?

window.plugins.toast.showWithOptions(
                {
                    message: message,
                    duration: "long",
                    position: "bottom",
          styling: {
            backgroundColor: '#66B2FF',
            textColor: '#000000',
          }
                },
                //Success callback
                function(args) {
          console.log('cordovaToast: '+JSON.stringify(args));
          if (args && args.event == "touch") {
            //next function
          }
                }, 
                function(error) {
                    log('cordovaToast error: ', error);
                }
    );

Thanks,
Luca

@EddyVerbruggen
Copy link
Owner

I just tested this code on a 5.1.0 simulator which works fine..

08-11 09:21:48.433 1996-1996/io.cordova.hellocordova I/chromium: [INFO:CONSOLE(37)] "cordovaToast: {"event":"touch","message":"hey there"}", source: file:///android_asset/www/index.html (37)
  • Which plugin version is this?
  • Does it work correctly on other Android models (or simulators)?

@ds8k
Copy link

ds8k commented Sep 14, 2016

This appears to be a duplicate of #88

@rafaellop
Copy link

rafaellop commented Feb 19, 2018

@EddyVerbruggen
I've just found the same issue. In my case (maybe this is some hint) the touch event doesn't work when the toast code is inside event listener registered using `document.addEventListener(). For example:

document.addEventListener('onAdDismiss', function(data) {
        $timeout(function() {          
                if (window.plugins.toast) {
                    window.plugins.toast.showWithOptions({
                        message: 'Tap to remove ads',
                        duration: "long", // 2000 ms
                        position: "center",
                        styling: {
                          opacity: 0.75, // 0.0 (transparent) to 1.0 (opaque). Default 0.8
                          backgroundColor: '#FF4848', // make sure you use #RRGGBB. Default #333333
                          textColor: '#FFFBF0', // Ditto. Default #FFFFFF
                          textSize: 16, // Default is approx. 13.
                        }
                      },
                      function(result) {
                            console.log(angular.toJson(result));
                            if (result && result.event) {
                                if (result.event === 'touch') {
                                  console.log('Toast touched!');
                                }                          
                            }
                       })
            }                    
        }, 1000);
    });

In that case the touch event handler doesn't work, but the "hide" event comes and the console outputs it. properly.

If I use the same code from outside an event listener, touch works OK.

Maybe this is the reason for other people as well?

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

4 participants