Skip to content

Commit

Permalink
feat(android): fire bubbled-up events synchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
jquick-axway authored and sgtcoolguy committed Jan 19, 2021
1 parent 59280d2 commit 7c8ebe6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions android/runtime/common/src/js/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Object.defineProperty(EventEmitter.prototype, 'callHandler', {

// Bubble the events to the parent view if needed.
if (data.bubbles && !cancelBubble) {
handled = this._fireEventToParent(type, data) || handled;
handled = this._fireSyncEventToParent(type, data) || handled;
}

return handled;
Expand Down Expand Up @@ -92,7 +92,7 @@ Object.defineProperty(EventEmitter.prototype, 'emit', {

if (!this._events || !this._events[type] || !this.callHandler) {
if (data.bubbles && !data.cancelBubble) {
handled = this._fireEventToParent(type, data);
handled = this._fireSyncEventToParent(type, data);
}
return handled;
}
Expand All @@ -108,7 +108,7 @@ Object.defineProperty(EventEmitter.prototype, 'emit', {
}

} else if (data.bubbles && !data.cancelBubble) {
handled = this._fireEventToParent(type, data);
handled = this._fireSyncEventToParent(type, data);
}

return handled;
Expand Down
19 changes: 19 additions & 0 deletions android/titanium/src/java/org/appcelerator/kroll/KrollProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,25 @@ public boolean fireSyncEvent(String event, Object data, long maxTimeout)
}
}

/**
* Fires an event synchronously to the view who is next to receive the event.
*
* @param eventName event to send to the next view
* @param data the data to include in the event
* @return true if the event was handled
*/
@Kroll.method(name = "_fireSyncEventToParent")
public boolean fireSyncEventToParent(String eventName, Object data)
{
if (bubbleParent) {
KrollProxy parentProxy = getParentForBubbling();
if (parentProxy != null) {
return parentProxy.fireSyncEvent(eventName, data);
}
}
return false;
}

@SuppressWarnings({ "rawtypes", "unchecked" })
public boolean doFireEvent(String event, Object data)
{
Expand Down

0 comments on commit 7c8ebe6

Please sign in to comment.