Post

Replies

Boosts

Views

Activity

Why I am not able to use mobile authentication for firebase in SwiftUI project?
I have a problem in my SwiftUI project, I try to use mobile authentication with firebase, when I put my number and click the button , it is throw an error as a If app delegate swizzling is disabled, remote notifications received by UIApplicationDelegate need to be forwarded to FIRAuth's canHandleNotification: method. I am still do not understand what I missed? @State var no = "" @State var show = false @State var msg = "" @State var alert = false @State var ID = "" var body : some View{ VStack{ TextField("No",text:self.$no) NavigationLink(destination: CodeView(show: $show, ID: $ID), isActive: $show) { Button { PhoneAuthProvider.provider().verifyPhoneNumber(self.no, uiDelegate: nil) { (ID, err) in if err != nil{ self.msg = (err?.localizedDescription)! self.alert.toggle() return } self.ID = ID! self.show.toggle() } } label: { Text("OK") .padding() } } } .alert(isPresented: $alert) { Alert(title: Text("Error"), message: Text(self.msg), dismissButton: .default(Text("Ok"))) } } CodeView: @State var scode = "" @State var show = false @State var msg = "" @State var alert = false @State var ID = "" VStack { TextField("SMS Code", text: self.$scode) NavigationLink(destination: HomeView(), isActive: $show) { Button { let credential = PhoneAuthProvider.provider().credential(withVerificationID: self.ID, verificationCode: self.scode) Auth.auth().signIn(with: credential) { (res, err) in if err != nil{ self.msg = (err?.localizedDescription)! self.alert.toggle() return } UserDefaults.standard.set(true, forKey: "status") NotificationCenter.default.post(name: NSNotification.Name("statusChange"), object: nil) } } label: { Text("Next") .padding() } } .alert(isPresented: $alert) { Alert(title: Text("Error"), message: Text(self.msg), dismissButton: .default(Text("Ok"))) } MyApp: import SwiftUI import Firebase @main struct App: App { init() { FirebaseApp.configure() } var body: some Scene { WindowGroup { ZStack{ ContentView() } } } }
1
0
1.7k
Mar ’22
How can I use custom image instead of the ImagePicker in SwiftUI?
I have simple chat app, and it is work for image picker, but I have custom image view and it fetch the images from internet, I want to use them instead of the image picker in my phone, but I did not find any solution, is there any idea about it? struct Home: View { @State var message = "" @State var imagePicker = false @State var imgData: Data = Data(count: 0) @StateObject var allMessages = Messages() var body: some View { ZStack { VStack { VStack { // Displaying Message ScrollView(.vertical, showsIndicators: true) { ScrollViewReader { reader in VStack(spacing: 20) { ForEach(allMessages.messages) { msg in ChatBubble(msg: msg) } .onChange(of: allMessages.messages) { value in if value.last!.myMsg { reader.scrollTo(value.last?.id) }}}}}}} .clipShape(RoundedRectangle(cornerRadius: 35))} VStack { HStack(spacing: 15) { HStack(spacing: 15) { TextField("Message", text: $message) Button(action: { // toggling image picker imagePicker.toggle() }) { Image(systemName: "paperclip.circle.fill") .font(.system(size: 22)) .foregroundColor(.gray)} .background(Color.black.opacity(0.06)) .clipShape(Capsule()) if message != "" { Button(action: { withAnimation(.easeIn) { allMessages.messages.append(Message(id: Date(), message: message, myMsg: true, profilePic: "p1", photo: nil)) } message = "" }) { Image(systemName: "paperplane.fill") .font(.system(size: 22)) .foregroundColor(Color("Color")) // rotating the image .rotationEffect(.init(degrees: 45)) .clipShape(Circle())}}} .padding(.bottom) .padding(.horizontal) .background(Color.white) .animation(.easeOut) } .fullScreenCover(isPresented: $imagePicker, onDismiss: { if imgData.count != 0 { allMessages.writeMessage(id: Date(), msg: "", photo: imgData, myMsg: true, profilePic: "p1") } }) { ImagePicker(imagePicker: $imagePicker, imgData: $imgData) }}}} struct ChatBubble: View { var msg: Message var body: some View { HStack(alignment: .top, spacing: 10) { if msg.myMsg { if msg.photo == nil { Text(msg.message) .padding(.all) .background(Color.black.opacity(0.06)) .clipShape(BubbleArrow(myMsg: msg.myMsg)) } else { Image(uiImage: UIImage(data: msg.photo!)!) .resizable() .frame(width: UIScreen.main.bounds.width - 150, height: 150) .clipShape(BubbleArrow(myMsg: msg.myMsg)) } Image(msg.profilePic) .resizable() .frame(width: 30, height: 30) .clipShape(Circle()) } else { Image(msg.profilePic) .resizable() .frame(width: 30, height: 30) .clipShape(Circle()) if msg.photo == nil { Text(msg.message) .foregroundColor(.white) .padding(.all) .background(Color("Color")) .clipShape(BubbleArrow(myMsg: msg.myMsg)) } else { Image(uiImage: UIImage(data: msg.photo!)!) .resizable() .frame(width: UIScreen.main.bounds.width - 150, height: 150) .clipShape(BubbleArrow(myMsg: msg.myMsg))}}} .id(msg.id)}} struct RoundedShape: Shape { func path(in rect: CGRect) -> Path { let path = UIBezierPath(roundedRect: rect, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: 35, height: 35)) return Path(path.cgPath) } } struct Message: Identifiable, Equatable { var id: Date var message: String var myMsg: Bool var profilePic: String var photo: Data? } class Messages: ObservableObject { @Published var messages: [Message] = [] init() { let strings = ["Hii", "Hello!!", "What's up?", "What Are you doing?", "Nothing, just enjoying quarantine holidays.. you??", "Same :))", "Ohhh", "What about your country?", "Very very bad..", "Ok, be safe.", "Ok", "Bye"] for i in 0..<strings.count { // simple logic for two side message View messages.append(Message(id: Date(), message: strings[i], myMsg: i % 2 == 0, profilePic: i % 2 == 0 ? "p1" : "p2")) } } func writeMessage(id: Date, msg: String, photo: Data?, myMsg: Bool, profilePic: String) { messages.append(Message(id: id, message: msg, myMsg: myMsg, profilePic: profilePic, photo: photo)) } } CustomImageView: struct CustomImageView: View { private let threeColumnGrid = [ GridItem(.flexible(minimum: 40)), GridItem(.flexible(minimum: 40)), GridItem(.flexible(minimum: 40)), ] var body: some Scene { LazyVGrid(columns: threeColumnGrid, alignment: .center) { ForEach(model.imageNames, id: \.self) { item in GeometryReader { gr in Image(item) .resizable() .scaledToFill() .frame(height: gr.size.width) } .clipped() .aspectRatio(1, contentMode: .fit) } } } }
1
0
1.1k
Mar ’22
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
514
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
1k
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
682
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
413
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
341
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
561
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
576
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
640
Mar ’22
Why I am not able to use mobile authentication for firebase in SwiftUI project?
I have a problem in my SwiftUI project, I try to use mobile authentication with firebase, when I put my number and click the button , it is throw an error as a If app delegate swizzling is disabled, remote notifications received by UIApplicationDelegate need to be forwarded to FIRAuth's canHandleNotification: method. I am still do not understand what I missed? @State var no = "" @State var show = false @State var msg = "" @State var alert = false @State var ID = "" var body : some View{ VStack{ TextField("No",text:self.$no) NavigationLink(destination: CodeView(show: $show, ID: $ID), isActive: $show) { Button { PhoneAuthProvider.provider().verifyPhoneNumber(self.no, uiDelegate: nil) { (ID, err) in if err != nil{ self.msg = (err?.localizedDescription)! self.alert.toggle() return } self.ID = ID! self.show.toggle() } } label: { Text("OK") .padding() } } } .alert(isPresented: $alert) { Alert(title: Text("Error"), message: Text(self.msg), dismissButton: .default(Text("Ok"))) } } CodeView: @State var scode = "" @State var show = false @State var msg = "" @State var alert = false @State var ID = "" VStack { TextField("SMS Code", text: self.$scode) NavigationLink(destination: HomeView(), isActive: $show) { Button { let credential = PhoneAuthProvider.provider().credential(withVerificationID: self.ID, verificationCode: self.scode) Auth.auth().signIn(with: credential) { (res, err) in if err != nil{ self.msg = (err?.localizedDescription)! self.alert.toggle() return } UserDefaults.standard.set(true, forKey: "status") NotificationCenter.default.post(name: NSNotification.Name("statusChange"), object: nil) } } label: { Text("Next") .padding() } } .alert(isPresented: $alert) { Alert(title: Text("Error"), message: Text(self.msg), dismissButton: .default(Text("Ok"))) } MyApp: import SwiftUI import Firebase @main struct App: App { init() { FirebaseApp.configure() } var body: some Scene { WindowGroup { ZStack{ ContentView() } } } }
Replies
1
Boosts
0
Views
1.7k
Activity
Mar ’22
How can I use custom image instead of the ImagePicker in SwiftUI?
I have simple chat app, and it is work for image picker, but I have custom image view and it fetch the images from internet, I want to use them instead of the image picker in my phone, but I did not find any solution, is there any idea about it? struct Home: View { @State var message = "" @State var imagePicker = false @State var imgData: Data = Data(count: 0) @StateObject var allMessages = Messages() var body: some View { ZStack { VStack { VStack { // Displaying Message ScrollView(.vertical, showsIndicators: true) { ScrollViewReader { reader in VStack(spacing: 20) { ForEach(allMessages.messages) { msg in ChatBubble(msg: msg) } .onChange(of: allMessages.messages) { value in if value.last!.myMsg { reader.scrollTo(value.last?.id) }}}}}}} .clipShape(RoundedRectangle(cornerRadius: 35))} VStack { HStack(spacing: 15) { HStack(spacing: 15) { TextField("Message", text: $message) Button(action: { // toggling image picker imagePicker.toggle() }) { Image(systemName: "paperclip.circle.fill") .font(.system(size: 22)) .foregroundColor(.gray)} .background(Color.black.opacity(0.06)) .clipShape(Capsule()) if message != "" { Button(action: { withAnimation(.easeIn) { allMessages.messages.append(Message(id: Date(), message: message, myMsg: true, profilePic: "p1", photo: nil)) } message = "" }) { Image(systemName: "paperplane.fill") .font(.system(size: 22)) .foregroundColor(Color("Color")) // rotating the image .rotationEffect(.init(degrees: 45)) .clipShape(Circle())}}} .padding(.bottom) .padding(.horizontal) .background(Color.white) .animation(.easeOut) } .fullScreenCover(isPresented: $imagePicker, onDismiss: { if imgData.count != 0 { allMessages.writeMessage(id: Date(), msg: "", photo: imgData, myMsg: true, profilePic: "p1") } }) { ImagePicker(imagePicker: $imagePicker, imgData: $imgData) }}}} struct ChatBubble: View { var msg: Message var body: some View { HStack(alignment: .top, spacing: 10) { if msg.myMsg { if msg.photo == nil { Text(msg.message) .padding(.all) .background(Color.black.opacity(0.06)) .clipShape(BubbleArrow(myMsg: msg.myMsg)) } else { Image(uiImage: UIImage(data: msg.photo!)!) .resizable() .frame(width: UIScreen.main.bounds.width - 150, height: 150) .clipShape(BubbleArrow(myMsg: msg.myMsg)) } Image(msg.profilePic) .resizable() .frame(width: 30, height: 30) .clipShape(Circle()) } else { Image(msg.profilePic) .resizable() .frame(width: 30, height: 30) .clipShape(Circle()) if msg.photo == nil { Text(msg.message) .foregroundColor(.white) .padding(.all) .background(Color("Color")) .clipShape(BubbleArrow(myMsg: msg.myMsg)) } else { Image(uiImage: UIImage(data: msg.photo!)!) .resizable() .frame(width: UIScreen.main.bounds.width - 150, height: 150) .clipShape(BubbleArrow(myMsg: msg.myMsg))}}} .id(msg.id)}} struct RoundedShape: Shape { func path(in rect: CGRect) -> Path { let path = UIBezierPath(roundedRect: rect, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: 35, height: 35)) return Path(path.cgPath) } } struct Message: Identifiable, Equatable { var id: Date var message: String var myMsg: Bool var profilePic: String var photo: Data? } class Messages: ObservableObject { @Published var messages: [Message] = [] init() { let strings = ["Hii", "Hello!!", "What's up?", "What Are you doing?", "Nothing, just enjoying quarantine holidays.. you??", "Same :))", "Ohhh", "What about your country?", "Very very bad..", "Ok, be safe.", "Ok", "Bye"] for i in 0..<strings.count { // simple logic for two side message View messages.append(Message(id: Date(), message: strings[i], myMsg: i % 2 == 0, profilePic: i % 2 == 0 ? "p1" : "p2")) } } func writeMessage(id: Date, msg: String, photo: Data?, myMsg: Bool, profilePic: String) { messages.append(Message(id: id, message: msg, myMsg: myMsg, profilePic: profilePic, photo: photo)) } } CustomImageView: struct CustomImageView: View { private let threeColumnGrid = [ GridItem(.flexible(minimum: 40)), GridItem(.flexible(minimum: 40)), GridItem(.flexible(minimum: 40)), ] var body: some Scene { LazyVGrid(columns: threeColumnGrid, alignment: .center) { ForEach(model.imageNames, id: \.self) { item in GeometryReader { gr in Image(item) .resizable() .scaledToFill() .frame(height: gr.size.width) } .clipped() .aspectRatio(1, contentMode: .fit) } } } }
Replies
1
Boosts
0
Views
1.1k
Activity
Mar ’22
Why apple reject webview for Swift App?
I have a simple app and it has simple properties, like user register to app, and it connect the webview, webview has payment also, but I am search on internet, and many people says like that apps will reject by apple, any idea?
Replies
1
Boosts
0
Views
2.2k
Activity
Mar ’22
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)   } }
Replies
0
Boosts
0
Views
514
Activity
Apr ’21
Why it throw error after pod install as "Error installing MaterialControls" ?
When I pod install in terminal it say "[!] Error installing MaterialControls", Cloning into '/var/folders/w_/46rzmwwn0k73x1dtmmqk4m_r0000gn/T/d20210618-4079-1b04w72'... remote: Repository not found. fatal: repository 'https://github.com/fpt-software/Material-Controls-For-iOS.git/' not found. Any idea?
Replies
0
Boosts
0
Views
568
Activity
Jun ’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])           } }
Replies
0
Boosts
0
Views
1k
Activity
Aug ’21
Why we are not enable to hide bottom nav bar in SwiftUI still?
I am have a problem in general in SwiftUI, when we click any items we are open new view, but bottom nav bar still not hide, why there is not any solution in SwiftUI still?
Replies
0
Boosts
0
Views
311
Activity
Feb ’22
How we can use grid view for buttons in SwiftUI?
I want to use many buttons like background have custom colors with grid view in swiftUI, is it possible? I know how to use grid layout for images, but I have confused to use for custom colors.
Replies
0
Boosts
0
Views
367
Activity
Feb ’22
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)
Replies
0
Boosts
0
Views
682
Activity
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")                           }) }}
Replies
0
Boosts
0
Views
413
Activity
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"), ] }
Replies
0
Boosts
0
Views
341
Activity
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()                                     }               } } }
Replies
0
Boosts
0
Views
561
Activity
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)                 }     }
Replies
0
Boosts
0
Views
576
Activity
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)       }     }
Replies
0
Boosts
0
Views
640
Activity
Mar ’22
Can pass my data in Web View form for SwiftUI?
I have a register view and when I complete my register, I want to pass register data in form from WebView, is there any way to do it?
Replies
0
Boosts
0
Views
569
Activity
Mar ’22