Skip to content

Sign up view #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions SwiftUIBasics.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
5598D3222B2403CF00A6AFD3 /* CircularImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5598D3212B2403CE00A6AFD3 /* CircularImage.swift */; };
5598D3242B24049B00A6AFD3 /* ProfileCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5598D3232B24049B00A6AFD3 /* ProfileCardView.swift */; };
5598D3262B2404FC00A6AFD3 /* ProfileCardVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5598D3252B2404FC00A6AFD3 /* ProfileCardVM.swift */; };
E63894902B2D0EF200B7D57C /* CatsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E638948F2B2D0EF200B7D57C /* CatsView.swift */; };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file not needed on PR

/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -41,6 +42,7 @@
5598D3212B2403CE00A6AFD3 /* CircularImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircularImage.swift; sourceTree = "<group>"; };
5598D3232B24049B00A6AFD3 /* ProfileCardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileCardView.swift; sourceTree = "<group>"; };
5598D3252B2404FC00A6AFD3 /* ProfileCardVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileCardVM.swift; sourceTree = "<group>"; };
E638948F2B2D0EF200B7D57C /* CatsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CatsView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -73,6 +75,7 @@
5570428C2B24D8050048C81C /* SignUpView.swift */,
5570428E2B24E50E0048C81C /* RatingView.swift */,
557042902B24E5220048C81C /* PlansView.swift */,
E638948F2B2D0EF200B7D57C /* CatsView.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -203,6 +206,7 @@
5598D3242B24049B00A6AFD3 /* ProfileCardView.swift in Sources */,
557042952B24F3100048C81C /* RequirementText.swift in Sources */,
557042932B24EFB00048C81C /* FormTextField.swift in Sources */,
E63894902B2D0EF200B7D57C /* CatsView.swift in Sources */,
557042892B24CB310048C81C /* ProfileListView.swift in Sources */,
557042912B24E5220048C81C /* PlansView.swift in Sources */,
5570428D2B24D8050048C81C /* SignUpView.swift in Sources */,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File not needed on PR

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>SwiftUIBasics.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
2 changes: 1 addition & 1 deletion SwiftUIBasics/SwiftUIBasicsApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SwiftUI
struct SwiftUIBasicsApp: App {
var body: some Scene {
WindowGroup {
ContentView()
SignUpView()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not required for testing view

}
}
}
22 changes: 22 additions & 0 deletions SwiftUIBasics/Views/CatsView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// CatsView.swift
// SwiftUIBasics
//
// Created by Gustavo Ali Gómez Trejo on 15/12/23.
//

import SwiftUI

struct CatsView: View {
var body: some View {
List {
ForEach((1..<20)){ _ in

}
}
}
}

#Preview {
CatsView()
}
Comment on lines +10 to +22
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should be skiped on PR

8 changes: 8 additions & 0 deletions SwiftUIBasics/Views/Components/CatsView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// CatsView.swift
// SwiftUIBasics
//
// Created by Gustavo Ali Gómez Trejo on 15/12/23.
//

import Foundation
Comment on lines +1 to +8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

86 changes: 83 additions & 3 deletions SwiftUIBasics/Views/PlansView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,92 @@

import SwiftUI

struct PlansView: View {
struct ContentView2: View {
var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
VStack(alignment:.center){
Text("Choose")
.font(.system(size: 32, weight: .black, design: .serif))
.fontDesign(.rounded)
Text("Your Plan")
.font(.system(size: 32, weight: .black, design: .serif))
.fontDesign(.rounded)
HStack {
CardView(iconName: "", title: "Basic", description: "Per month", price: "$9")
.foregroundStyle(.white)
.background(.purple)
.cornerRadius(6.0)
ZStack {
CardView(iconName: "", title: "Pro", description: "Per month", price: "$19")
.background(.gray)
.cornerRadius(6.0)
BadgeView(text: "Best for designer", padding: 5)
.foregroundStyle(.white)
.background(.orange)
.padding(.top, 200)
}
}
VStack {
CardView(iconName: "sparkles", title: "Team", description: " Per month ", price: "299")
.background(.black)
.foregroundStyle(.white)
.cornerRadius(6.0)
BadgeView(text: "Perfect for teams with 20 memebers", padding: 5)
.foregroundStyle(.white)
.background(.orange)
.padding(.top, -30)

}
}


}
}


#Preview {
PlansView()
ContentView2()
}

struct CardView: View {
var iconName: String
var title: String
var description: String
var price: String

var body: some View {
VStack(spacing: 10) {
Image(systemName: iconName)
.font(.system(size: 40))
.padding(.top, 30)
.padding(.bottom, -15)
VStack(spacing: 10) {
Text(title)
.font(.system(.title, design: .rounded))
.fontWeight(.black)
.padding(.horizontal)
.padding(.vertical)
.padding(.bottom, -25)
Text(price)
.fontWeight(.bold)
.font(.system(size: 40, design: .rounded))
Text(description)
.padding(.horizontal,40)
.padding(.vertical)
.padding(.bottom)
}
}
}

}

struct BadgeView: View {
var text: String
var padding: CGFloat


var body: some View {
Text(text)
.padding(padding)

}
}
78 changes: 68 additions & 10 deletions SwiftUIBasics/Views/SignUpView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,36 @@ import Combine

class SignUpViewModel: ObservableObject {
// inputs
@Published var username: String = ""
@Published var email: String = ""
@Published var password: String = ""
@Published var passwordConfirm: String = ""

// outputs
@Published var isValidUsernameLength: Bool = false
@Published var isValidEmailLength: Bool = false
@Published var isValidPasswordLength: Bool = false
@Published var isValidPasswordUpperCase: Bool = false
@Published var isValidPasswordLowerCase: Bool = false
@Published var isValidPasswordSymbol: Bool = false
@Published var isValidPasswordNumber: Bool = false
@Published var isValidPasswordMatch: Bool = false
@Published var isValid: Bool = false
@Published var isValidPre: Bool = false


private var cancelableSet: Set<AnyCancellable> = []

init() {
$username
$email
.receive(on: RunLoop.main)
.map { username in
return username.count >= 4
.map { email in
let pattern = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}"
if let _ = email.range(of: pattern, options: .regularExpression) {
return true
} else {
return false
}
}
.assign(to: \.isValidUsernameLength, on: self)
.assign(to: \.isValidEmailLength, on: self)
.store(in: &cancelableSet)

$password
Expand All @@ -52,16 +62,59 @@ class SignUpViewModel: ObservableObject {
}
.assign(to: \.isValidPasswordUpperCase, on: self)
.store(in: &cancelableSet)

$password
.receive(on: RunLoop.main)
.map { password in
let pattern = "[a-z]"
if let _ = password.range(of: pattern, options: .regularExpression) {
return true
} else {
return false
}
}
.assign(to: \.isValidPasswordLowerCase, on: self)
.store(in: &cancelableSet)
$password
.receive(on: RunLoop.main)
.map { password in
let pattern = "[0-9]"
if let _ = password.range(of: pattern, options: .regularExpression) {
return true
} else {
return false
}
}
.assign(to: \.isValidPasswordNumber, on: self)
.store(in: &cancelableSet)
$password
.receive(on: RunLoop.main)
.map { password in
let pattern = "[!\"#$%&'()*+,-./:;<=>?@\\[\\\\\\]^_`{|}~]+"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let pattern = "[!\"#$%&'()*+,-./:;<=>?@\\[\\\\\\]^_`{|}~]+"
let pattern = "[\\W]"

if let _ = password.range(of: pattern, options: .regularExpression) {
return true
} else {
return false
}
}
.assign(to: \.isValidPasswordSymbol, on: self)
.store(in: &cancelableSet)

Publishers.CombineLatest($password, $passwordConfirm)
.receive(on: RunLoop.main)
.map { (password, passwordConfirm) in
return !password.isEmpty && !passwordConfirm.isEmpty && password == passwordConfirm
}
.assign(to: \.isValidPasswordMatch, on: self)
.store(in: &cancelableSet)

Publishers.CombineLatest4($isValidPasswordNumber, $isValidPasswordSymbol, $isValidPasswordLowerCase, $isValidPasswordUpperCase)
.map { (a, b, c, d) in
return a && b && c && d
}
.assign(to: \.isValidPre, on: self)
.store(in: &cancelableSet)

Publishers.CombineLatest4($isValidUsernameLength, $isValidPasswordLength, $isValidPasswordUpperCase, $isValidPasswordMatch)
Publishers.CombineLatest4($isValidEmailLength, $isValidPasswordLength, $isValidPre, $isValidPasswordMatch)
.map { (a, b, c, d) in
return a && b && c && d
}
Expand All @@ -80,13 +133,18 @@ struct SignUpView: View {
.bold()
.foregroundStyle(.maryBlue)
.padding(.bottom, 30)
FormTextField(name: "Username", value: $vm.username)
RequirementText(text: "A minimum of 4 characters", isValid: vm.isValidUsernameLength)
FormTextField(name: "Email", value: $vm.email)
.keyboardType(.emailAddress)
.autocapitalization(.none)
RequirementText(text: "Enter a valid Email.", isValid: vm.isValidEmailLength)
.padding()
FormTextField(name: "Password", value: $vm.password, isSecure: true)
VStack {
RequirementText(text: "A minimum of 8 characters", isValid: vm.isValidPasswordLength)
RequirementText(text: "One uppercase letter", isValid: vm.isValidPasswordUpperCase)
RequirementText(text: "One lowercase letter", isValid: vm.isValidPasswordLowerCase)
RequirementText(text: "One symbol", isValid: vm.isValidPasswordSymbol)
RequirementText(text: "One number", isValid: vm.isValidPasswordNumber)
}
.padding()
FormTextField(name: "Confirm Password", value: $vm.passwordConfirm, isSecure: true)
Expand Down