Toast-PhoneGap-Plugin icon indicating copy to clipboard operation
Toast-PhoneGap-Plugin copied to clipboard

Android Toast callback on touch

Open lucapale opened this issue 8 years ago • 3 comments

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
  • [x] 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.
  • [x] 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

lucapale avatar Aug 01 '16 13:08 lucapale

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

EddyVerbruggen avatar Aug 11 '16 13:08 EddyVerbruggen

This appears to be a duplicate of #88

ds8k avatar Sep 14 '16 19:09 ds8k

@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?

rafaellop avatar Feb 19 '18 14:02 rafaellop