Skip to content

Commit

Permalink
Deprecate UIManager.{show,dismiss}PopupMenu
Browse files Browse the repository at this point in the history
Summary:
This API is better implemented as a component: PopupMenuAndroid. Please see the ancestor diff D52712758.

Changelog: [Android][Deprecated] Deprecate UIManager.showPopupMenu, and UIManager.dismissPopupMenu

Reviewed By: mdvacca

Differential Revision: D52887565

fbshipit-source-id: 42da6bdaa707395c5694ec8ae3eb77b64cdefb69
  • Loading branch information
RSNara authored and facebook-github-bot committed Jan 30, 2024
1 parent 35308a7 commit 8a8f74b
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 14 deletions.
44 changes: 31 additions & 13 deletions packages/react-native/Libraries/ReactNative/BridgelessUIManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const UIManagerJSOverridenAPIs = {
* In OSS, the New Architecture will just use the Fabric renderer, which uses
* different APIs.
*/
const UIManagerJSUnusedAPIs = {
const UIManagerJSUnusedInNewArchAPIs = {
createView: (
reactTag: ?number,
viewName: string,
Expand Down Expand Up @@ -155,6 +155,34 @@ const UIManagerJSUnusedAPIs = {
},
};

/**
* Leave unimplemented: These APIs are deprecated in UIManager. We will eventually remove
* 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.',
);
},
},
});

const UIManagerJSPlatformAPIs = Platform.select({
android: {
getConstantsForViewManager: (viewManagerName: string): ?Object => {
Expand Down Expand Up @@ -232,17 +260,6 @@ const UIManagerJSPlatformAPIs = Platform.select({

FabricUIManager.sendAccessibilityEvent(shadowNode, eventName);
},
showPopupMenu: (
reactTag: ?number,
items: Array<string>,
error: (error: Object) => void,
success: (event: string, selected?: number) => void,
): void => {
raiseSoftError('showPopupMenu');
},
dismissPopupMenu: (): void => {
raiseSoftError('dismissPopupMenu');
},
},
ios: {
/**
Expand Down Expand Up @@ -293,8 +310,9 @@ const UIManagerJSPlatformAPIs = Platform.select({

const UIManagerJS: UIManagerJSInterface & {[string]: any} = {
...UIManagerJSOverridenAPIs,
...UIManagerJSDeprecatedPlatformAPIs,
...UIManagerJSPlatformAPIs,
...UIManagerJSUnusedAPIs,
...UIManagerJSUnusedInNewArchAPIs,
getViewManagerConfig: (viewManagerName: string): mixed => {
if (getUIManagerConstants) {
const constants = getUIManagerConstantsCached();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -866,12 +866,17 @@ public synchronized void dispatchCommand(
/**
* 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();
Expand All @@ -894,7 +899,14 @@ public synchronized void showPopupMenu(
mPopupMenu.show();
}

/** Dismiss the last opened PopupMenu {@link PopupMenu}. */
/**
* 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,13 +750,18 @@ public void dispatchViewManagerCommand(
/**
* 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) {
Expand All @@ -766,6 +771,8 @@ public void showPopupMenu(int reactTag, ReadableArray items, Callback error, Cal
mOperationsQueue.enqueueShowPopupMenu(reactTag, items, error, success);
}

/** TODO(T175424986): Remove UIManager.dismissPopupMenu() in React Native v0.75. */
@Deprecated
public void dismissPopupMenu() {
mOperationsQueue.enqueueDismissPopupMenu();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,10 @@ public void dispatchCommand(int reactTag, String commandId, @Nullable ReadableAr
/**
* 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
Expand All @@ -626,11 +630,18 @@ public void dispatchCommand(int reactTag, String commandId, @Nullable ReadableAr
* 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,12 @@ public int getRetries() {
}
}

/**
* This is deprecated, please use the <PopupMenuAndroid /> component instead.
*
* <p>TODO(T175424986): Remove UIManager.showPopupMenu() in React Native v0.75.
*/
@Deprecated
private final class ShowPopupMenuOperation extends ViewOperation {

private final ReadableArray mItems;
Expand All @@ -362,6 +368,12 @@ public void execute() {
}
}

/**
* This is deprecated, please use the <PopupMenuAndroid /> component instead.
*
* <p>TODO(T175424986): Remove UIManager.dismissPopupMenu() in React Native v0.75.
*/
@Deprecated
private final class DismissPopupMenuOperation implements UIOperation {
@Override
public void execute() {
Expand Down Expand Up @@ -703,11 +715,23 @@ public void enqueueUpdateExtraData(int reactTag, Object extraData) {
mOperations.add(new UpdateViewExtraData(reactTag, extraData));
}

/**
* This is deprecated, please use the <PopupMenuAndroid /> component instead.
*
* <p>TODO(T175424986): Remove UIManager.showPopupMenu() in React Native v0.75.
*/
@Deprecated
public void enqueueShowPopupMenu(
int reactTag, ReadableArray items, Callback error, Callback success) {
mOperations.add(new ShowPopupMenuOperation(reactTag, items, error, success));
}

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

0 comments on commit 8a8f74b

Please sign in to comment.