Skip to content

Commit

Permalink
feat(android): fire touch events synchronously
Browse files Browse the repository at this point in the history
Fixes TIMOB-28286
  • Loading branch information
jquick-axway authored and sgtcoolguy committed Jan 19, 2021
1 parent 541f3f4 commit 59280d2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public boolean onFilterTouchEventForSecurity(MotionEvent event)
{
boolean isTouchAllowed = super.onFilterTouchEventForSecurity(event);
if (!isTouchAllowed) {
fireEvent(TiC.EVENT_TOUCH_FILTERED, dictFromEvent(event));
fireSyncEvent(TiC.EVENT_TOUCH_FILTERED, dictFromEvent(event));
}
return isTouchAllowed;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -961,13 +961,9 @@ public boolean fireEvent(String eventName, Object data, boolean bubbles)
if (data == null) {
data = new KrollDict();
}

// Set the "bubbles" property to indicate if the event needs to be bubbled.
if (data instanceof HashMap) {
((HashMap) data).put(TiC.PROPERTY_BUBBLES, bubbles);
}

// Dispatch the event to JavaScript which takes care of the bubbling.
return super.fireEvent(eventName, data);
}

Expand All @@ -977,12 +973,27 @@ public boolean fireEvent(String eventName, Object data, boolean bubbles)
@Override
public boolean fireEvent(String eventName, Object data)
{
// To remain compatible this override of fireEvent will always
// bubble the event to the parent view. It should eventually be deprecated
// in favor of using the fireEvent(String, Object, boolean) method.
return fireEvent(eventName, data, true);
}

@SuppressWarnings({ "rawtypes", "unchecked" })
public boolean fireSyncEvent(String eventName, Object data, boolean bubbles)
{
if (data == null) {
data = new KrollDict();
}
if (data instanceof HashMap) {
((HashMap) data).put(TiC.PROPERTY_BUBBLES, bubbles);
}
return super.fireSyncEvent(eventName, data);
}

@Override
public boolean fireSyncEvent(String eventName, Object data)
{
return fireSyncEvent(eventName, data, true);
}

/**
* @return The parent view proxy of this view proxy.
* @module.api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,7 @@ public boolean onScale(ScaleGestureDetector sgd)
data.put(TiC.EVENT_PROPERTY_VELOCITY, (sgd.getScaleFactor() - 1.0f) / timeDelta * 1000);
data.put(TiC.EVENT_PROPERTY_SOURCE, proxy);

return fireEvent(TiC.EVENT_PINCH, data);
return fireSyncEvent(TiC.EVENT_PINCH, data);
}
return false;
}
Expand Down Expand Up @@ -1808,7 +1808,7 @@ public boolean onTouch(View view, MotionEvent event)
String motionEvent = motionEvents.get(event.getAction());
if (motionEvent != null) {
if (proxy != null && proxy.hierarchyHasListener(motionEvent)) {
fireEvent(motionEvent, dictFromEvent(event));
fireSyncEvent(motionEvent, dictFromEvent(event));
}
}

Expand Down Expand Up @@ -2060,6 +2060,24 @@ public boolean fireEvent(String eventName, KrollDict data, boolean bubbles)
return proxy.fireEvent(eventName, data, bubbles);
}

public boolean fireSyncEvent(String eventName, KrollDict data)
{
return fireSyncEvent(eventName, data, true);
}

public boolean fireSyncEvent(String eventName, KrollDict data, boolean bubbles)
{
if (proxy == null) {
return false;
}
if (data == null && additionalEventData != null) {
data = new KrollDict(additionalEventData);
} else if (additionalEventData != null) {
data.putAll(additionalEventData);
}
return proxy.fireSyncEvent(eventName, data, bubbles);
}

protected void setOnLongClickListener(View view)
{
view.setOnLongClickListener(new OnLongClickListener() {
Expand Down

0 comments on commit 59280d2

Please sign in to comment.