diff --git a/action-sheet/README.md b/action-sheet/README.md index ea657acd4..7c402cd23 100644 --- a/action-sheet/README.md +++ b/action-sheet/README.md @@ -84,20 +84,20 @@ to select. #### ShowActionsResult -| Prop | Type | Description | Since | -| -------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- | -| **`index`** | number | The index of the clicked option (Zero-based), or -1 if the sheet was canceled. On iOS, if there is a button with ActionSheetButtonStyle.Cancel, and user clicks outside the sheet, the index of the cancel option is returned | 1.0.0 | -| **`canceled`** | boolean | True if sheet was canceled by user; False otherwise On Web, requires having @ionic/pwa-elements version 3.4.0 or higher. | 8.1.0 | +| Prop | Type | Description | Since | +| -------------- | -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- | +| **`index`** | number | The index of the clicked option (Zero-based), or -1 if the Action Sheet was canceled. On iOS, if there is a button with ActionSheetButtonStyle.Cancel, and user clicks outside the Action Sheet, the index of the Cancel button is returned. | 1.0.0 | +| **`canceled`** | boolean | True if the Action Sheet was canceled by user; False otherwise. On Web, requires having @ionic/pwa-elements version 3.4.0 or higher. | 8.1.0 | #### ShowActionsOptions -| Prop | Type | Description | Since | -| ---------------- | -------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- | -| **`title`** | string | The title of the Action Sheet. | 1.0.0 | -| **`message`** | string | A message to show under the title. This option is only supported on iOS. | 1.0.0 | -| **`options`** | ActionSheetButton[] | Options the user can choose from. | 1.0.0 | -| **`cancelable`** | boolean | If true, sheet is canceled when clicked outside; If false, it is not. By default, false. Not available on iOS, sheet is always cancelable by clicking outside of it. On Web, requires having @ionic/pwa-elements version 3.4.0 or higher. | 8.1.0 | +| Prop | Type | Description | Default | Since | +| ---------------- | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- | +| **`title`** | string | The title of the Action Sheet. | | 1.0.0 | +| **`message`** | string | A message to show under the title. This option is only supported on iOS. | | 1.0.0 | +| **`options`** | ActionSheetButton[] | Options the user can choose from. | | 1.0.0 | +| **`cancelable`** | boolean | If true, the Action Sheet is canceled when clicked outside; If false, it is not. On iOS, it's not available if there is a button with ActionSheetButtonStyle.Cancel, or on iOS 26+. In those cases, the Action Sheet is always cancelable by clicking outside of it. On Web, requires having @ionic/pwa-elements version 3.4.0 or higher. | false | 8.1.0 | #### ActionSheetButton @@ -114,10 +114,10 @@ to select. #### ActionSheetButtonStyle -| Members | Value | Description | Since | -| ----------------- | -------------------------- | ----------------------------------------------------------------------------------------------------------- | ----- | -| **`Default`** | 'DEFAULT' | Default style of the option. | 1.0.0 | -| **`Destructive`** | 'DESTRUCTIVE' | Style to use on destructive options. | 1.0.0 | -| **`Cancel`** | 'CANCEL' | Style to use on the option that cancels the Action Sheet. If used, should be on the latest availabe option. | 1.0.0 | +| Members | Value | Description | Since | +| ----------------- | -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- | +| **`Default`** | 'DEFAULT' | Default style of the option. | 1.0.0 | +| **`Destructive`** | 'DESTRUCTIVE' | Style to use on destructive options. | 1.0.0 | +| **`Cancel`** | 'CANCEL' | Style to use on the option that cancels the Action Sheet. If used, should be on the latest available option. On iOS 26+ is not displayed, the Action Sheet is cancelable by tapping outside. | 1.0.0 | diff --git a/action-sheet/android/src/main/java/com/capacitorjs/plugins/actionsheet/ActionSheetPlugin.java b/action-sheet/android/src/main/java/com/capacitorjs/plugins/actionsheet/ActionSheetPlugin.java index 808f0af6d..1868dd208 100644 --- a/action-sheet/android/src/main/java/com/capacitorjs/plugins/actionsheet/ActionSheetPlugin.java +++ b/action-sheet/android/src/main/java/com/capacitorjs/plugins/actionsheet/ActionSheetPlugin.java @@ -45,9 +45,7 @@ public void showActions(final PluginCall call) { implementation.setOnCancelListener(() -> resolve(call, -1)); } implementation.setOnSelectedListener((index) -> { - JSObject ret = new JSObject(); - ret.put("index", index); - call.resolve(ret); + resolve(call, index); implementation.dismiss(); }); implementation.show(getActivity().getSupportFragmentManager(), "capacitorModalsActionSheet"); diff --git a/action-sheet/ios/Sources/ActionSheetPlugin/ActionSheetPlugin.swift b/action-sheet/ios/Sources/ActionSheetPlugin/ActionSheetPlugin.swift index b4a2b83ff..638de78eb 100644 --- a/action-sheet/ios/Sources/ActionSheetPlugin/ActionSheetPlugin.swift +++ b/action-sheet/ios/Sources/ActionSheetPlugin/ActionSheetPlugin.swift @@ -33,14 +33,10 @@ public class ActionSheetPlugin: CAPPlugin, CAPBridgedPlugin, UIAdaptivePresentat buttonStyle = .cancel } let action = UIAlertAction(title: title, style: buttonStyle, handler: { [weak self] (_) in - if buttonStyle == .cancel { - call.actionSheetCanceled() - } else { - call.resolve([ - "index": index, - "canceled": false - ]) - } + call.resolve([ + "index": index, + "canceled": buttonStyle == .cancel + ]) self?.currentCall = nil }) alertActions.append(action) @@ -51,18 +47,19 @@ public class ActionSheetPlugin: CAPPlugin, CAPBridgedPlugin, UIAdaptivePresentat self?.setCenteredPopover(alertController) self?.bridge?.viewController?.present(alertController, animated: true) { if !hasCancellableButton { - self?.setupCancelationListerners(alertController, call) + self?.setupCancelationListeners(alertController, call) } } } } } - private func setupCancelationListerners(_ alertController: UIAlertController, _ call: CAPPluginCall) { + private func setupCancelationListeners(_ alertController: UIAlertController, _ call: CAPPluginCall) { + let cancelable = call.getBool("cancelable", false) if #available(iOS 26, *) { self.currentCall = call alertController.presentationController?.delegate = self - } else { + } else if cancelable { // For iOS versions below 26, setting the presentation controller delegate would result in a crash // "Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The presentation controller of an alert controller presenting as an alert must not have its delegate modified" // Hence, the alternative by adding a gesture recognizer (which only works for iOS versions below 26) @@ -70,8 +67,8 @@ public class ActionSheetPlugin: CAPPlugin, CAPBridgedPlugin, UIAdaptivePresentat alertController.dismiss(animated: true, completion: nil) call.actionSheetCanceled() } - let backroundView = alertController.view.superview?.subviews[0] - backroundView?.addGestureRecognizer(gestureRecognizer) + let backgroundView = alertController.view.superview?.subviews[0] + backgroundView?.addGestureRecognizer(gestureRecognizer) } } diff --git a/action-sheet/src/definitions.ts b/action-sheet/src/definitions.ts index 09b0470e2..d33c7dea3 100644 --- a/action-sheet/src/definitions.ts +++ b/action-sheet/src/definitions.ts @@ -23,12 +23,14 @@ export interface ShowActionsOptions { options: ActionSheetButton[]; /** - * If true, sheet is canceled when clicked outside; If false, it is not. By default, false. + * If true, the Action Sheet is canceled when clicked outside; If false, it is not. * - * Not available on iOS, sheet is always cancelable by clicking outside of it. + * On iOS, it's not available if there is a button with ActionSheetButtonStyle.Cancel, or on iOS 26+. + * In those cases, the Action Sheet is always cancelable by clicking outside of it. * * On Web, requires having @ionic/pwa-elements version 3.4.0 or higher. * + * @default false * @since 8.1.0 */ cancelable?: boolean; @@ -51,7 +53,8 @@ export enum ActionSheetButtonStyle { /** * Style to use on the option that cancels the Action Sheet. - * If used, should be on the latest availabe option. + * If used, should be on the latest available option. + * On iOS 26+ is not displayed, the Action Sheet is cancelable by tapping outside. * * @since 1.0.0 */ @@ -87,15 +90,15 @@ export interface ActionSheetButton { export interface ShowActionsResult { /** - * The index of the clicked option (Zero-based), or -1 if the sheet was canceled. + * The index of the clicked option (Zero-based), or -1 if the Action Sheet was canceled. * - * On iOS, if there is a button with ActionSheetButtonStyle.Cancel, and user clicks outside the sheet, the index of the cancel option is returned + * On iOS, if there is a button with ActionSheetButtonStyle.Cancel, and user clicks outside the Action Sheet, the index of the Cancel button is returned. * * @since 1.0.0 */ index: number; /** - * True if sheet was canceled by user; False otherwise + * True if the Action Sheet was canceled by user; False otherwise. * * On Web, requires having @ionic/pwa-elements version 3.4.0 or higher. * diff --git a/action-sheet/src/web.ts b/action-sheet/src/web.ts index fbb85264e..9031ee864 100644 --- a/action-sheet/src/web.ts +++ b/action-sheet/src/web.ts @@ -11,7 +11,7 @@ export class ActionSheetWeb extends WebPlugin implements ActionSheetPlugin { document.body.appendChild(actionSheet); } actionSheet.header = options.title; - actionSheet.cancelable = options.cancelable; + actionSheet.cancelable = options.cancelable ?? false; actionSheet.options = options.options; actionSheet.addEventListener('onSelection', async (e: any) => { const selection = e.detail;