Skip to content

Commit 0c18ec5

Browse files
dryganetsfacebook-github-bot
authored andcommittedJan 23, 2018
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
1 parent 70d23e8 commit 0c18ec5

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed
 

‎ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyManager.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -724,11 +724,13 @@ public synchronized void dispatchCommand(
724724
* @param success will be called with the position of the selected item as the first argument, or
725725
* no arguments if the menu is dismissed
726726
*/
727-
public synchronized void showPopupMenu(int reactTag, ReadableArray items, Callback success) {
727+
public synchronized void showPopupMenu(int reactTag, ReadableArray items, Callback success,
728+
Callback error) {
728729
UiThreadUtil.assertOnUiThread();
729730
View anchor = mTagsToViews.get(reactTag);
730731
if (anchor == null) {
731-
throw new JSApplicationIllegalArgumentException("Could not find view with tag " + reactTag);
732+
error.invoke("Can't display popup. Could not find view with tag " + reactTag);
733+
return;
732734
}
733735
PopupMenu popupMenu = new PopupMenu(getReactContextForView(reactTag), anchor);
734736

‎ReactAndroid/src/main/java/com/facebook/react/uimanager/UIViewOperationQueue.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -266,20 +266,23 @@ public void execute() {
266266
private final class ShowPopupMenuOperation extends ViewOperation {
267267

268268
private final ReadableArray mItems;
269+
private final Callback mError;
269270
private final Callback mSuccess;
270271

271272
public ShowPopupMenuOperation(
272273
int tag,
273274
ReadableArray items,
275+
Callback error,
274276
Callback success) {
275277
super(tag);
276278
mItems = items;
279+
mError = error;
277280
mSuccess = success;
278281
}
279282

280283
@Override
281284
public void execute() {
282-
mNativeViewHierarchyManager.showPopupMenu(mTag, mItems, mSuccess);
285+
mNativeViewHierarchyManager.showPopupMenu(mTag, mItems, mSuccess, mError);
283286
}
284287
}
285288

@@ -651,7 +654,7 @@ public void enqueueShowPopupMenu(
651654
ReadableArray items,
652655
Callback error,
653656
Callback success) {
654-
mOperations.add(new ShowPopupMenuOperation(reactTag, items, success));
657+
mOperations.add(new ShowPopupMenuOperation(reactTag, items, error, success));
655658
}
656659

657660
public void enqueueCreateView(

0 commit comments

Comments
 (0)
Please sign in to comment.