commit bf7120dc08b36b3cc8d9d39dedf936bfbd3550f3
parent dbe938ad9bdc69ca2d489d462db30a6dad57dca9
Author: Terry Yiu <963907+tyiu@users.noreply.github.com>
Date: Wed, 8 Feb 2023 21:22:04 -0500
Add password autofill on account login and creation
Changelog-Added: Add password autofill on account login and creation
Closes: #559
Diffstat:
4 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/damus/Util/InputDismissKeyboard.swift b/damus/Util/InputDismissKeyboard.swift
@@ -29,7 +29,7 @@ public struct DismissKeyboardOnTap: ViewModifier {
}
-func end_editing() {
+public func end_editing() {
UIApplication.shared.connectedScenes
.filter {$0.activationState == .foregroundActive}
.map {$0 as? UIWindowScene}
diff --git a/damus/Views/LoginView.swift b/damus/Views/LoginView.swift
@@ -275,6 +275,7 @@ struct KeyInput: View {
.autocapitalization(.none)
.foregroundColor(.white)
.font(.body.monospaced())
+ .textContentType(.password)
}
}
diff --git a/damus/Views/SaveKeysView.swift b/damus/Views/SaveKeysView.swift
@@ -15,6 +15,9 @@ struct SaveKeysView: View {
@State var priv_copied: Bool = false
@State var loading: Bool = false
@State var error: String? = nil
+
+ @FocusState var pubkey_focused: Bool
+ @FocusState var privkey_focused: Bool
var body: some View {
ZStack(alignment: .top) {
@@ -39,7 +42,7 @@ struct SaveKeysView: View {
.foregroundColor(.white)
.padding(.bottom, 10)
- SaveKeyView(text: account.pubkey_bech32, is_copied: $pub_copied)
+ SaveKeyView(text: account.pubkey_bech32, textContentType: .username, is_copied: $pub_copied, focus: $pubkey_focused)
.padding(.bottom, 10)
if pub_copied {
@@ -52,7 +55,7 @@ struct SaveKeysView: View {
.foregroundColor(.white)
.padding(.bottom, 10)
- SaveKeyView(text: account.privkey_bech32, is_copied: $priv_copied)
+ SaveKeyView(text: account.privkey_bech32, textContentType: .newPassword, is_copied: $priv_copied, focus: $privkey_focused)
.padding(.bottom, 10)
}
@@ -77,6 +80,13 @@ struct SaveKeysView: View {
}
.navigationBarBackButtonHidden(true)
.navigationBarItems(leading: BackNav())
+ .onAppear {
+ // Hack to force keyboard to show up for a short moment and then hiding it to register password autofill flow.
+ pubkey_focused = true
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
+ pubkey_focused = false
+ }
+ }
}
func complete_account_creation(_ account: CreateAccountModel) {
@@ -138,7 +148,9 @@ struct SaveKeysView: View {
struct SaveKeyView: View {
let text: String
+ let textContentType: UITextContentType
@Binding var is_copied: Bool
+ var focus: FocusState<Bool>.Binding
func copy_text() {
UIPasteboard.general.string = text
@@ -166,8 +178,8 @@ struct SaveKeyView: View {
}
}
}
-
- Text(text)
+
+ TextField("", text: .constant(text))
.padding(5)
.background {
RoundedRectangle(cornerRadius: 4.0).opacity(0.2)
@@ -177,7 +189,14 @@ struct SaveKeyView: View {
.foregroundColor(.white)
.onTapGesture {
copy_text()
+ // Hack to force keyboard to hide. Showing keyboard on text field is necessary to register password autofill flow but the text itself should not be modified.
+ DispatchQueue.main.async {
+ end_editing()
+ }
}
+ .textContentType(textContentType)
+ .deleteDisabled(true)
+ .focused(focus)
spacerBlock(width: 0, height: 0) /// set a 'width' > 0 here to vary key Text's aspect ratio
}
diff --git a/damus/damus.entitlements b/damus/damus.entitlements
@@ -7,6 +7,7 @@
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:damus.io</string>
+ <string>webcredentials:damus.io</string>
</array>
<key>keychain-access-groups</key>
<array>