Skip to content

Commit 2018f78

Browse files
authored
feat(action-sheet): Make title optional (ionic-team#805)
1 parent bfa2a38 commit 2018f78

File tree

5 files changed

+11
-16
lines changed

5 files changed

+11
-16
lines changed

action-sheet/android/src/main/java/com/capacitorjs/plugins/actionsheet/ActionSheet.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,13 @@ public void setupDialog(Dialog dialog, int style) {
8686
LinearLayout layout = new LinearLayout(getContext());
8787
layout.setOrientation(LinearLayout.VERTICAL);
8888
layout.setPadding(layoutPaddingPx16, layoutPaddingPx16, layoutPaddingPx16, layoutPaddingPx16);
89-
TextView ttv = new TextView(getContext());
90-
ttv.setTextColor(Color.parseColor("#757575"));
91-
ttv.setPadding(layoutPaddingPx8, layoutPaddingPx8, layoutPaddingPx8, layoutPaddingPx8);
92-
ttv.setText(title);
93-
layout.addView(ttv);
89+
if (title != null) {
90+
TextView ttv = new TextView(getContext());
91+
ttv.setTextColor(Color.parseColor("#757575"));
92+
ttv.setPadding(layoutPaddingPx8, layoutPaddingPx8, layoutPaddingPx8, layoutPaddingPx8);
93+
ttv.setText(title);
94+
layout.addView(ttv);
95+
}
9496

9597
for (int i = 0; i < options.length; i++) {
9698
final int optionIndex = i;

action-sheet/android/src/main/java/com/capacitorjs/plugins/actionsheet/ActionSheetPlugin.java

-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ public class ActionSheetPlugin extends Plugin {
2020
public void showActions(final PluginCall call) {
2121
String title = call.getString("title");
2222
JSArray options = call.getArray("options");
23-
if (title == null) {
24-
call.reject("Must supply a title");
25-
return;
26-
}
2723
if (options == null) {
2824
call.reject("Must supply options");
2925
return;

action-sheet/ios/Plugin/ActionSheet.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import UIKit
33

44
@objc public class ActionSheet: NSObject {
55

6-
@objc public func buildActionSheet(title: String, message: String, actions: [UIAlertAction]) -> UIAlertController {
6+
@objc public func buildActionSheet(title: String?, message: String?, actions: [UIAlertAction]) -> UIAlertController {
77
let controller = UIAlertController(title: title, message: message, preferredStyle: .actionSheet)
88
for action in actions {
99
controller.addAction(action)

action-sheet/ios/Plugin/ActionSheetPlugin.swift

+2-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ public class ActionSheetPlugin: CAPPlugin {
1010
private let implementation = ActionSheet()
1111

1212
@objc func showActions(_ call: CAPPluginCall) {
13-
guard let title = call.options["title"] as? String else {
14-
call.reject("title must be provided")
15-
return
16-
}
17-
let message = call.options["message"] as? String ?? ""
13+
let title = call.options["title"] as? String
14+
let message = call.options["message"] as? String
1815

1916
let options = call.getArray("options", JSObject.self) ?? []
2017
var alertActions = [UIAlertAction]()

action-sheet/src/definitions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export interface ShowActionsOptions {
44
*
55
* @since 1.0.0
66
*/
7-
title: string;
7+
title?: string;
88

99
/**
1010
* A message to show under the title.

0 commit comments

Comments
 (0)