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

This commit is contained in:
Olivier Lemasle
2024-01-11 03:30:32 +01:00
committed by GitHub
parent 1b1d795b58
commit bf5a21d5b2
3 changed files with 28 additions and 7 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"dialog": "patch"
---
On Android, do not add a `Cancel` button to message dialogs.
+17 -1
View File
@@ -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()
}