Permalink
Browse files

Popups calling error callback instead of crashing if view with passed…

… tagId not found

Summary:
The showPopup method has an error callback. For some reason, it is asserting in case the wrong tagId is passed instead of calling the error callback on Android.

Pass not existing tagId to showPopup method and make sure it is receiving an error in js instead of crashing in native on Android.

[ANDROID] [MINOR] showPopup method calls error callback instead of crashing on errors.
Closes #17550

Differential Revision: D6776014

Pulled By: hramos

fbshipit-source-id: 1d97b762818d1591018fd43556eb41c3fb491eb9
  • Loading branch information...
dryganets authored and facebook-github-bot committed Jan 23, 2018
1 parent 70d23e8 commit 0c18ec5b9c64613dbdcd4be9f80e470e9532483d
@@ -724,11 +724,13 @@ public synchronized void dispatchCommand(
* @param success will be called with the position of the selected item as the first argument, or
* no arguments if the menu is dismissed
*/
public synchronized void showPopupMenu(int reactTag, ReadableArray items, Callback success) {
public synchronized void showPopupMenu(int reactTag, ReadableArray items, Callback success,
Callback error) {
UiThreadUtil.assertOnUiThread();
View anchor = mTagsToViews.get(reactTag);
if (anchor == null) {
throw new JSApplicationIllegalArgumentException("Could not find view with tag " + reactTag);
error.invoke("Can't display popup. Could not find view with tag " + reactTag);
return;
}
PopupMenu popupMenu = new PopupMenu(getReactContextForView(reactTag), anchor);
@@ -266,20 +266,23 @@ public void execute() {
private final class ShowPopupMenuOperation extends ViewOperation {
private final ReadableArray mItems;
private final Callback mError;
private final Callback mSuccess;
public ShowPopupMenuOperation(
int tag,
ReadableArray items,
Callback error,
Callback success) {
super(tag);
mItems = items;
mError = error;
mSuccess = success;
}
@Override
public void execute() {
mNativeViewHierarchyManager.showPopupMenu(mTag, mItems, mSuccess);
mNativeViewHierarchyManager.showPopupMenu(mTag, mItems, mSuccess, mError);
}
}
@@ -651,7 +654,7 @@ public void enqueueShowPopupMenu(
ReadableArray items,
Callback error,
Callback success) {
mOperations.add(new ShowPopupMenuOperation(reactTag, items, success));
mOperations.add(new ShowPopupMenuOperation(reactTag, items, error, success));
}
public void enqueueCreateView(

0 comments on commit 0c18ec5

Please sign in to comment.