@capawesome/capacitor-dialog 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/CapawesomeCapacitorDialog.podspec +17 -0
- package/LICENSE +21 -0
- package/Package.swift +28 -0
- package/README.md +232 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/Dialog.java +75 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/DialogPlugin.java +121 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/classes/CustomException.java +20 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/classes/CustomExceptions.java +6 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/classes/options/AlertOptions.java +43 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/classes/options/ConfirmOptions.java +52 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/classes/options/PromptOptions.java +70 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/classes/results/ConfirmResult.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/classes/results/PromptResult.java +27 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/interfaces/Callback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/interfaces/EmptyCallback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/interfaces/NonEmptyResultCallback.java +7 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/interfaces/Result.java +7 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +433 -0
- package/dist/esm/definitions.d.ts +180 -0
- package/dist/esm/definitions.js +2 -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 +8 -0
- package/dist/esm/web.js +29 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +43 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +46 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/Classes/Options/AlertOptions.swift +17 -0
- package/ios/Plugin/Classes/Options/ConfirmOptions.swift +19 -0
- package/ios/Plugin/Classes/Options/PromptOptions.swift +23 -0
- package/ios/Plugin/Classes/Results/ConfirmResult.swift +16 -0
- package/ios/Plugin/Classes/Results/PromptResult.swift +19 -0
- package/ios/Plugin/Dialog.swift +57 -0
- package/ios/Plugin/DialogPlugin.swift +83 -0
- package/ios/Plugin/Enums/CustomError.swift +21 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/Protocols/Result.swift +5 -0
- package/package.json +95 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'CapawesomeCapacitorDialog'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = package['repository']['url']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '15.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.swift_version = '5.1'
|
|
17
|
+
end
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Robin Genz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/Package.swift
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// swift-tools-version: 5.9
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
let package = Package(
|
|
5
|
+
name: "CapawesomeCapacitorDialog",
|
|
6
|
+
platforms: [.iOS(.v15)],
|
|
7
|
+
products: [
|
|
8
|
+
.library(
|
|
9
|
+
name: "CapawesomeCapacitorDialog",
|
|
10
|
+
targets: ["DialogPlugin"])
|
|
11
|
+
],
|
|
12
|
+
dependencies: [
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
|
|
14
|
+
],
|
|
15
|
+
targets: [
|
|
16
|
+
.target(
|
|
17
|
+
name: "DialogPlugin",
|
|
18
|
+
dependencies: [
|
|
19
|
+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
20
|
+
.product(name: "Cordova", package: "capacitor-swift-pm")
|
|
21
|
+
],
|
|
22
|
+
path: "ios/Plugin"),
|
|
23
|
+
.testTarget(
|
|
24
|
+
name: "DialogPluginTests",
|
|
25
|
+
dependencies: ["DialogPlugin"],
|
|
26
|
+
path: "ios/PluginTests")
|
|
27
|
+
]
|
|
28
|
+
)
|
package/README.md
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
# Capacitor Dialog Plugin
|
|
2
|
+
|
|
3
|
+
Capacitor plugin for native alert, confirm, and prompt dialogs.
|
|
4
|
+
|
|
5
|
+
<div class="capawesome-z29o10a">
|
|
6
|
+
<a href="https://cloud.capawesome.io/" target="_blank">
|
|
7
|
+
<img alt="Deliver Live Updates to your Capacitor app with Capawesome Cloud" src="https://cloud.capawesome.io/assets/banners/cloud-build-and-deploy-capacitor-apps.png?t=1" />
|
|
8
|
+
</a>
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- 💬 **Alert**: Display a native alert dialog with a single button.
|
|
14
|
+
- ❓ **Confirm**: Ask the user to confirm or cancel an action.
|
|
15
|
+
- ⌨️ **Prompt**: Request text input from the user.
|
|
16
|
+
- 🌐 **Cross-platform**: Works on Android, iOS, and the web.
|
|
17
|
+
- 🔒 **App Store safe**: Uses only official platform APIs.
|
|
18
|
+
- 📦 **CocoaPods & SPM**: Supports CocoaPods and Swift Package Manager for iOS.
|
|
19
|
+
- 🔁 **Up-to-date**: Always supports the latest Capacitor version.
|
|
20
|
+
|
|
21
|
+
Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!
|
|
22
|
+
|
|
23
|
+
## Newsletter
|
|
24
|
+
|
|
25
|
+
Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
|
|
26
|
+
|
|
27
|
+
## Compatibility
|
|
28
|
+
|
|
29
|
+
| Plugin Version | Capacitor Version | Status |
|
|
30
|
+
| -------------- | ----------------- | -------------- |
|
|
31
|
+
| 0.x.x | >=8.x.x | Active support |
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
You can use our **AI-Assisted Setup** to install the plugin.
|
|
36
|
+
Add the [Capawesome Skills](https://github.com/capawesome-team/skills) to your AI tool using the following command:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npx skills add capawesome-team/skills --skill capacitor-plugins
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Then use the following prompt:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capawesome/capacitor-dialog` plugin in my project.
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
If you prefer **Manual Setup**, install the plugin by running the following commands and follow the platform-specific instructions below:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm install @capawesome/capacitor-dialog
|
|
52
|
+
npx cap sync
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Android
|
|
56
|
+
|
|
57
|
+
No additional configuration is required for this plugin.
|
|
58
|
+
|
|
59
|
+
### iOS
|
|
60
|
+
|
|
61
|
+
No additional configuration is required for this plugin.
|
|
62
|
+
|
|
63
|
+
## Configuration
|
|
64
|
+
|
|
65
|
+
No configuration required for this plugin.
|
|
66
|
+
|
|
67
|
+
## Usage
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { Dialog } from '@capawesome/capacitor-dialog';
|
|
71
|
+
|
|
72
|
+
const alert = async () => {
|
|
73
|
+
await Dialog.alert({
|
|
74
|
+
title: 'Success',
|
|
75
|
+
message: 'Your changes have been saved.',
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const confirm = async () => {
|
|
80
|
+
const { value } = await Dialog.confirm({
|
|
81
|
+
title: 'Confirm',
|
|
82
|
+
message: 'Do you want to delete this item?',
|
|
83
|
+
});
|
|
84
|
+
console.log('Confirmed:', value);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const prompt = async () => {
|
|
88
|
+
const { value, canceled } = await Dialog.prompt({
|
|
89
|
+
title: 'Name',
|
|
90
|
+
message: 'What is your name?',
|
|
91
|
+
inputPlaceholder: 'Enter your name',
|
|
92
|
+
});
|
|
93
|
+
console.log('Value:', value, 'Canceled:', canceled);
|
|
94
|
+
};
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## API
|
|
98
|
+
|
|
99
|
+
<docgen-index>
|
|
100
|
+
|
|
101
|
+
* [`alert(...)`](#alert)
|
|
102
|
+
* [`confirm(...)`](#confirm)
|
|
103
|
+
* [`prompt(...)`](#prompt)
|
|
104
|
+
* [Interfaces](#interfaces)
|
|
105
|
+
|
|
106
|
+
</docgen-index>
|
|
107
|
+
|
|
108
|
+
<docgen-api>
|
|
109
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
110
|
+
|
|
111
|
+
### alert(...)
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
alert(options: AlertOptions) => Promise<void>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Display an alert dialog with a single button.
|
|
118
|
+
|
|
119
|
+
| Param | Type |
|
|
120
|
+
| ------------- | ----------------------------------------------------- |
|
|
121
|
+
| **`options`** | <code><a href="#alertoptions">AlertOptions</a></code> |
|
|
122
|
+
|
|
123
|
+
**Since:** 0.1.0
|
|
124
|
+
|
|
125
|
+
--------------------
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
### confirm(...)
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
confirm(options: ConfirmOptions) => Promise<ConfirmResult>
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Display a confirmation dialog with two buttons.
|
|
135
|
+
|
|
136
|
+
| Param | Type |
|
|
137
|
+
| ------------- | --------------------------------------------------------- |
|
|
138
|
+
| **`options`** | <code><a href="#confirmoptions">ConfirmOptions</a></code> |
|
|
139
|
+
|
|
140
|
+
**Returns:** <code>Promise<<a href="#confirmresult">ConfirmResult</a>></code>
|
|
141
|
+
|
|
142
|
+
**Since:** 0.1.0
|
|
143
|
+
|
|
144
|
+
--------------------
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
### prompt(...)
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
prompt(options: PromptOptions) => Promise<PromptResult>
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Display a prompt dialog with a text input, a confirm and a cancel button.
|
|
154
|
+
|
|
155
|
+
| Param | Type |
|
|
156
|
+
| ------------- | ------------------------------------------------------- |
|
|
157
|
+
| **`options`** | <code><a href="#promptoptions">PromptOptions</a></code> |
|
|
158
|
+
|
|
159
|
+
**Returns:** <code>Promise<<a href="#promptresult">PromptResult</a>></code>
|
|
160
|
+
|
|
161
|
+
**Since:** 0.1.0
|
|
162
|
+
|
|
163
|
+
--------------------
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
### Interfaces
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
#### AlertOptions
|
|
170
|
+
|
|
171
|
+
| Prop | Type | Description | Default | Since |
|
|
172
|
+
| ----------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------- | ----------------- | ----- |
|
|
173
|
+
| **`buttonTitle`** | <code>string</code> | The title of the button that confirms the dialog. On the web, the button title cannot be customized and is ignored. | <code>'OK'</code> | 0.1.0 |
|
|
174
|
+
| **`message`** | <code>string</code> | The message to display in the dialog. | | 0.1.0 |
|
|
175
|
+
| **`title`** | <code>string</code> | The title of the dialog. On the web, the title cannot be customized and is ignored. | | 0.1.0 |
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
#### ConfirmResult
|
|
179
|
+
|
|
180
|
+
| Prop | Type | Description | Since |
|
|
181
|
+
| ----------- | -------------------- | -------------------------------------- | ----- |
|
|
182
|
+
| **`value`** | <code>boolean</code> | Whether the user confirmed the dialog. | 0.1.0 |
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
#### ConfirmOptions
|
|
186
|
+
|
|
187
|
+
| Prop | Type | Description | Default | Since |
|
|
188
|
+
| ----------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------- | --------------------- | ----- |
|
|
189
|
+
| **`cancelButtonTitle`** | <code>string</code> | The title of the button that cancels the dialog. On the web, the button title cannot be customized and is ignored. | <code>'Cancel'</code> | 0.1.0 |
|
|
190
|
+
| **`message`** | <code>string</code> | The message to display in the dialog. | | 0.1.0 |
|
|
191
|
+
| **`okButtonTitle`** | <code>string</code> | The title of the button that confirms the dialog. On the web, the button title cannot be customized and is ignored. | <code>'OK'</code> | 0.1.0 |
|
|
192
|
+
| **`title`** | <code>string</code> | The title of the dialog. On the web, the title cannot be customized and is ignored. | | 0.1.0 |
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
#### PromptResult
|
|
196
|
+
|
|
197
|
+
| Prop | Type | Description | Since |
|
|
198
|
+
| -------------- | -------------------- | ------------------------------------- | ----- |
|
|
199
|
+
| **`canceled`** | <code>boolean</code> | Whether the user canceled the dialog. | 0.1.0 |
|
|
200
|
+
| **`value`** | <code>string</code> | The value of the text input. | 0.1.0 |
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
#### PromptOptions
|
|
204
|
+
|
|
205
|
+
| Prop | Type | Description | Default | Since |
|
|
206
|
+
| ----------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------- | --------------------- | ----- |
|
|
207
|
+
| **`cancelButtonTitle`** | <code>string</code> | The title of the button that cancels the dialog. On the web, the button title cannot be customized and is ignored. | <code>'Cancel'</code> | 0.1.0 |
|
|
208
|
+
| **`inputPlaceholder`** | <code>string</code> | The placeholder of the text input. On the web, the placeholder cannot be customized and is ignored. | | 0.1.0 |
|
|
209
|
+
| **`inputText`** | <code>string</code> | The initial value of the text input. | | 0.1.0 |
|
|
210
|
+
| **`message`** | <code>string</code> | The message to display in the dialog. | | 0.1.0 |
|
|
211
|
+
| **`okButtonTitle`** | <code>string</code> | The title of the button that confirms the dialog. On the web, the button title cannot be customized and is ignored. | <code>'OK'</code> | 0.1.0 |
|
|
212
|
+
| **`title`** | <code>string</code> | The title of the dialog. On the web, the title cannot be customized and is ignored. | | 0.1.0 |
|
|
213
|
+
|
|
214
|
+
</docgen-api>
|
|
215
|
+
|
|
216
|
+
## Migrating from `@capacitor/dialog`
|
|
217
|
+
|
|
218
|
+
This plugin is API-compatible with the official [`@capacitor/dialog`](https://github.com/ionic-team/capacitor-plugins/tree/main/dialog) plugin, with a single difference: the `prompt(...)` result uses the property `canceled` (one `l`) instead of `cancelled` (two `l`s).
|
|
219
|
+
|
|
220
|
+
| `@capacitor/dialog` | `@capawesome/capacitor-dialog` |
|
|
221
|
+
| ---------------------------------- | ---------------------------------- |
|
|
222
|
+
| `alert({ title, message, buttonTitle })` | `alert({ title, message, buttonTitle })` |
|
|
223
|
+
| `confirm({ ... }) → { value }` | `confirm({ ... }) → { value }` |
|
|
224
|
+
| `prompt({ ... }) → { value, cancelled }` | `prompt({ ... }) → { value, canceled }` |
|
|
225
|
+
|
|
226
|
+
## Changelog
|
|
227
|
+
|
|
228
|
+
See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/dialog/CHANGELOG.md).
|
|
229
|
+
|
|
230
|
+
## License
|
|
231
|
+
|
|
232
|
+
See [LICENSE](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/dialog/LICENSE).
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
repositories {
|
|
10
|
+
google()
|
|
11
|
+
mavenCentral()
|
|
12
|
+
}
|
|
13
|
+
dependencies {
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.13.0'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: 'com.android.library'
|
|
19
|
+
|
|
20
|
+
android {
|
|
21
|
+
namespace = "io.capawesome.capacitorjs.plugins.dialog"
|
|
22
|
+
compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
|
|
23
|
+
defaultConfig {
|
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
|
|
26
|
+
versionCode 1
|
|
27
|
+
versionName "1.0"
|
|
28
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
29
|
+
}
|
|
30
|
+
buildTypes {
|
|
31
|
+
release {
|
|
32
|
+
minifyEnabled false
|
|
33
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
lintOptions {
|
|
37
|
+
abortOnError = false
|
|
38
|
+
}
|
|
39
|
+
compileOptions {
|
|
40
|
+
sourceCompatibility JavaVersion.VERSION_21
|
|
41
|
+
targetCompatibility JavaVersion.VERSION_21
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
repositories {
|
|
46
|
+
google()
|
|
47
|
+
mavenCentral()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
dependencies {
|
|
52
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
|
+
implementation project(':capacitor-android')
|
|
54
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
55
|
+
testImplementation "junit:junit:$junitVersion"
|
|
56
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
57
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
58
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.dialog;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.text.InputType;
|
|
5
|
+
import android.widget.EditText;
|
|
6
|
+
import androidx.annotation.NonNull;
|
|
7
|
+
import androidx.appcompat.app.AlertDialog;
|
|
8
|
+
import io.capawesome.capacitorjs.plugins.dialog.classes.options.AlertOptions;
|
|
9
|
+
import io.capawesome.capacitorjs.plugins.dialog.classes.options.ConfirmOptions;
|
|
10
|
+
import io.capawesome.capacitorjs.plugins.dialog.classes.options.PromptOptions;
|
|
11
|
+
import io.capawesome.capacitorjs.plugins.dialog.classes.results.ConfirmResult;
|
|
12
|
+
import io.capawesome.capacitorjs.plugins.dialog.classes.results.PromptResult;
|
|
13
|
+
import io.capawesome.capacitorjs.plugins.dialog.interfaces.EmptyCallback;
|
|
14
|
+
import io.capawesome.capacitorjs.plugins.dialog.interfaces.NonEmptyResultCallback;
|
|
15
|
+
|
|
16
|
+
public class Dialog {
|
|
17
|
+
|
|
18
|
+
@NonNull
|
|
19
|
+
private final DialogPlugin plugin;
|
|
20
|
+
|
|
21
|
+
public Dialog(@NonNull DialogPlugin plugin) {
|
|
22
|
+
this.plugin = plugin;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public void alert(@NonNull AlertOptions options, @NonNull EmptyCallback callback) {
|
|
26
|
+
Activity activity = plugin.getActivity();
|
|
27
|
+
activity.runOnUiThread(() -> {
|
|
28
|
+
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
|
29
|
+
builder.setTitle(options.getTitle());
|
|
30
|
+
builder.setMessage(options.getMessage());
|
|
31
|
+
builder.setPositiveButton(options.getButtonTitle(), (dialog, which) -> callback.success());
|
|
32
|
+
builder.setOnCancelListener(dialog -> callback.success());
|
|
33
|
+
builder.create().show();
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public void confirm(@NonNull ConfirmOptions options, @NonNull NonEmptyResultCallback<ConfirmResult> callback) {
|
|
38
|
+
Activity activity = plugin.getActivity();
|
|
39
|
+
activity.runOnUiThread(() -> {
|
|
40
|
+
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
|
41
|
+
builder.setTitle(options.getTitle());
|
|
42
|
+
builder.setMessage(options.getMessage());
|
|
43
|
+
builder.setPositiveButton(options.getOkButtonTitle(), (dialog, which) -> callback.success(new ConfirmResult(true)));
|
|
44
|
+
builder.setNegativeButton(options.getCancelButtonTitle(), (dialog, which) -> callback.success(new ConfirmResult(false)));
|
|
45
|
+
builder.setOnCancelListener(dialog -> callback.success(new ConfirmResult(false)));
|
|
46
|
+
builder.create().show();
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public void prompt(@NonNull PromptOptions options, @NonNull NonEmptyResultCallback<PromptResult> callback) {
|
|
51
|
+
Activity activity = plugin.getActivity();
|
|
52
|
+
activity.runOnUiThread(() -> {
|
|
53
|
+
EditText input = new EditText(activity);
|
|
54
|
+
input.setInputType(InputType.TYPE_CLASS_TEXT);
|
|
55
|
+
if (options.getInputPlaceholder() != null) {
|
|
56
|
+
input.setHint(options.getInputPlaceholder());
|
|
57
|
+
}
|
|
58
|
+
if (options.getInputText() != null) {
|
|
59
|
+
input.setText(options.getInputText());
|
|
60
|
+
}
|
|
61
|
+
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
|
62
|
+
builder.setTitle(options.getTitle());
|
|
63
|
+
builder.setMessage(options.getMessage());
|
|
64
|
+
builder.setView(input);
|
|
65
|
+
builder.setPositiveButton(options.getOkButtonTitle(), (dialog, which) ->
|
|
66
|
+
callback.success(new PromptResult(input.getText().toString(), false))
|
|
67
|
+
);
|
|
68
|
+
builder.setNegativeButton(options.getCancelButtonTitle(), (dialog, which) ->
|
|
69
|
+
callback.success(new PromptResult(input.getText().toString(), true))
|
|
70
|
+
);
|
|
71
|
+
builder.setOnCancelListener(dialog -> callback.success(new PromptResult("", true)));
|
|
72
|
+
builder.create().show();
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.dialog;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
import com.getcapacitor.Logger;
|
|
6
|
+
import com.getcapacitor.Plugin;
|
|
7
|
+
import com.getcapacitor.PluginCall;
|
|
8
|
+
import com.getcapacitor.PluginMethod;
|
|
9
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
10
|
+
import io.capawesome.capacitorjs.plugins.dialog.classes.CustomException;
|
|
11
|
+
import io.capawesome.capacitorjs.plugins.dialog.classes.options.AlertOptions;
|
|
12
|
+
import io.capawesome.capacitorjs.plugins.dialog.classes.options.ConfirmOptions;
|
|
13
|
+
import io.capawesome.capacitorjs.plugins.dialog.classes.options.PromptOptions;
|
|
14
|
+
import io.capawesome.capacitorjs.plugins.dialog.classes.results.ConfirmResult;
|
|
15
|
+
import io.capawesome.capacitorjs.plugins.dialog.classes.results.PromptResult;
|
|
16
|
+
import io.capawesome.capacitorjs.plugins.dialog.interfaces.EmptyCallback;
|
|
17
|
+
import io.capawesome.capacitorjs.plugins.dialog.interfaces.NonEmptyResultCallback;
|
|
18
|
+
import io.capawesome.capacitorjs.plugins.dialog.interfaces.Result;
|
|
19
|
+
|
|
20
|
+
@CapacitorPlugin(name = "Dialog")
|
|
21
|
+
public class DialogPlugin extends Plugin {
|
|
22
|
+
|
|
23
|
+
public static final String ERROR_UNKNOWN_ERROR = "An unknown error has occurred.";
|
|
24
|
+
public static final String TAG = "DialogPlugin";
|
|
25
|
+
|
|
26
|
+
private Dialog implementation;
|
|
27
|
+
|
|
28
|
+
@Override
|
|
29
|
+
public void load() {
|
|
30
|
+
super.load();
|
|
31
|
+
this.implementation = new Dialog(this);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@PluginMethod
|
|
35
|
+
public void alert(PluginCall call) {
|
|
36
|
+
try {
|
|
37
|
+
AlertOptions options = new AlertOptions(call);
|
|
38
|
+
EmptyCallback callback = new EmptyCallback() {
|
|
39
|
+
@Override
|
|
40
|
+
public void success() {
|
|
41
|
+
resolveCall(call);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Override
|
|
45
|
+
public void error(Exception exception) {
|
|
46
|
+
rejectCall(call, exception);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
implementation.alert(options, callback);
|
|
50
|
+
} catch (Exception exception) {
|
|
51
|
+
rejectCall(call, exception);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@PluginMethod
|
|
56
|
+
public void confirm(PluginCall call) {
|
|
57
|
+
try {
|
|
58
|
+
ConfirmOptions options = new ConfirmOptions(call);
|
|
59
|
+
NonEmptyResultCallback<ConfirmResult> callback = new NonEmptyResultCallback<>() {
|
|
60
|
+
@Override
|
|
61
|
+
public void success(@NonNull ConfirmResult result) {
|
|
62
|
+
resolveCall(call, result);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@Override
|
|
66
|
+
public void error(Exception exception) {
|
|
67
|
+
rejectCall(call, exception);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
implementation.confirm(options, callback);
|
|
71
|
+
} catch (Exception exception) {
|
|
72
|
+
rejectCall(call, exception);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@PluginMethod
|
|
77
|
+
public void prompt(PluginCall call) {
|
|
78
|
+
try {
|
|
79
|
+
PromptOptions options = new PromptOptions(call);
|
|
80
|
+
NonEmptyResultCallback<PromptResult> callback = new NonEmptyResultCallback<>() {
|
|
81
|
+
@Override
|
|
82
|
+
public void success(@NonNull PromptResult result) {
|
|
83
|
+
resolveCall(call, result);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@Override
|
|
87
|
+
public void error(Exception exception) {
|
|
88
|
+
rejectCall(call, exception);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
implementation.prompt(options, callback);
|
|
92
|
+
} catch (Exception exception) {
|
|
93
|
+
rejectCall(call, exception);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private void rejectCall(@NonNull PluginCall call, @NonNull Exception exception) {
|
|
98
|
+
String message = exception.getMessage();
|
|
99
|
+
if (message == null) {
|
|
100
|
+
message = ERROR_UNKNOWN_ERROR;
|
|
101
|
+
}
|
|
102
|
+
String code = null;
|
|
103
|
+
if (exception instanceof CustomException) {
|
|
104
|
+
code = ((CustomException) exception).getCode();
|
|
105
|
+
}
|
|
106
|
+
Logger.error(TAG, message, exception);
|
|
107
|
+
call.reject(message, code);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private void resolveCall(@NonNull PluginCall call) {
|
|
111
|
+
call.resolve();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private void resolveCall(@NonNull PluginCall call, @Nullable Result result) {
|
|
115
|
+
if (result == null) {
|
|
116
|
+
call.resolve();
|
|
117
|
+
} else {
|
|
118
|
+
call.resolve(result.toJSObject());
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/classes/CustomException.java
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.dialog.classes;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
|
|
6
|
+
public class CustomException extends Exception {
|
|
7
|
+
|
|
8
|
+
@Nullable
|
|
9
|
+
private final String code;
|
|
10
|
+
|
|
11
|
+
public CustomException(@Nullable String code, @NonNull String message) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.code = code;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@Nullable
|
|
17
|
+
public String getCode() {
|
|
18
|
+
return code;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.dialog.classes.options;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
import com.getcapacitor.PluginCall;
|
|
6
|
+
import io.capawesome.capacitorjs.plugins.dialog.classes.CustomExceptions;
|
|
7
|
+
|
|
8
|
+
public class AlertOptions {
|
|
9
|
+
|
|
10
|
+
@NonNull
|
|
11
|
+
private final String buttonTitle;
|
|
12
|
+
|
|
13
|
+
@NonNull
|
|
14
|
+
private final String message;
|
|
15
|
+
|
|
16
|
+
@Nullable
|
|
17
|
+
private final String title;
|
|
18
|
+
|
|
19
|
+
public AlertOptions(@NonNull PluginCall call) throws Exception {
|
|
20
|
+
String message = call.getString("message");
|
|
21
|
+
if (message == null) {
|
|
22
|
+
throw CustomExceptions.MESSAGE_MISSING;
|
|
23
|
+
}
|
|
24
|
+
this.message = message;
|
|
25
|
+
this.buttonTitle = call.getString("buttonTitle", "OK");
|
|
26
|
+
this.title = call.getString("title");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@NonNull
|
|
30
|
+
public String getButtonTitle() {
|
|
31
|
+
return buttonTitle;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@NonNull
|
|
35
|
+
public String getMessage() {
|
|
36
|
+
return message;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@Nullable
|
|
40
|
+
public String getTitle() {
|
|
41
|
+
return title;
|
|
42
|
+
}
|
|
43
|
+
}
|