From 2018f7823cc25ea39c3533772512d221d2dba926 Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Tue, 1 Mar 2022 16:06:45 +0100 Subject: [PATCH] feat(action-sheet): Make title optional (#805) --- .../capacitorjs/plugins/actionsheet/ActionSheet.java | 12 +++++++----- .../plugins/actionsheet/ActionSheetPlugin.java | 4 ---- action-sheet/ios/Plugin/ActionSheet.swift | 2 +- action-sheet/ios/Plugin/ActionSheetPlugin.swift | 7 ++----- action-sheet/src/definitions.ts | 2 +- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/action-sheet/android/src/main/java/com/capacitorjs/plugins/actionsheet/ActionSheet.java b/action-sheet/android/src/main/java/com/capacitorjs/plugins/actionsheet/ActionSheet.java index 2690ea396..13a78f11a 100644 --- a/action-sheet/android/src/main/java/com/capacitorjs/plugins/actionsheet/ActionSheet.java +++ b/action-sheet/android/src/main/java/com/capacitorjs/plugins/actionsheet/ActionSheet.java @@ -86,11 +86,13 @@ public void setupDialog(Dialog dialog, int style) { LinearLayout layout = new LinearLayout(getContext()); layout.setOrientation(LinearLayout.VERTICAL); layout.setPadding(layoutPaddingPx16, layoutPaddingPx16, layoutPaddingPx16, layoutPaddingPx16); - TextView ttv = new TextView(getContext()); - ttv.setTextColor(Color.parseColor("#757575")); - ttv.setPadding(layoutPaddingPx8, layoutPaddingPx8, layoutPaddingPx8, layoutPaddingPx8); - ttv.setText(title); - layout.addView(ttv); + if (title != null) { + TextView ttv = new TextView(getContext()); + ttv.setTextColor(Color.parseColor("#757575")); + ttv.setPadding(layoutPaddingPx8, layoutPaddingPx8, layoutPaddingPx8, layoutPaddingPx8); + ttv.setText(title); + layout.addView(ttv); + } for (int i = 0; i < options.length; i++) { final int optionIndex = i; 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 4c62a8ae7..7ca88b8e4 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 @@ -20,10 +20,6 @@ public class ActionSheetPlugin extends Plugin { public void showActions(final PluginCall call) { String title = call.getString("title"); JSArray options = call.getArray("options"); - if (title == null) { - call.reject("Must supply a title"); - return; - } if (options == null) { call.reject("Must supply options"); return; diff --git a/action-sheet/ios/Plugin/ActionSheet.swift b/action-sheet/ios/Plugin/ActionSheet.swift index 72a18211d..ceeff00fd 100644 --- a/action-sheet/ios/Plugin/ActionSheet.swift +++ b/action-sheet/ios/Plugin/ActionSheet.swift @@ -3,7 +3,7 @@ import UIKit @objc public class ActionSheet: NSObject { - @objc public func buildActionSheet(title: String, message: String, actions: [UIAlertAction]) -> UIAlertController { + @objc public func buildActionSheet(title: String?, message: String?, actions: [UIAlertAction]) -> UIAlertController { let controller = UIAlertController(title: title, message: message, preferredStyle: .actionSheet) for action in actions { controller.addAction(action) diff --git a/action-sheet/ios/Plugin/ActionSheetPlugin.swift b/action-sheet/ios/Plugin/ActionSheetPlugin.swift index 140b2b155..8b044478d 100644 --- a/action-sheet/ios/Plugin/ActionSheetPlugin.swift +++ b/action-sheet/ios/Plugin/ActionSheetPlugin.swift @@ -10,11 +10,8 @@ public class ActionSheetPlugin: CAPPlugin { private let implementation = ActionSheet() @objc func showActions(_ call: CAPPluginCall) { - guard let title = call.options["title"] as? String else { - call.reject("title must be provided") - return - } - let message = call.options["message"] as? String ?? "" + let title = call.options["title"] as? String + let message = call.options["message"] as? String let options = call.getArray("options", JSObject.self) ?? [] var alertActions = [UIAlertAction]() diff --git a/action-sheet/src/definitions.ts b/action-sheet/src/definitions.ts index 98f65a1c5..84dbfbaae 100644 --- a/action-sheet/src/definitions.ts +++ b/action-sheet/src/definitions.ts @@ -4,7 +4,7 @@ export interface ShowActionsOptions { * * @since 1.0.0 */ - title: string; + title?: string; /** * A message to show under the title.