Moved some login code into its own file within the Login module.

This commit is contained in:
Javier Cicchelli 2022-12-02 20:55:13 +01:00
parent 9ed753b2fe
commit a98c5df41e
5 changed files with 100 additions and 53 deletions

View File

@ -1,6 +1,6 @@
// //
// LoginForm.swift // LoginForm.swift
// BeReal // Login
// //
// Created by Javier Cicchelli on 01/12/2022. // Created by Javier Cicchelli on 01/12/2022.
// Copyright © 2022 Röck+Cöde. All rights reserved. // Copyright © 2022 Röck+Cöde. All rights reserved.
@ -32,7 +32,11 @@ struct LoginForm: View {
spacing: 16 spacing: 16
) { ) {
TextField( TextField(
NSLocalizedString(
"login.text_field.username.placeholder", "login.text_field.username.placeholder",
bundle: .module,
comment: "The placeholder for the username text field."
),
text: $username text: $username
) { isBeginEditing in ) { isBeginEditing in
guard isBeginEditing, errorMessage != nil else { return } guard isBeginEditing, errorMessage != nil else { return }
@ -52,7 +56,11 @@ struct LoginForm: View {
Divider() Divider()
SecureField( SecureField(
NSLocalizedString(
"login.text_field.password.placeholder", "login.text_field.password.placeholder",
bundle: .module,
comment: "The placeholder for the password text field."
),
text: $password text: $password
) )
.textContentType(.password) .textContentType(.password)

View File

@ -0,0 +1,22 @@
//
// ViewHeightGeometry.swift
// Login
//
// Created by Javier Cicchelli on 02/12/2022.
// Copyright © 2022 Röck+Cöde. All rights reserved.
//
import SwiftUI
struct ViewHeightGeometry: View {
var body: some View {
GeometryReader { proxy in
Color.clear.preference(
key: ViewHeightPreferenceKey.self,
value: proxy.size.height
+ proxy.safeAreaInsets.top
+ proxy.safeAreaInsets.bottom
)
}
}
}

View File

@ -0,0 +1,17 @@
//
// ViewHeightPreferenceKey.swift
// Login
//
// Created by Javier Cicchelli on 02/12/2022.
// Copyright © 2022 Röck+Cöde. All rights reserved.
//
import SwiftUI
struct ViewHeightPreferenceKey: PreferenceKey {
static var defaultValue: CGFloat = 0
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
value = nextValue()
}
}

View File

@ -0,0 +1,34 @@
//
// LogInLabelStyle.swift
// Login
//
// Created by Javier Cicchelli on 02/12/2022.
// Copyright © 2022 Röck+Cöde. All rights reserved.
//
import SwiftUI
struct LogInLabelStyle: LabelStyle {
func makeBody(configuration: Configuration) -> some View {
HStack(spacing: 8) {
Spacer()
configuration.title
.font(.body)
.foregroundColor(.primary)
configuration.icon
.tint(.primary)
Spacer()
}
}
}
// MARK: - LabelStyle
extension LabelStyle where Self == LogInLabelStyle {
static var logIn: Self {
LogInLabelStyle()
}
}

View File

@ -1,6 +1,6 @@
// //
// LoginView.swift // LoginView.swift
// BeReal // Login
// //
// Created by Javier Cicchelli on 30/11/2022. // Created by Javier Cicchelli on 30/11/2022.
// Copyright © 2022 Röck+Cöde. All rights reserved. // Copyright © 2022 Röck+Cöde. All rights reserved.
@ -54,7 +54,11 @@ fileprivate extension LoginView {
var body: some View { var body: some View {
VStack(spacing: 32) { VStack(spacing: 32) {
Text("login.title.text", bundle: .module) Text(
"login.title.text",
bundle: .module,
comment: "Login view title text."
)
.font(.largeTitle) .font(.largeTitle)
.fontWeight(.bold) .fontWeight(.bold)
.foregroundColor(.primary) .foregroundColor(.primary)
@ -71,7 +75,11 @@ fileprivate extension LoginView {
// TODO: login with the username and password. // TODO: login with the username and password.
} label: { } label: {
Label { Label {
Text("login.button.log_in.text", bundle: .module) Text(
"login.button.log_in.text",
bundle: .module,
comment: "Log in button text."
)
.fontWeight(.semibold) .fontWeight(.semibold)
} icon: { } icon: {
if isAuthenticating { if isAuthenticating {
@ -80,7 +88,7 @@ fileprivate extension LoginView {
EmptyView() EmptyView()
} }
} }
.labelStyle(LogInLabelStyle()) .labelStyle(.logIn)
} }
.tint(.orange) .tint(.orange)
.buttonStyle(.borderedProminent) .buttonStyle(.borderedProminent)
@ -90,38 +98,6 @@ fileprivate extension LoginView {
} }
} }
} }
struct ViewHeightGeometry: View {
var body: some View {
GeometryReader { proxy in
Color.clear.preference(
key: ViewHeightPreferenceKey.self,
value: proxy.size.height + proxy.safeAreaInsets.top + proxy.safeAreaInsets.bottom
)
}
}
}
}
// MARK: - Label styles
private extension LoginView.LoginContainer {
struct LogInLabelStyle: LabelStyle {
func makeBody(configuration: Configuration) -> some View {
HStack(spacing: 8) {
Spacer()
configuration.title
.font(.body)
.foregroundColor(.primary)
configuration.icon
.tint(.primary)
Spacer()
}
}
}
} }
// MARK: - Helpers // MARK: - Helpers
@ -132,16 +108,6 @@ private extension LoginView.LoginContainer {
} }
} }
// MARK: - Preference keys
struct ViewHeightPreferenceKey: PreferenceKey {
static var defaultValue: CGFloat = 0
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
value = nextValue()
}
}
// MARK: - Previews // MARK: - Previews
struct LoginView_Previews: PreviewProvider { struct LoginView_Previews: PreviewProvider {