Post

Replies

Boosts

Views

Activity

How to navigate from side menu in SwiftUI to new SwiftUI.
I have side bar menu in my project, it is work correctly, but I want to use every side bar option menu, when I click any side bar menu, it may router to other Swift UI. How can I create Swift UI for every side option menu? SideMenuViewModel: enum SideMenuViewModel: Int, CaseIterable { case profile case lists case bookmarks case messages var title: String { switch self { case .profile: return "Profile" case .lists: return "lists" case .bookmarks: return "bookmarks" case .messages: return "messages" }} var imageName: String { switch self { case .profile: return "profile" case .lists: return "list.bullet" case .bookmarks: return "bookmark" case .messages: return "message" }}} SideMenuView: struct SideMenuView: View { @Binding var isShowing: Bool var body: some View { ZStack { LinearGradient(gradient: Gradient(colors: [Color("red"), Color("blue")]), startPoint: .top, endPoint: .bottom) .ignoresSafeArea() VStack { SideMenuHeaderView(isShowing: $isShowing) .frame(height: 240) ForEach(SideMenuViewModel.allCases, id:\.self) { option in NavigationLink( destination: Text(option.title), label: { SideMenuOptionView(viewModel: option) })} Spacer() }}.navigationBarHidden(true) }}
0
0
811
Mar ’21
Using sidebar menu with tabbar in SwiftUI
I have sidebar menu, I want to integrate with my app. In app, I have tabbar, sidebar menu not work correctly with tab bar. Any idea will be appreciated? var body: some View { SideMenuView() TabView(selection: $selection){ PeopleView() .tabItem { selection == 0 ? Image("people-selected") : Image("people") } .tag(0) AnimalView() .tabItem { selection == 1 ? Image("animal-selected") : Image("animal") } .tag(1) PlantsView() .tabItem { selection == 2 ? Image("plants-selected") : Image("plants") } .tag(2) }
0
0
891
Mar ’21
Using slide menu with bottom navigation bar
I have a simple slide menu project in SwiftUI, and I want to add bottom navigation bar in my project, but when I click the slide menu button, I want to draw bottom navigation bar as well like in image. - https://stackoverflow.com/questions/66693507/using-slide-menu-with-bottom-navigation-bar Any idea will be appreciated. Drawer: struct Home: View { // Hiding tab Bar... init() { UITabBar.appearance().isHidden = true } @StateObject var menuData = MenuViewModel() @Namespace var animation var body: some View { HStack(spacing: 0){ // Drawer And Main View... // Drawer... Drawer(animation: animation) // Main View... TabView(selection: $menuData.selectedMenu){ Catalogue() .tag("Catalogue") Orders() .tag("Your Orders") Cart() .tag("Your Cart") Favourites() .tag("Favourites") } .frame(width: UIScreen.main.bounds.width) } // Max Frame... .frame(width: UIScreen.main.bounds.width) // Moving View.... // 250/2 = 125.... .offset(x: menuData.showDrawer ? 125 : -125) .overlay( ZStack{ if !menuData.showDrawer{ DrawerCloseButton(animation: animation) .padding() } }, alignment: .topLeading ) // Setting As Environment Object.... // For Avoiding Re-Declarations... .environmentObject(menuData) } }
0
0
1k
Mar ’21
Destination view for multiple list item in SwiftUI
I have list item, and all item destination view routed to EndView, how can I add multiple destination view for every item, for example: when I click the first item it will open EndView, when I click the second item it will open NewView...., any idea will be appreciated. Option: struct InnerOptionValues: Codable {   var title: String   var image: String   var isAddSection: Bool   var isUseToggle: Bool   var headerTitle: String } extension Option {   static let listValues: [InnerOptionValues] = [     .init(title: "title1", image: "image1", isAddSection: true, isUseToggle: false, headerTitle: ""),     .init(title: "title2",image: "image2", isAddSection: false, isUseToggle: false, headerTitle: ""),     .init(title: "title3", image: "image3", isAddSection: false, isUseToggle: false, headerTitle: ""),     .init(title: "4", image: "image4", isAddSection: false, isUseToggle: false, headerTitle: ""),     .init(title: "5", image: "image5", isAddSection: false, isUseToggle: false, headerTitle: ""),   ]     InnerView: struct InnerView: View {   let value: InnerOptionValues       var body: some View {     return NavigationLink(destination: EndView(value: value)) {       HStack {         Image(value.image)           .resizable()           .frame(width: 16, height: 16)           .aspectRatio(contentMode: .fill)         Text(value.title)           .foregroundColor(.blue)           .font(.system(size: 18))       }     }   } } struct EndView: View {   let value: InnerOptionValues       var body: some View {     return NavigationLink(destination: EndView(value: value)) {               Text("Coming Soon!!!")         .font(.system(size: 25))         .foregroundColor(.blue)     } .navigationBarTitle(Text(value.title), displayMode: .inline)   } }
0
0
505
Apr ’21
How can I hide bottom navigation bar when I click the list item?
I have bottom navigation bar and in fist view I have list item, when I click the list item, it is open detail view, but bottom navigation bar still stay in detail view, I want to hide navigation bar when I click open the detail view. Is it possible? ContentView: struct TabView : View {   @State private var selection = 0   @State var index = 0       var body: some View{           VStack(spacing: 0){               ZStack{                 ListView()                     .opacity(self.index == 0 ? 1 : 0)         }               HStack{                   Button(action: {                       self.index = 0                     }) {                       HStack(spacing: 6){                         Image("List")                              .foregroundColor(self.index == 0 ? Color("blue") : .black)                           if self.index == 0{                               Text("List")                 .foregroundColor(Color("blue"))             }                         }           .padding(.vertical,10)           .padding(.horizontal)           .background(self.index == 0 ? Color("tabbar-background") : Color.clear)           .clipShape(Capsule())         }                   Spacer(minLength: 0)                   Button(action: {                       self.index = 1                     }) {                       HStack(spacing: 6){                         Image("SecondList")                              .foregroundColor(self.index == 1 ? Color("blue") : .black)                           if self.index == 1{                               Text("SecondList")                 .foregroundColor(Color("blue"))             }                         }           .padding(.vertical,10)           .padding(.horizontal)           .background(self.index == 1 ? Color("tabbar-background"): Color.clear)           .clipShape(Capsule())         }}}     .edgesIgnoringSafeArea(.bottom)   } } ListView: struct ListView: View {   var body: some View {     VStack{       ScrollView(.vertical, showsIndicators: false, content: {         VStack(spacing: 15){             RowView(docs: docs)                       }         }         }   }     } } struct RowView: View {   @State var docs: Datas   var body: some View {          HStack(spacing: 15){       NavigationLink(destination:  ListDetailView(docs: docs)) {       HStack{       Image(docs.image)         .resizable()         .frame(width: 64, height: 48)                }       }     }     .padding(.horizontal)         } } ListDetailView: import SwiftUI struct ListDetailView: View {   @State var docs: Datas       var body: some View {                 ZStack{       Image(docs.image)         .resizable()         .aspectRatio(contentMode: .fit)             }              } } struct ListDetailView_Previews: PreviewProvider {   static var previews: some View {     ListDetailView(docs: datas[0])           } }
0
0
989
Aug ’21
Why it is throw an error as "'windows' was deprecated in iOS 15.0: Use UIWindowScene.windows on a relevant window scene instead" in SwiftUI?
I have project in SwiftUI 2.0 but when I update to SwiftUI 3.0 it is throw an error for windows as a windows' was deprecated in iOS 15.0: Use UIWindowScene.windows on a relevant window scene instead any idea?     .padding(.top, UIApplication.shared.windows.first?.safeAreaInsets.top)
0
0
668
Feb ’22
How can I add costom emoji to example chat app?
I have simple chat app, and I want to use simple emoji in this chat app, my emoji is located in EmojiView an when I click the emoji button, I want to add in live chat, but I do not know how I will forward for it, I was look at many resources but I did not find any example on internet, is it possible to do it? import SwiftUI struct MessageDetailsView: View {   var body: some View {     HomeMessageDetails()}} struct MessageDetailsView_Previews: PreviewProvider {      static var previews: some View {     MessageDetailsView()      }} struct HomeMessageDetails : View {   @State var message = ""   @StateObject var allMessages = Messages()   @State private var emojiData = false   var body: some View{           ZStack {       VStack{         ScrollView(.vertical, showsIndicators: false, content: {           ScrollViewReader{reader in             VStack{               ForEach(allMessages.messages){message in                 ChatBubble(message: message)               }                .onChange(of: allMessages.messages) { (value) in                 if value.last!.chatMessages{                   reader.scrollTo(value.last?.id)}}}             .padding([.horizontal,.bottom])}})         HStack {             HStack{             TextField("Message", text: self.$message)             Button(action: {             emojiData = true             }, label: {               Image("emoji")             }) .sheet(isPresented: $emojiData) {           EmojiView()         } }           .padding(.vertical, 10)           .padding(.horizontal)                Button(action: {             allMessages.messages.append(Message(id: Date(), message: message, chatMessages: true))                           message = ""           }, label: {             Image("reply")              })   }         .padding(.horizontal)       }} }} struct ChatBubble : View {   var message : Message   var body: some View{     HStack(alignment: .top,spacing: 10){       if message.chatMessages{         Text(message.message)           .foregroundColor(Color("black))         }             else{         Text(message.message)             .foregroundColor(.white)  }}     .id(message.id)}} struct Message : Identifiable,Equatable{   var id : Date   var message : String   var chatMessages : Bool    } class Messages : ObservableObject{   @Published var messages : [Message] = []   init() {           let strings = ["Hii","Hello !!!!"]     for i in 0..<strings.count{       messages.append(Message(id: Date(), message: strings[i], chatMessages: i % 2 == 0 ? true : false))}}           func writeMessage(id: Date,message: String,chatMessages: Bool){           messages.append(Message(id: id, message: message, chatMessages: chatMessages))}} struct EmojiView: View {   var body: some View {  Button(action: {             }, label: {               Image("smile_emoji")                           }) }}
0
0
398
Feb ’22
How can use model in view shortly?
I have small restaurans data in content view, but I want to use this data shortly inside of the homeview, I am typing   to use  @State var restaurants: [ Restaurant] but in other view I have HomeView, it is throw an error like     Cannot convert value of type '[Restaurant].Type' to expected argument type '[Restaurant]' for    HomeView( restaurants: [Restaurant]) line of code, I do not know what I missed? Any idea? struct HomeView: View { @State var restaurants = [ Restaurant(name: "Cafe Deadend", image: "cafedeadend"), Restaurant(name: "Homei", image: "homei"), Restaurant(name: "Teakha", image: "teakha"), Restaurant(name: "Cafe Loisl", image: "cafeloisl"), ] }
0
0
331
Feb ’22
Why I am not succes to register in my app in SwiftUI?
I am use firebase for my SwiftUI App, and I want to register with mail, but when I typing my mail it is throw an error like Oops! Something went wrong. Please try again. I do not know why? here is my code: StatusViewModel: class StatusViewModel: Identifiable, ObservableObject {       var title: String   var message: String       init(title: String = "", message: String = "") {     self.title = title     self.message = message   }       static var signUpSuccessStatus: StatusViewModel {     return StatusViewModel(title: "Successful", message: "Your account has been created successfully")   }       static var logInSuccessStatus: StatusViewModel {     return StatusViewModel(title: "Successful", message: "Your account has been logged in successfully")   }       static var errorStatus: StatusViewModel {     return StatusViewModel(title: "Error", message: "Oops! Something went wrong. Please try again.")   } } RegisterViewModel: import Foundation import Combine class RegisterViewModel: ObservableObject {   @Published var email: String = ""   @Published var password: String = ""   @Published var statusViewModel: StatusViewModel?   @Published var state: AppState       private var cancellableBag = Set<AnyCancellable>()   private let authAPI: AuthAPI       init(authAPI: AuthAPI, state: AppState) {     self.authAPI = authAPI     self.state = state   }       func signUp() {     authAPI.signUp(email: email, password: password)       .receive(on: RunLoop.main)       .map(resultMapper)       .replaceError(with: StatusViewModel.errorStatus)       .assign(to: \.statusViewModel, on: self)       .store(in: &cancellableBag)   } } extension RegisterViewModel {   private func resultMapper(with user: User?) -> StatusViewModel {     if user != nil {       state.currentUser = user       return StatusViewModel.signUpSuccessStatus     } else {       return StatusViewModel.errorStatus     }   } } struct Register: View {       @ObservedObject private var viewModel: RegisterViewModel   @State var pushActive = false         init(state: AppState) {           self.viewModel = RegisterViewModel(authAPI: AuthService(), state: state)           }   var body: some View {   NavigationLink(destination: HomeView(state: viewModel.state),                       isActive: self.$pushActive) {                 Button {                              self.viewModel.signUp()                                     } label: {                   Text("Register")                     .padding()                                     }               } } }
0
0
538
Mar ’22
How we can use the multiple register screen in SwiftUI for firebase?
I have multiple register screen in swiftUI, I did not understand how I will connect first register screen to second register screen, normally first register screen connect to main screen, but I want to connect first register screen to second register screen, and connect second register screen to main screen, how can I do it, any idea? StatusViewModel: class StatusViewModel: Identifiable, ObservableObject {       var title: String   var message: String       init(title: String = "", message: String = "") {     self.title = title     self.message = message   }       static var signUpSuccessStatus: StatusViewModel {     return StatusViewModel(title: "Successful", message: "Your account has been created successfully")   }       static var logInSuccessStatus: StatusViewModel {     return StatusViewModel(title: "Successful", message: "Your account has been logged in successfully")   }       static var errorStatus: StatusViewModel {     return StatusViewModel(title: "Error", message: "Oops! Something went wrong. Please try again.")   } } RegisterViewModel: import Foundation import Combine class RegisterViewModel: ObservableObject {   @Published var email: String = ""   @Published var password: String = ""   @Published var statusViewModel: StatusViewModel?   @Published var state: AppState       private var cancellableBag = Set<AnyCancellable>()   private let authAPI: AuthAPI       init(authAPI: AuthAPI, state: AppState) {     self.authAPI = authAPI     self.state = state   }       func signUp() {     authAPI.signUp(email: email, password: password)       .receive(on: RunLoop.main)       .map(resultMapper)       .replaceError(with: StatusViewModel.errorStatus)       .assign(to: \.statusViewModel, on: self)       .store(in: &cancellableBag)   } } extension RegisterViewModel {   private func resultMapper(with user: User?) -> StatusViewModel {     if user != nil {       state.currentUser = user       return StatusViewModel.signUpSuccessStatus     } else {       return StatusViewModel.errorStatus     }   } } first register screen: struct Register: View {       @ObservedObject private var viewModel: RegisterViewModel   @State var pushActive = false         init(state: AppState) {           self.viewModel = RegisterViewModel(authAPI: AuthService(), state: state)           }   var body: some View {  VStack(){                               TextField("Email Address",text:$viewModel.email)                 .autocapitalization(.none)                 .padding()                  HStack(spacing: 15){                     TextField("Password", text: $viewModel.password)                       .autocapitalization(.none)                                 }   NavigationLink(destination: HomeView(state: viewModel.state),                       isActive: self.$pushActive) {                 Button {                              self.viewModel.signUp()                                     } label: {                   Text("Register")                     .padding()                                     }               } } } second register screen: struct SecondRegister: View {   var body: some View {           GeometryReader { geometry in          ZStack{           VStack(alignment: .center, spacing: 3){                          TextField("First Name",text:self.$first_name)                 .autocapitalization(.none)                 .padding()               TextField("Last Name", text: self.$last_name)                 .autocapitalization(.none)                 .padding()                                 }                 Button {                 } label: {                   Text("Next")                     .padding()                    }             }           }.padding()           }.padding(.top,60)                 }     }
0
0
563
Mar ’22
Why I am able to register user info to firebase in SwiftUI App?
I have register screen and I am not able to register info to firebase, I put user info on simulator, but it just hold on on screen, and no any change on firebase, any idea? where I missed? import SwiftUI import Firebase struct Register: View {   @State var name = ""   @State var about = ""       @Binding var show : Bool   var body: some View {    VStack(alignment: .center, spacing: 3){                          TextField("Name",text:self.$name)                 .padding()                                       TextField(" about", text: self.$about)                 .padding()                if self.loading{                                          HStack{                                              Spacer()                                              Indicator()                                              Spacer()                     }                   }                                        else{                                 Button {                                       if self.name != "" && self.about != "" {                                                    self.loading.toggle()                     CreateUser(name: self.name, about: self.about) { (status) in                                                          if status{                                                              self.show.toggle()                                                       }                         }                       }                     else{                                                    self.alert.toggle()                                             }                 } label: {                   Text("Next")                     .padding()                    }               } } import Foundation import Firebase func CreateUser(name: String,about : String, completion : @escaping (Bool)-> Void){       let db = Firestore.firestore()       let storage = Storage.storage().reference()       let uid = Auth.auth().currentUser?.uid                   db.collection("users").document(uid!).setData(["name":name,"about":about, "uid":uid!]) { (err) in                   if err != nil{                       print((err?.localizedDescription)!)           return         }                   completion(true)                   UserDefaults.standard.set(true, forKey: "status")                   UserDefaults.standard.set(name, forKey: "UserName")                   NotificationCenter.default.post(name: NSNotification.Name("statusChange"), object: nil)       }     }
0
0
603
Mar ’22