From 89c7be890b0dcef72e465b70314ac47ca5ca0280 Mon Sep 17 00:00:00 2001 From: Lorenzo Pieri <13508373+LRNZ09@users.noreply.github.com> Date: Mon, 9 Oct 2023 17:16:27 -0700 Subject: [PATCH] Add typings for dismissActionSheet method (#40012) Summary: This pull request addresses two key issues. Firstly, it adds a missing docstring to the `dismissActionSheet` function within the `ActionSheetIOS` object. Secondly, it introduces TypeScript typings for the `dismissActionSheet` function. ## Changelog: [iOS] [Added] - Add missing docstring to the `dismissActionSheet` function in `ActionSheetIOS`. [iOS] [Added] - Add TypeScript typings for the `dismissActionSheet` function in `ActionSheetIOS`. Pull Request resolved: https://github.com/facebook/react-native/pull/40012 Test Plan: To ensure the code is solid, I followed these steps: 1. Ran Flow to verify that there were no errors. 2. Added a TypeScript test related to the `dismissActionSheet` function to ensure it's typed as expected. Reviewed By: NickGerleman Differential Revision: D50097458 Pulled By: arushikesarwani94 fbshipit-source-id: 63348239dfe19e3a07f94e5a7b59ae43a47c1975 --- .../Libraries/ActionSheetIOS/ActionSheetIOS.d.ts | 6 ++++++ .../react-native/Libraries/ActionSheetIOS/ActionSheetIOS.js | 4 ++++ packages/react-native/types/__typetests__/index.tsx | 3 +++ 3 files changed, 13 insertions(+) diff --git a/packages/react-native/Libraries/ActionSheetIOS/ActionSheetIOS.d.ts b/packages/react-native/Libraries/ActionSheetIOS/ActionSheetIOS.d.ts index 89bdd373239..bafdeb65e42 100644 --- a/packages/react-native/Libraries/ActionSheetIOS/ActionSheetIOS.d.ts +++ b/packages/react-native/Libraries/ActionSheetIOS/ActionSheetIOS.d.ts @@ -74,6 +74,12 @@ export interface ActionSheetIOSStatic { failureCallback: (error: Error) => void, successCallback: (success: boolean, method: string) => void, ) => void; + + /** + * Dismisses the most upper iOS action sheet presented, if no action sheet is + * present a warning is displayed. + */ + dismissActionSheet: () => void; } export const ActionSheetIOS: ActionSheetIOSStatic; diff --git a/packages/react-native/Libraries/ActionSheetIOS/ActionSheetIOS.js b/packages/react-native/Libraries/ActionSheetIOS/ActionSheetIOS.js index b5959aca24f..5366c0ccc2c 100644 --- a/packages/react-native/Libraries/ActionSheetIOS/ActionSheetIOS.js +++ b/packages/react-native/Libraries/ActionSheetIOS/ActionSheetIOS.js @@ -145,6 +145,10 @@ const ActionSheetIOS = { ); }, + /** + * Dismisses the most upper iOS action sheet presented, if no action sheet is + * present a warning is displayed. + */ dismissActionSheet: () => { invariant(RCTActionSheetManager, "ActionSheetManager doesn't exist"); if (typeof RCTActionSheetManager.dismissActionSheet === 'function') { diff --git a/packages/react-native/types/__typetests__/index.tsx b/packages/react-native/types/__typetests__/index.tsx index d7382b98b79..a7f8250e25d 100644 --- a/packages/react-native/types/__typetests__/index.tsx +++ b/packages/react-native/types/__typetests__/index.tsx @@ -2115,4 +2115,7 @@ const ActionSheetIOSTest = () => { }, () => undefined, ); + + // test dismissActionSheet method + ActionSheetIOS.dismissActionSheet(); };