From 02e229042a5119a8772dfa3334acb556dd5e67df Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Fri, 10 Jun 2022 11:08:09 -0400 Subject: [PATCH] Use PasteButton on iOS 16 --- OTP/Views/EditKeyForm.swift | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/OTP/Views/EditKeyForm.swift b/OTP/Views/EditKeyForm.swift index e996eb5..6fbb903 100644 --- a/OTP/Views/EditKeyForm.swift +++ b/OTP/Views/EditKeyForm.swift @@ -41,15 +41,25 @@ struct EditKeyForm: View { HStack { TextField("Secret", text: $editedKey.secret) - Button { - self.editedKey.secret = UIPasteboard.general.string ?? "" - } label: { - Label("Paste", systemImage: "doc.on.clipboard") - .labelStyle(.iconOnly) - .foregroundColor(.accentColor) + if #available(iOS 16.0, *) { + PasteButton(payloadType: String.self) { pasted in + if let s = pasted.first { + self.editedKey.secret = s + } + } + .labelStyle(.iconOnly) + .buttonBorderShape(.capsule) + } else { + Button { + self.editedKey.secret = UIPasteboard.general.string ?? "" + } label: { + Label("Paste", systemImage: "doc.on.clipboard") + .labelStyle(.iconOnly) + .foregroundColor(.accentColor) + } + .buttonStyle(.plain) + .disabled(!UIPasteboard.general.hasStrings) } - .buttonStyle(.plain) - .disabled(!UIPasteboard.general.hasStrings) } HStack {