Refactor no autocorrection into raw text style

This commit is contained in:
Davide De Rosa 2022-05-24 08:25:10 +02:00
parent 02213a7c50
commit f752594d3c
2 changed files with 13 additions and 16 deletions

View File

@ -364,6 +364,11 @@ extension View {
.truncationMode(.middle)
}
func themeRawTextStyle() -> some View {
disableAutocorrection(true)
.autocapitalization(.none)
}
func themeInformativeTextStyle() -> some View {
multilineTextAlignment(.center)
.font(.title)
@ -467,22 +472,19 @@ extension View {
extension View {
func themeValidProfileName() -> some View {
autocapitalization(.none)
.disableAutocorrection(true)
themeRawTextStyle()
}
func themeValidURL(_ urlString: String?) -> some View {
themeValidating(urlString, validator: Validators.url)
.keyboardType(.asciiCapable)
.autocapitalization(.none)
.disableAutocorrection(true)
.themeRawTextStyle()
}
func themeValidIPAddress(_ ipAddress: String?) -> some View {
themeValidating(ipAddress, validator: Validators.ipAddress)
.keyboardType(.numbersAndPunctuation)
.autocapitalization(.none)
.disableAutocorrection(true)
.themeRawTextStyle()
}
func themeValidSocketPort() -> some View {
@ -492,22 +494,19 @@ extension View {
func themeValidDomainName(_ domainName: String?) -> some View {
themeValidating(domainName, validator: Validators.domainName)
.keyboardType(.asciiCapable)
.autocapitalization(.none)
.disableAutocorrection(true)
.themeRawTextStyle()
}
func themeValidDNSOverTLSServerName(_ string: String?) -> some View {
themeValidating(string, validator: Validators.dnsOverTLSServerName)
.keyboardType(.asciiCapable)
.autocapitalization(.none)
.disableAutocorrection(true)
.themeRawTextStyle()
}
func themeValidSSID(_ text: String?) -> some View {
themeValidating(text, validator: Validators.notEmpty)
.keyboardType(.asciiCapable)
.autocapitalization(.none)
.disableAutocorrection(true)
.themeRawTextStyle()
}
private func themeValidating(_ string: String?, validator: (String) throws -> Void) -> some View {

View File

@ -63,9 +63,8 @@ struct AccountView: View {
Section {
TextField(usernamePlaceholder ?? L10n.Account.Items.Username.placeholder, text: $liveAccount.username)
.textContentType(.username)
.disableAutocorrection(true)
.autocapitalization(.none)
.keyboardType(.emailAddress)
.themeRawTextStyle()
.withLeadingText(L10n.Account.Items.Username.caption)
RevealingSecureField(L10n.Account.Items.Password.placeholder, text: $liveAccount.password) {
@ -75,8 +74,7 @@ struct AccountView: View {
themeRevealImage.asSystemImage
.themeAccentForegroundStyle()
}.textContentType(.password)
.disableAutocorrection(true)
.autocapitalization(.none)
.themeRawTextStyle()
.withLeadingText(L10n.Account.Items.Password.caption)
} footer: {
metadata?.localizedGuidanceString.map {