Skip to content

Commit

Permalink
Remove UIManager.{show|dismiss}PopupMenu (#44096)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #44096

These Android only APIs have been deprecated and are being removed for 0.75 release.

Changelog:
[Android][Removed] - UIManager.showPopupMenu() and UIManager.dismissPopupMenu() have been removed

Reviewed By: RSNara

Differential Revision: D56041827

fbshipit-source-id: e2afebf55860f33d2c8d1887e865adb4dd555e6c
  • Loading branch information
alanleedev authored and facebook-github-bot committed Apr 18, 2024
1 parent 4fbc1f2 commit c631e93
Show file tree
Hide file tree
Showing 10 changed files with 1 addition and 268 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,27 +160,7 @@ const UIManagerJSUnusedInNewArchAPIs = {
* them from React Native.
*/
const UIManagerJSDeprecatedPlatformAPIs = Platform.select({
android: {
// TODO(T175424986): Remove UIManager.showPopupMenu() in React Native v0.75.
showPopupMenu: (
reactTag: number,
items: Array<string>,
error: (error: Object) => void,
success: (event: string, selected?: number) => void,
): void => {
raiseSoftError(
'showPopupMenu',
'Please use the <PopupMenuAndroid /> component instead.',
);
},
// TODO(T175424986): Remove UIManager.dismissPopupMenu() in React Native v0.75.
dismissPopupMenu: (): void => {
raiseSoftError(
'dismissPopupMenu',
'Please use the <PopupMenuAndroid /> component instead.',
);
},
},
android: {},
});

const UIManagerJSPlatformAPIs = Platform.select({
Expand Down
21 changes: 0 additions & 21 deletions packages/react-native/Libraries/ReactNative/UIManager.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,27 +89,6 @@ export interface UIManagerStatic {
| ((value: boolean) => void)
| undefined;

/**
* Used to display an Android PopupMenu. If a menu item is pressed, the success callback will
* be called with the following arguments:
*
* - item - the menu item.
* - index - index of the pressed item in array. Returns `undefined` if cancelled.
*
* To obtain a native node handle for a component, you can use
* `React.findNodeHandle(component)`.
*
* Note that this works only on Android
*/
showPopupMenu?:
| ((
node: number,
items: string[],
error: () => void /* currently unused */,
success: (item: string, index: number | undefined) => void,
) => void)
| undefined;

getViewManagerConfig: (name: string) => {
Commands: {[key: string]: number};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ module.exports = [
'clearJSResponder',
'configureNextLayoutAnimation',
'createView',
'dismissPopupMenu',
'dispatchViewManagerCommand',
'findSubviewIn',
'getConstantsForViewManager',
Expand All @@ -45,10 +44,8 @@ module.exports = [
'setChildren',
'setJSResponder',
'setLayoutAnimationEnabledExperimental',
'showPopupMenu',
'updateView',
'viewIsDescendantOf',
'PopupMenu',
'LazyViewManagersEnabled',
'ViewManagerNames',
'StyleConstants',
Expand Down
8 changes: 0 additions & 8 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -4257,7 +4257,6 @@ public class com/facebook/react/uimanager/NativeViewHierarchyManager {
protected final fun addRootViewGroup (ILandroid/view/View;)V
public fun clearJSResponder ()V
public fun createView (Lcom/facebook/react/uimanager/ThemedReactContext;ILjava/lang/String;Lcom/facebook/react/uimanager/ReactStylesDiffMap;)V
public fun dismissPopupMenu ()V
public fun dispatchCommand (IILcom/facebook/react/bridge/ReadableArray;)V
public fun dispatchCommand (ILjava/lang/String;Lcom/facebook/react/bridge/ReadableArray;)V
protected fun dropView (Landroid/view/View;)V
Expand All @@ -4274,7 +4273,6 @@ public class com/facebook/react/uimanager/NativeViewHierarchyManager {
public fun setChildren (ILcom/facebook/react/bridge/ReadableArray;)V
public fun setJSResponder (IIZ)V
public fun setLayoutAnimationEnabled (Z)V
public fun showPopupMenu (ILcom/facebook/react/bridge/ReadableArray;Lcom/facebook/react/bridge/Callback;Lcom/facebook/react/bridge/Callback;)V
public fun updateInstanceHandle (IJ)V
public fun updateLayout (IIIIII)V
public fun updateProperties (ILcom/facebook/react/uimanager/ReactStylesDiffMap;)V
Expand Down Expand Up @@ -4989,7 +4987,6 @@ public class com/facebook/react/uimanager/UIImplementation {
protected fun createRootShadowNode ()Lcom/facebook/react/uimanager/ReactShadowNode;
protected fun createShadowNode (Ljava/lang/String;)Lcom/facebook/react/uimanager/ReactShadowNode;
public fun createView (ILjava/lang/String;ILcom/facebook/react/bridge/ReadableMap;)V
public fun dismissPopupMenu ()V
public fun dispatchViewManagerCommand (IILcom/facebook/react/bridge/ReadableArray;)V
public fun dispatchViewManagerCommand (ILjava/lang/String;Lcom/facebook/react/bridge/ReadableArray;)V
public fun dispatchViewUpdates (I)V
Expand Down Expand Up @@ -5025,7 +5022,6 @@ public class com/facebook/react/uimanager/UIImplementation {
public fun setLayoutUpdateListener (Lcom/facebook/react/uimanager/UIImplementation$LayoutUpdateListener;)V
public fun setViewHierarchyUpdateDebugListener (Lcom/facebook/react/uimanager/debug/NotThreadSafeViewHierarchyUpdateDebugListener;)V
public fun setViewLocalData (ILjava/lang/Object;)V
public fun showPopupMenu (ILcom/facebook/react/bridge/ReadableArray;Lcom/facebook/react/bridge/Callback;Lcom/facebook/react/bridge/Callback;)V
public fun synchronouslyUpdateViewOnUIThread (ILcom/facebook/react/uimanager/ReactStylesDiffMap;)V
public fun updateNodeSize (III)V
public fun updateRootView (III)V
Expand Down Expand Up @@ -5069,7 +5065,6 @@ public class com/facebook/react/uimanager/UIManagerModule : com/facebook/react/b
public fun configureNextLayoutAnimation (Lcom/facebook/react/bridge/ReadableMap;Lcom/facebook/react/bridge/Callback;Lcom/facebook/react/bridge/Callback;)V
public static fun createConstants (Ljava/util/List;Ljava/util/Map;Ljava/util/Map;)Ljava/util/Map;
public fun createView (ILjava/lang/String;ILcom/facebook/react/bridge/ReadableMap;)V
public fun dismissPopupMenu ()V
public fun dispatchCommand (IILcom/facebook/react/bridge/ReadableArray;)V
public fun dispatchCommand (ILjava/lang/String;Lcom/facebook/react/bridge/ReadableArray;)V
public fun dispatchViewManagerCommand (ILcom/facebook/react/bridge/Dynamic;Lcom/facebook/react/bridge/ReadableArray;)V
Expand Down Expand Up @@ -5113,7 +5108,6 @@ public class com/facebook/react/uimanager/UIManagerModule : com/facebook/react/b
public fun setLayoutAnimationEnabledExperimental (Z)V
public fun setViewHierarchyUpdateDebugListener (Lcom/facebook/react/uimanager/debug/NotThreadSafeViewHierarchyUpdateDebugListener;)V
public fun setViewLocalData (ILjava/lang/Object;)V
public fun showPopupMenu (ILcom/facebook/react/bridge/ReadableArray;Lcom/facebook/react/bridge/Callback;Lcom/facebook/react/bridge/Callback;)V
public fun startSurface (Landroid/view/View;Ljava/lang/String;Lcom/facebook/react/bridge/WritableMap;II)I
public fun stopSurface (I)V
public fun synchronouslyUpdateViewOnUIThread (ILcom/facebook/react/bridge/ReadableMap;)V
Expand Down Expand Up @@ -5144,7 +5138,6 @@ public class com/facebook/react/uimanager/UIViewOperationQueue {
public fun enqueueClearJSResponder ()V
public fun enqueueConfigureLayoutAnimation (Lcom/facebook/react/bridge/ReadableMap;Lcom/facebook/react/bridge/Callback;)V
public fun enqueueCreateView (Lcom/facebook/react/uimanager/ThemedReactContext;ILjava/lang/String;Lcom/facebook/react/uimanager/ReactStylesDiffMap;)V
public fun enqueueDismissPopupMenu ()V
public fun enqueueDispatchCommand (IILcom/facebook/react/bridge/ReadableArray;)V
public fun enqueueDispatchCommand (ILjava/lang/String;Lcom/facebook/react/bridge/ReadableArray;)V
public fun enqueueFindTargetForTouch (IFFLcom/facebook/react/bridge/Callback;)V
Expand All @@ -5157,7 +5150,6 @@ public class com/facebook/react/uimanager/UIViewOperationQueue {
public fun enqueueSetChildren (ILcom/facebook/react/bridge/ReadableArray;)V
public fun enqueueSetJSResponder (IIZ)V
public fun enqueueSetLayoutAnimationEnabled (Z)V
public fun enqueueShowPopupMenu (ILcom/facebook/react/bridge/ReadableArray;Lcom/facebook/react/bridge/Callback;Lcom/facebook/react/bridge/Callback;)V
public fun enqueueUIBlock (Lcom/facebook/react/uimanager/UIBlock;)V
protected fun enqueueUIOperation (Lcom/facebook/react/uimanager/UIViewOperationQueue$UIOperation;)V
public fun enqueueUpdateExtraData (ILjava/lang/Object;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
import android.graphics.RectF;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.PopupMenu;
import androidx.annotation.Nullable;
import com.facebook.common.logging.FLog;
import com.facebook.react.R;
Expand Down Expand Up @@ -81,7 +78,6 @@ public class NativeViewHierarchyManager {
private final RectF mBoundingBox = new RectF();

private boolean mLayoutAnimationEnabled;
private PopupMenu mPopupMenu;
private HashMap<Integer, Set<Integer>> mPendingDeletionsForTag;

public NativeViewHierarchyManager(ViewManagerRegistry viewManagers) {
Expand Down Expand Up @@ -862,85 +858,6 @@ public synchronized void dispatchCommand(
viewManager.receiveCommand(view, commandId, args);
}

/**
* Show a {@link PopupMenu}.
*
* <p>This is deprecated, please use the <PopupMenuAndroid /> component instead.
*
* <p>TODO(T175424986): Remove UIManager.showPopupMenu() in React Native v0.75.
*
* @param reactTag the tag of the anchor view (the PopupMenu is displayed next to this view); this
* needs to be the tag of a native view (shadow views can not be anchors)
* @param items the menu items as an array of strings
* @param success will be called with the position of the selected item as the first argument, or
* no arguments if the menu is dismissed
*/
@Deprecated
public synchronized void showPopupMenu(
int reactTag, ReadableArray items, Callback success, Callback error) {
UiThreadUtil.assertOnUiThread();
View anchor = mTagsToViews.get(reactTag);
if (anchor == null) {
error.invoke("Can't display popup. Could not find view with tag " + reactTag);
return;
}
mPopupMenu = new PopupMenu(getReactContextForView(reactTag), anchor);

Menu menu = mPopupMenu.getMenu();
for (int i = 0; i < items.size(); i++) {
menu.add(Menu.NONE, Menu.NONE, i, items.getString(i));
}

PopupMenuCallbackHandler handler = new PopupMenuCallbackHandler(success);
mPopupMenu.setOnMenuItemClickListener(handler);
mPopupMenu.setOnDismissListener(handler);

mPopupMenu.show();
}

/**
* This is deprecated, please use the <PopupMenuAndroid /> component instead.
*
* <p>TODO(T175424986): Remove UIManager.dismissPopupMenu() in React Native v0.75.
*
* <p>Dismiss the last opened PopupMenu {@link PopupMenu}.
*/
@Deprecated
public void dismissPopupMenu() {
if (mPopupMenu != null) {
mPopupMenu.dismiss();
}
}

private static class PopupMenuCallbackHandler
implements PopupMenu.OnMenuItemClickListener, PopupMenu.OnDismissListener {

final Callback mSuccess;
boolean mConsumed = false;

private PopupMenuCallbackHandler(Callback success) {
mSuccess = success;
}

@Override
public void onDismiss(PopupMenu menu) {
if (!mConsumed) {
mSuccess.invoke(UIManagerModuleConstants.ACTION_DISMISSED);
mConsumed = true;
}
}

@Override
public boolean onMenuItemClick(MenuItem item) {
if (!mConsumed) {
mSuccess.invoke(UIManagerModuleConstants.ACTION_ITEM_SELECTED, item.getOrder());
mConsumed = true;
return true;
}
return false;
}
}

/**
* @return Themed React context for view with a given {@param reactTag} - it gets the context
* directly from the view using {@link View#getContext}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,36 +741,6 @@ public void dispatchViewManagerCommand(
mOperationsQueue.enqueueDispatchCommand(reactTag, commandId, commandArgs);
}

/**
* Show a PopupMenu.
*
* <p>This is deprecated, please use the <PopupMenuAndroid /> component instead.
*
* <p>TODO(T175424986): Remove UIManager.showPopupMenu() in React Native v0.75.
*
* @param reactTag the tag of the anchor view (the PopupMenu is displayed next to this view); this
* needs to be the tag of a native view (shadow views can not be anchors)
* @param items the menu items as an array of strings
* @param error will be called if there is an error displaying the menu
* @param success will be called with the position of the selected item as the first argument, or
* no arguments if the menu is dismissed
*/
@Deprecated
public void showPopupMenu(int reactTag, ReadableArray items, Callback error, Callback success) {
boolean viewExists = checkOrAssertViewExists(reactTag, "showPopupMenu");
if (!viewExists) {
return;
}

mOperationsQueue.enqueueShowPopupMenu(reactTag, items, error, success);
}

/** TODO(T175424986): Remove UIManager.dismissPopupMenu() in React Native v0.75. */
@Deprecated
public void dismissPopupMenu() {
mOperationsQueue.enqueueDismissPopupMenu();
}

public void sendAccessibilityEvent(int tag, int eventType) {
mOperationsQueue.enqueueSendAccessibilityEvent(tag, eventType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,37 +615,6 @@ public void dispatchCommand(int reactTag, String commandId, @Nullable ReadableAr
mUIImplementation.dispatchViewManagerCommand(reactTag, commandId, commandArgs);
}

/**
* Show a PopupMenu.
*
* <p>This is deprecated, please use the <PopupMenuAndroid /> component instead.
*
* <p>TODO(T175424986): Remove UIManager.showPopupMenu() in React Native v0.75.
*
* @param reactTag the tag of the anchor view (the PopupMenu is displayed next to this view); this
* needs to be the tag of a native view (shadow views can not be anchors)
* @param items the menu items as an array of strings
* @param error will be called if there is an error displaying the menu
* @param success will be called with the position of the selected item as the first argument, or
* no arguments if the menu is dismissed
*/
@ReactMethod
@Deprecated
public void showPopupMenu(int reactTag, ReadableArray items, Callback error, Callback success) {
mUIImplementation.showPopupMenu(reactTag, items, error, success);
}

/**
* This is deprecated, please use the <PopupMenuAndroid /> component instead.
*
* <p>TODO(T175424986): Remove UIManager.dismissPopupMenu() in React Native v0.75.
*/
@ReactMethod
@Deprecated
public void dismissPopupMenu() {
mUIImplementation.dismissPopupMenu();
}

/**
* LayoutAnimation API on Android is currently experimental. Therefore, it needs to be enabled
* explicitly in order to avoid regression in existing application written for iOS using this API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ public static Map<String, Object> getConstants() {
"unspecified",
PointerEvents.AUTO.ordinal())));

constants.put(
"PopupMenu",
MapBuilder.of(
ACTION_DISMISSED, ACTION_DISMISSED, ACTION_ITEM_SELECTED, ACTION_ITEM_SELECTED));

constants.put(
"AccessibilityEventTypes",
MapBuilder.of(
Expand Down
Loading

0 comments on commit c631e93

Please sign in to comment.