Toast-PhoneGap-Plugin: Touch callback never triggers

Expected behaviour

the trigger event listed below should trigger.

Actual behaviour

The success is always called upon initializing the toast, and result returns a value of “ok”. result.event is never populated. The trigger event works if I set it to occur when the result value is “ok”, so whatever I’m doing wrong is specific to the code below. Any help or suggestions?

I’m seeing this behaviour on

Remove this hint: these checkboxes can be checked like this: [x]

  • [X ] iOS device
  • [ X] iOS sim
  • [ X] Android device
  • [ X] Android sim

Code Sample

Acts.prototype.ShowToast = function (st_message,st_duration,st_location,st_offset,st_opacity,st_backcolor,st_textcolor,st_textsize,st_cornerradius,st_hpadding,st_vpadding) {if(st_location === 0){st_location = “top”;} else if(st_location === 1){st_location = “center”;} else{st_location = “bottom”;} window[“plugins”][“toast”][“showWithOptions”]({ “message”: st_message, “duration”: st_duration, “position”: st_location, “addPixelsY”: st_offset, “data”: {“foo”:“bar”}, “styling”: { “opacity”: st_opacity, // 0.0 %28transparent) to 1.0 (opaque). Default 0.8 “backgroundColor”: st_backcolor, // make sure you use #RRGGBB. Default #333333 “textColor”: st_textcolor, // Ditto. Default #FFFFFF “textSize”: st_textsize, // Default is approx. 13. “cornerRadius”: st_cornerradius, // minimum is 0 (square). iOS default 20, Android default 100 “horizontalPadding”: st_hpadding, // iOS default 16, Android default 50 “verticalPadding”: st_vpadding // iOS default 12, Android default 30

}
},
// implement the success callback
function(result) {
    ToastMessage = result["event"];
        if (result && result["event"]) {

    if(result["event"] == 'hide')
            {
                ToastRuntime.trigger(cr.plugins_.locke_cordova_toast.prototype.cnds.OnToast, ToastInst);
            }
            else if(result["event"] == 'touch')
            {
            ToastRuntime.trigger(cr.plugins_.locke_cordova_toast.prototype.cnds.OnToastTouch, ToastInst);
          }
  }


},function(result1){
  ToastMessage = result1;
    ToastRuntime.trigger(cr.plugins_.locke_cordova_toast.prototype.cnds.OnToastFail, ToastInst);
}

); };

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Reactions: 2
  • Comments: 18 (5 by maintainers)

Most upvoted comments

I have the same problem, the touch event is not coming out for s7 edge.

So i tinkered in the Toast.java file for ANDROIDE located in: <app>/platforms/android/src/nl/xservices/plugins/Toast.java

I commented this entire line:

if (IS_AT_LEAST_LOLLIPOP) {
getViewGroup().setOnTouchListener(new View.OnTouchListener() {
  @Override
  public boolean onTouch(View view, MotionEvent motionEvent) {
	if (motionEvent.getAction() != MotionEvent.ACTION_DOWN) {
	  return false;
	}
	if (mostRecentToast == null || !mostRecentToast.getView().isShown()) {
	  getViewGroup().setOnTouchListener(null);
	  return false;
	}

	float w = mostRecentToast.getView().getWidth();
	float startX = (view.getWidth() / 2) - (w / 2);
	float endX = (view.getWidth() / 2) + (w / 2);

	float startY;
	float endY;

	float g = mostRecentToast.getGravity();
	float y = mostRecentToast.getYOffset();
	float h = mostRecentToast.getView().getHeight();

	if (g == GRAVITY_BOTTOM) {
	  startY = view.getHeight() - y - h;
	  endY = view.getHeight() - y;
	} else if (g == GRAVITY_CENTER) {
	  startY = (view.getHeight() / 2) + y - (h / 2);
	  endY = (view.getHeight() / 2) + y + (h / 2);
	} else {
	  // top
	  startY = y;
	  endY = y + h;
	}

	float tapX = motionEvent.getX();
	float tapY = motionEvent.getY();

	final boolean tapped = tapX >= startX && tapX <= endX &&
		tapY >= startY && tapY <= endY;

	return tapped && returnTapEvent("touch", msg, data, callbackContext);
  }
});
} else {
toast.getView().setOnTouchListener(new View.OnTouchListener() {
  @Override
  public boolean onTouch(View view, MotionEvent motionEvent) {
	return motionEvent.getAction() == MotionEvent.ACTION_DOWN && returnTapEvent("touch", msg, data, callbackContext);
  }
});
}

Replaced it with this:

toast.getView().setOnTouchListener(new View.OnTouchListener() {
  @Override
  public boolean onTouch(View view, MotionEvent motionEvent) {
	toast.cancel(); //new code
	return motionEvent.getAction() == MotionEvent.ACTION_DOWN && returnTapEvent("touch", msg, data, callbackContext);
  }
});

Now, I can receive the touch event.

Same issue here on multiple Android devices.

The touch event is correctly received in a Pixel_2_API_R emulator but that’s not the case for some physical devices (eg. Galaxy S9).

This issue is blocking my release to production 😿

I am having a similar issue where on some android (8 and 9) phones, the result from the callback after touching the toast has event set to “hide” instead of “touch”, though seems to work properly on iOS

I’m experiencing the same problem on a Samsung Galaxy S6 running Android 5.1.1, as well as an S7 Edge on 6.0.1.

However I’m not experiencing this on a Galaxy Avant running 4.4.2 or a Nexus 6P on 7.0. Coincidentally, these are the same devices that have an issue with #95