@capawesome/capacitor-action-sheet 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapawesomeCapacitorActionSheet.podspec +17 -0
- package/LICENSE +21 -0
- package/Package.swift +28 -0
- package/README.md +185 -0
- package/android/build.gradle +60 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/actionsheet/ActionSheet.java +144 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/actionsheet/ActionSheetPlugin.java +71 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/actionsheet/classes/CustomException.java +20 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/actionsheet/classes/CustomExceptions.java +8 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/actionsheet/classes/options/ActionSheetButton.java +45 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/actionsheet/classes/options/ShowActionsOptions.java +62 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/actionsheet/classes/results/ShowActionsResult.java +25 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/actionsheet/interfaces/Callback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/actionsheet/interfaces/NonEmptyResultCallback.java +7 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/actionsheet/interfaces/Result.java +7 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +258 -0
- package/dist/esm/definitions.d.ts +116 -0
- package/dist/esm/definitions.js +29 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +5 -0
- package/dist/esm/web.js +7 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +50 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +53 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/ActionSheet.swift +59 -0
- package/ios/Plugin/ActionSheetPlugin.swift +47 -0
- package/ios/Plugin/Classes/Options/ActionSheetButton.swift +19 -0
- package/ios/Plugin/Classes/Options/ShowActionsOptions.swift +23 -0
- package/ios/Plugin/Classes/Results/ShowActionsResult.swift +19 -0
- package/ios/Plugin/Enums/CustomError.swift +31 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/Protocols/Result.swift +5 -0
- package/package.json +94 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
@objc(ActionSheetPlugin)
|
|
5
|
+
public class ActionSheetPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
6
|
+
public let identifier = "ActionSheetPlugin"
|
|
7
|
+
public let jsName = "ActionSheet"
|
|
8
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
9
|
+
CAPPluginMethod(name: "showActions", returnType: CAPPluginReturnPromise)
|
|
10
|
+
]
|
|
11
|
+
public static let tag = "ActionSheetPlugin"
|
|
12
|
+
|
|
13
|
+
private var implementation: ActionSheet?
|
|
14
|
+
|
|
15
|
+
override public func load() {
|
|
16
|
+
self.implementation = ActionSheet(plugin: self)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@objc func showActions(_ call: CAPPluginCall) {
|
|
20
|
+
do {
|
|
21
|
+
let options = try ShowActionsOptions(call)
|
|
22
|
+
implementation?.showActions(options) { result, error in
|
|
23
|
+
if let error = error {
|
|
24
|
+
self.rejectCall(call, error)
|
|
25
|
+
return
|
|
26
|
+
}
|
|
27
|
+
self.resolveCall(call, result)
|
|
28
|
+
}
|
|
29
|
+
} catch {
|
|
30
|
+
rejectCall(call, error)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private func rejectCall(_ call: CAPPluginCall, _ error: Error) {
|
|
35
|
+
CAPLog.print("[", ActionSheetPlugin.tag, "] ", error)
|
|
36
|
+
let code = (error as? CustomError)?.code
|
|
37
|
+
call.reject(error.localizedDescription, code)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private func resolveCall(_ call: CAPPluginCall, _ result: Result?) {
|
|
41
|
+
if let result = result?.toJSObject() as? JSObject {
|
|
42
|
+
call.resolve(result)
|
|
43
|
+
} else {
|
|
44
|
+
call.resolve()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
@objc public class ActionSheetButton: NSObject {
|
|
5
|
+
static let styleCancel = "CANCEL"
|
|
6
|
+
static let styleDefault = "DEFAULT"
|
|
7
|
+
static let styleDestructive = "DESTRUCTIVE"
|
|
8
|
+
|
|
9
|
+
let style: String
|
|
10
|
+
let title: String
|
|
11
|
+
|
|
12
|
+
init(_ object: JSObject) throws {
|
|
13
|
+
guard let title = object["title"] as? String else {
|
|
14
|
+
throw CustomError.buttonTitleMissing
|
|
15
|
+
}
|
|
16
|
+
self.title = title
|
|
17
|
+
self.style = object["style"] as? String ?? ActionSheetButton.styleDefault
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
@objc public class ShowActionsOptions: NSObject {
|
|
5
|
+
let buttons: [ActionSheetButton]
|
|
6
|
+
let cancelable: Bool
|
|
7
|
+
let message: String?
|
|
8
|
+
let title: String?
|
|
9
|
+
|
|
10
|
+
init(_ call: CAPPluginCall) throws {
|
|
11
|
+
guard let rawButtons = call.getArray("options", JSObject.self) else {
|
|
12
|
+
throw CustomError.optionsMissing
|
|
13
|
+
}
|
|
14
|
+
let buttons = try rawButtons.map { try ActionSheetButton($0) }
|
|
15
|
+
if buttons.isEmpty {
|
|
16
|
+
throw CustomError.optionsEmpty
|
|
17
|
+
}
|
|
18
|
+
self.buttons = buttons
|
|
19
|
+
self.cancelable = call.getBool("cancelable", true)
|
|
20
|
+
self.message = call.getString("message")
|
|
21
|
+
self.title = call.getString("title")
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
@objc public class ShowActionsResult: NSObject, Result {
|
|
5
|
+
let canceled: Bool
|
|
6
|
+
let index: Int
|
|
7
|
+
|
|
8
|
+
init(index: Int, canceled: Bool) {
|
|
9
|
+
self.index = index
|
|
10
|
+
self.canceled = canceled
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@objc public func toJSObject() -> AnyObject {
|
|
14
|
+
var result = JSObject()
|
|
15
|
+
result["canceled"] = canceled
|
|
16
|
+
result["index"] = index
|
|
17
|
+
return result as AnyObject
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
enum CustomError: Error {
|
|
4
|
+
case buttonTitleMissing
|
|
5
|
+
case optionsEmpty
|
|
6
|
+
case optionsMissing
|
|
7
|
+
|
|
8
|
+
var code: String? {
|
|
9
|
+
switch self {
|
|
10
|
+
case .buttonTitleMissing:
|
|
11
|
+
return nil
|
|
12
|
+
case .optionsEmpty:
|
|
13
|
+
return nil
|
|
14
|
+
case .optionsMissing:
|
|
15
|
+
return nil
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
extension CustomError: LocalizedError {
|
|
21
|
+
public var errorDescription: String? {
|
|
22
|
+
switch self {
|
|
23
|
+
case .buttonTitleMissing:
|
|
24
|
+
return NSLocalizedString("each button must provide a title.", comment: "buttonTitleMissing")
|
|
25
|
+
case .optionsEmpty:
|
|
26
|
+
return NSLocalizedString("options must not be empty.", comment: "optionsEmpty")
|
|
27
|
+
case .optionsMissing:
|
|
28
|
+
return NSLocalizedString("options must be provided.", comment: "optionsMissing")
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>CFBundleDevelopmentRegion</key>
|
|
6
|
+
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
|
7
|
+
<key>CFBundleExecutable</key>
|
|
8
|
+
<string>$(EXECUTABLE_NAME)</string>
|
|
9
|
+
<key>CFBundleIdentifier</key>
|
|
10
|
+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
|
11
|
+
<key>CFBundleInfoDictionaryVersion</key>
|
|
12
|
+
<string>6.0</string>
|
|
13
|
+
<key>CFBundleName</key>
|
|
14
|
+
<string>$(PRODUCT_NAME)</string>
|
|
15
|
+
<key>CFBundlePackageType</key>
|
|
16
|
+
<string>FMWK</string>
|
|
17
|
+
<key>CFBundleShortVersionString</key>
|
|
18
|
+
<string>1.0</string>
|
|
19
|
+
<key>CFBundleVersion</key>
|
|
20
|
+
<string>$(CURRENT_PROJECT_VERSION)</string>
|
|
21
|
+
<key>NSPrincipalClass</key>
|
|
22
|
+
<string></string>
|
|
23
|
+
</dict>
|
|
24
|
+
</plist>
|
package/package.json
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capawesome/capacitor-action-sheet",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Capacitor plugin for native action sheets.",
|
|
5
|
+
"main": "dist/plugin.cjs.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/esm/index.d.ts",
|
|
8
|
+
"unpkg": "dist/plugin.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"android/src/main/",
|
|
11
|
+
"android/build.gradle",
|
|
12
|
+
"dist/",
|
|
13
|
+
"ios/Plugin/",
|
|
14
|
+
"CapawesomeCapacitorActionSheet.podspec",
|
|
15
|
+
"Package.swift"
|
|
16
|
+
],
|
|
17
|
+
"author": "Robin Genz <mail@robingenz.dev>",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/capawesome-team/capacitor-plugins.git"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/capawesome-team/capacitor-plugins/issues"
|
|
25
|
+
},
|
|
26
|
+
"funding": [
|
|
27
|
+
{
|
|
28
|
+
"type": "github",
|
|
29
|
+
"url": "https://github.com/sponsors/capawesome-team/"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"type": "opencollective",
|
|
33
|
+
"url": "https://opencollective.com/capawesome"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"homepage": "https://capawesome.io/docs/sdks/capacitor/action-sheet/",
|
|
37
|
+
"keywords": [
|
|
38
|
+
"capacitor",
|
|
39
|
+
"plugin",
|
|
40
|
+
"native",
|
|
41
|
+
"action-sheet",
|
|
42
|
+
"action sheet",
|
|
43
|
+
"bottom sheet"
|
|
44
|
+
],
|
|
45
|
+
"scripts": {
|
|
46
|
+
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
47
|
+
"verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination generic/platform=iOS && cd ..",
|
|
48
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
49
|
+
"verify:web": "npm run build",
|
|
50
|
+
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
51
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
52
|
+
"eslint": "eslint . --ext ts",
|
|
53
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
|
|
54
|
+
"swiftlint": "node-swiftlint",
|
|
55
|
+
"docgen": "docgen --api ActionSheetPlugin --output-readme README.md --output-json dist/docs.json",
|
|
56
|
+
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
57
|
+
"clean": "rimraf ./dist",
|
|
58
|
+
"watch": "tsc --watch",
|
|
59
|
+
"ios:pod:install": "cd ios && pod install --repo-update && cd ..",
|
|
60
|
+
"ios:spm:install": "cd ios && swift package resolve && cd ..",
|
|
61
|
+
"prepublishOnly": "npm run build"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@capacitor/android": "8.0.0",
|
|
65
|
+
"@capacitor/cli": "8.0.0",
|
|
66
|
+
"@capacitor/core": "8.0.0",
|
|
67
|
+
"@capacitor/docgen": "0.3.1",
|
|
68
|
+
"@capacitor/ios": "8.0.0",
|
|
69
|
+
"@ionic/eslint-config": "0.4.0",
|
|
70
|
+
"eslint": "8.57.0",
|
|
71
|
+
"prettier-plugin-java": "2.6.7",
|
|
72
|
+
"rimraf": "6.1.2",
|
|
73
|
+
"rollup": "4.53.3",
|
|
74
|
+
"swiftlint": "2.0.0",
|
|
75
|
+
"typescript": "5.9.3"
|
|
76
|
+
},
|
|
77
|
+
"peerDependencies": {
|
|
78
|
+
"@capacitor/core": ">=8.0.0"
|
|
79
|
+
},
|
|
80
|
+
"eslintConfig": {
|
|
81
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
82
|
+
},
|
|
83
|
+
"capacitor": {
|
|
84
|
+
"ios": {
|
|
85
|
+
"src": "ios"
|
|
86
|
+
},
|
|
87
|
+
"android": {
|
|
88
|
+
"src": "android"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"publishConfig": {
|
|
92
|
+
"access": "public"
|
|
93
|
+
}
|
|
94
|
+
}
|