fix(dialog): On Android, do not add a `Cancel` button to message dialogs (#873)

pull/903/head
Olivier Lemasle 1 year ago committed by GitHub
parent 1b1d795b58
commit bf5a21d5b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
"dialog": "patch"
---
On Android, do not add a `Cancel` button to message dialogs.

@ -1,5 +1,5 @@
<script>
import { open, save, confirm } from "@tauri-apps/plugin-dialog";
import { open, save, confirm, message } from "@tauri-apps/plugin-dialog";
import { readFile } from "@tauri-apps/plugin-fs";
export let onMessage;
@ -22,6 +22,16 @@
}
async function prompt() {
confirm("Do you want to do something?")
.then((res) =>
onMessage(
res ? "Yes" : "No"
)
)
.catch(onMessage);
}
async function promptCustom() {
confirm("Is Tauri awesome?", {
okLabel: "Absolutely",
cancelLabel: "Totally",
@ -34,6 +44,10 @@
.catch(onMessage);
}
async function msg() {
await message("Tauri is awesome!");
}
function openDialog() {
open({
title: "My wonderful open dialog",
@ -130,3 +144,5 @@
>Open save dialog</button
>
<button class="btn" id="prompt-dialog" on:click={prompt}>Prompt</button>
<button class="btn" id="custom-prompt-dialog" on:click={promptCustom}>Prompt (custom)</button>
<button class="btn" id="message-dialog" on:click={msg}>Message</button>

@ -190,16 +190,16 @@ class DialogPlugin(private val activity: Activity): Plugin(activity) {
dialog.dismiss()
handler(false, true)
}
.setNegativeButton(
args.cancelButtonLabel ?: "Cancel"
) { dialog, _ ->
dialog.dismiss()
handler(false, false)
}
.setOnCancelListener { dialog ->
dialog.dismiss()
handler(true, false)
}
if (args.cancelButtonLabel != null) {
builder.setNegativeButton( args.cancelButtonLabel) { dialog, _ ->
dialog.dismiss()
handler(false, false)
}
}
val dialog = builder.create()
dialog.show()
}

Loading…
Cancel
Save