-
Notifications
You must be signed in to change notification settings - Fork 25
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
Login-Pau #88
base: main
Are you sure you want to change the base?
Login-Pau #88
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Bucket | ||
uuid = "1E94BF2F-5C75-4BF5-ACF2-B4A66A488C79" | ||
type = "1" | ||
version = "2.0"> | ||
<Breakpoints> | ||
<BreakpointProxy | ||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> | ||
<BreakpointContent | ||
uuid = "4A216A60-7DB9-4B84-AFB3-532FD5D32B38" | ||
shouldBeEnabled = "Yes" | ||
ignoreCount = "0" | ||
continueAfterRunningActions = "No" | ||
filePath = "SwiftUIBasics/Views/PlansView.swift" | ||
startingColumnNumber = "9223372036854775807" | ||
endingColumnNumber = "9223372036854775807" | ||
startingLineNumber = "9" | ||
endingLineNumber = "9" | ||
landmarkName = "unknown" | ||
landmarkType = "0"> | ||
</BreakpointContent> | ||
</BreakpointProxy> | ||
</Breakpoints> | ||
</Bucket> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,30 @@ | ||
// | ||
// RatingView.swift | ||
// SwiftUIBasics | ||
// | ||
// Created by Diplomado on 09/12/23. | ||
// | ||
|
||
import SwiftUI | ||
struct StarRatingView: View { | ||
@State private var rating: Int = 0 | ||
|
||
struct RatingView: View { | ||
var body: some View { | ||
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) | ||
VStack { | ||
Text("Selected Rating: \(rating)") | ||
|
||
HStack { | ||
ForEach(1...5, id: \.self) { index in | ||
Image(systemName: index <= self.rating ? "star.fill" : "star") | ||
.resizable() | ||
.frame(width: 40, height: 40) | ||
.foregroundColor(.yellow) | ||
.onTapGesture { | ||
self.rating = index | ||
} | ||
} | ||
} | ||
} | ||
.padding() | ||
} | ||
} | ||
|
||
#Preview { | ||
RatingView() | ||
struct ContentView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
StarRatingView() | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,37 @@ | ||
// | ||
// SignUpView.swift | ||
// SwiftUIBasics | ||
// | ||
// Created by Diplomado on 09/12/23. | ||
// | ||
|
||
import SwiftUI | ||
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 isValidPasswordLength: Bool = false | ||
@Published var isValidPasswordUpperCase: Bool = false | ||
@Published var isValidEmail: Bool = false | ||
@Published var isValidPassword: Bool = false | ||
@Published var isValidPasswordMatch: Bool = false | ||
@Published var isValid: Bool = false | ||
|
||
private var cancelableSet: Set<AnyCancellable> = [] | ||
|
||
init() { | ||
$username | ||
.receive(on: RunLoop.main) | ||
.map { username in | ||
return username.count >= 4 | ||
} | ||
.assign(to: \.isValidUsernameLength, on: self) | ||
.store(in: &cancelableSet) | ||
|
||
$password | ||
.receive(on: RunLoop.main) | ||
.map { password in | ||
return password.count >= 8 | ||
.map { email in | ||
let emailPattern = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}" | ||
let emailPredicate = NSPredicate(format: "SELF MATCHES %@", emailPattern) | ||
return emailPredicate.evaluate(with: email) | ||
} | ||
.assign(to: \.isValidPasswordLength, on: self) | ||
.assign(to: \.isValidEmail, 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 | ||
} | ||
return password.isValidPassword() | ||
} | ||
.assign(to: \.isValidPasswordUpperCase, on: self) | ||
.assign(to: \.isValidPassword, on: self) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the other bindings are being ignored |
||
.store(in: &cancelableSet) | ||
|
||
Publishers.CombineLatest($password, $passwordConfirm) | ||
|
@@ -61,9 +42,9 @@ class SignUpViewModel: ObservableObject { | |
.assign(to: \.isValidPasswordMatch, on: self) | ||
.store(in: &cancelableSet) | ||
|
||
Publishers.CombineLatest4($isValidUsernameLength, $isValidPasswordLength, $isValidPasswordUpperCase, $isValidPasswordMatch) | ||
.map { (a, b, c, d) in | ||
return a && b && c && d | ||
Publishers.CombineLatest3($isValidEmail, $isValidPassword, $isValidPasswordMatch) | ||
.map { (a, b, c) in | ||
return a && b && c | ||
} | ||
.assign(to: \.isValid, on: self) | ||
.store(in: &cancelableSet) | ||
|
@@ -78,21 +59,28 @@ struct SignUpView: View { | |
Text("Create an account") | ||
.font(.system(.largeTitle, design: .rounded)) | ||
.bold() | ||
.foregroundStyle(.maryBlue) | ||
.foregroundColor(.maryBlue) | ||
Comment on lines
-81
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this change indicates me that you are using an older version of XCode, when that happen try to avoid to commit those changes |
||
.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) | ||
RequirementText(text: "Valid email format", isValid: vm.isValidEmail) | ||
.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: "At least 8 characters", isValid: vm.isValidPassword) | ||
RequirementText(text: "At least one uppercase letter", isValid: vm.password.containsUppercase()) | ||
RequirementText(text: "At least one lowercase letter", isValid: vm.password.containsLowercase()) | ||
RequirementText(text: "At least one symbol", isValid: vm.password.containsSymbol()) | ||
RequirementText(text: "At least one number", isValid: vm.password.containsNumber()) | ||
} | ||
.padding() | ||
|
||
FormTextField(name: "Confirm Password", value: $vm.passwordConfirm, isSecure: true) | ||
RequirementText(text: "Your confirm password should be the same as password", isValid: vm.isValidPasswordMatch) | ||
.padding() | ||
.padding(.bottom, 50) | ||
|
||
Button(action: { | ||
print("Doing") | ||
// Proceed to the next screen | ||
|
@@ -104,7 +92,6 @@ struct SignUpView: View { | |
.padding() | ||
.frame(minWidth: 0, maxWidth: .infinity) | ||
.background(vm.isValid ? .maryBlue :.turquoise) | ||
// .background(LinearGradient(gradient: Gradient(colors: [.turquoise, .maryBlue]), startPoint: .leading, endPoint: .trailing)) | ||
.cornerRadius(10) | ||
.padding(.horizontal) | ||
} | ||
|
@@ -129,6 +116,33 @@ struct SignUpView: View { | |
} | ||
} | ||
|
||
#Preview { | ||
SignUpView() | ||
extension String { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
func isValidPassword() -> Bool { | ||
// Implement your password validation logic here | ||
return self.count >= 8 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also its only checking for password lenght the other valiations are being skiped |
||
} | ||
|
||
func containsUppercase() -> Bool { | ||
return self.rangeOfCharacter(from: .uppercaseLetters) != nil | ||
} | ||
|
||
func containsLowercase() -> Bool { | ||
return self.rangeOfCharacter(from: .lowercaseLetters) != nil | ||
} | ||
|
||
func containsSymbol() -> Bool { | ||
let symbolCharacterSet = CharacterSet(charactersIn: "!@#$%^&*()-_=+[]{}|;:'\",.<>/?`~") | ||
return self.rangeOfCharacter(from: symbolCharacterSet) != nil | ||
} | ||
|
||
func containsNumber() -> Bool { | ||
return self.rangeOfCharacter(from: .decimalDigits) != nil | ||
} | ||
} | ||
|
||
struct SignUpView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
SignUpView() | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File not needed for the PR