Moved some login code into its own file within the Login module.
This commit is contained in:
parent
9ed753b2fe
commit
a98c5df41e
@ -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(
|
||||||
"login.text_field.username.placeholder",
|
NSLocalizedString(
|
||||||
|
"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(
|
||||||
"login.text_field.password.placeholder",
|
NSLocalizedString(
|
||||||
|
"login.text_field.password.placeholder",
|
||||||
|
bundle: .module,
|
||||||
|
comment: "The placeholder for the password text field."
|
||||||
|
),
|
||||||
text: $password
|
text: $password
|
||||||
)
|
)
|
||||||
.textContentType(.password)
|
.textContentType(.password)
|
||||||
|
22
Modules/Sources/Login/UI/Components/ViewHeightGeometry.swift
Normal file
22
Modules/Sources/Login/UI/Components/ViewHeightGeometry.swift
Normal 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
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
34
Modules/Sources/Login/UI/Styles/LogInLabelStyle.swift
Normal file
34
Modules/Sources/Login/UI/Styles/LogInLabelStyle.swift
Normal 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()
|
||||||
|
}
|
||||||
|
}
|
@ -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,10 +54,14 @@ fileprivate extension LoginView {
|
|||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack(spacing: 32) {
|
VStack(spacing: 32) {
|
||||||
Text("login.title.text", bundle: .module)
|
Text(
|
||||||
.font(.largeTitle)
|
"login.title.text",
|
||||||
.fontWeight(.bold)
|
bundle: .module,
|
||||||
.foregroundColor(.primary)
|
comment: "Login view title text."
|
||||||
|
)
|
||||||
|
.font(.largeTitle)
|
||||||
|
.fontWeight(.bold)
|
||||||
|
.foregroundColor(.primary)
|
||||||
|
|
||||||
LoginForm(
|
LoginForm(
|
||||||
username: $username,
|
username: $username,
|
||||||
@ -71,8 +75,12 @@ 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(
|
||||||
.fontWeight(.semibold)
|
"login.button.log_in.text",
|
||||||
|
bundle: .module,
|
||||||
|
comment: "Log in button text."
|
||||||
|
)
|
||||||
|
.fontWeight(.semibold)
|
||||||
} icon: {
|
} icon: {
|
||||||
if isAuthenticating {
|
if isAuthenticating {
|
||||||
ProgressView()
|
ProgressView()
|
||||||
@ -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 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user