Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import SwiftUI
- struct ContentView: View {
- @State private var showingLoginSheet = false
- @State private var login = ""
- @State private var password = ""
- @State private var showingLoginFailedAlert = false
- var body: some View {
- NavigationView {
- VStack {
- Spacer()
- Text("Witamy w X")
- .font(.largeTitle)
- .padding(.bottom, 10)
- Text("Wybierz sposób logowania")
- .font(.subheadline)
- .padding(.bottom, 40)
- VStack(spacing: 20) {
- NavigationLink(destination: GuestPhotoGridView()) {
- Text("Jako gość")
- .font(.headline)
- .frame(minWidth: 0, maxWidth: .infinity)
- .padding()
- .background(Color.blue)
- .foregroundColor(.white)
- .cornerRadius(10)
- }
- Button(action: {
- showingLoginSheet = true
- }) {
- Text("Zaloguj się")
- .font(.headline)
- .frame(minWidth: 0, maxWidth: .infinity)
- .padding()
- .background(Color.green)
- .foregroundColor(.white)
- .cornerRadius(10)
- }
- .sheet(isPresented: $showingLoginSheet) {
- VStack {
- Text("Logowanie")
- .font(.headline)
- .padding()
- TextField("Login", text: $login)
- .textFieldStyle(RoundedBorderTextFieldStyle())
- .padding()
- SecureField("Hasło", text: $password)
- .textFieldStyle(RoundedBorderTextFieldStyle())
- .padding()
- HStack {
- Button("Anuluj") {
- showingLoginSheet = false
- }
- .padding()
- Button("OK") {
- if login == "TestUser" && password == "TestPassword" {
- showingLoginFailedAlert = false
- login = ""
- password = ""
- showingLoginSheet = false
- // Navigate to user photo grid view
- if let window = UIApplication.shared.windows.first {
- window.rootViewController = UIHostingController(rootView: UserPhotoGridView())
- window.makeKeyAndVisible()
- }
- } else {
- showingLoginFailedAlert = true
- showingLoginSheet = false
- }
- }
- .padding()
- }
- }
- .padding()
- }
- .alert(isPresented: $showingLoginFailedAlert) {
- Alert(title: Text("Błąd"),
- message: Text("Nieprawidłowy login lub hasło"),
- primaryButton: .default(Text("OK")),
- secondaryButton: .default(Text("Zaloguj jako gość"), action: {
- // Navigate to guest photo grid view
- if let window = UIApplication.shared.windows.first {
- window.rootViewController = UIHostingController(rootView: GuestPhotoGridView())
- window.makeKeyAndVisible()
- }
- }))
- }
- }
- .padding(.horizontal, 40)
- Spacer()
- }
- .navigationBarTitle("Ekran Logowania", displayMode: .inline)
- }
- }
- }
- struct GuestPhotoGridView: View {
- var body: some View {
- Text("Photo Grid View for Guest")
- }
- }
- struct UserPhotoGridView: View {
- var body: some View {
- VStack {
- Text("Photo Grid View for User")
- Button(action: {
- // Action to add a recipe (not implemented yet)
- }) {
- Text("Dodaj przepis")
- .font(.headline)
- .padding()
- .background(Color.orange)
- .foregroundColor(.white)
- .cornerRadius(10)
- }
- }
- .padding()
- }
- }
- struct ContentView_Previews: PreviewProvider {
- static var previews: some View {
- ContentView()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement