Post

Replies

Boosts

Views

Activity

Reply to Fix For Type '()' cannot conform to 'View' Error?
@Claude31, under asyncView there is the part "cities in " which cities is passed to the content function. I wish to set this to the citiesList variable, so i will pass it as content(citiesList) import SwiftUI struct CityListView: View {       private let MAX_DISPLAY_PER_FETCH = 20   private var cityUrl: String?         @State private var citiesList: [City]?     @State private var html: String?     @State private var index = 0     @State private var showFooter = true       init(cities: [City]? = nil) {     self.citiesList = cities     setupData()   }       var body: some View {     if let citiesList {       content(citiesList)     }     else {       AsyncView(         operation: { try await getCities() },         content: { cities in           content(cities)         }       )     }   }       func content(_ cities: [City]) -> some View {     return GeometryReader { geometryProxy in       ScrollView {         LazyVStack(alignment: .leading, spacing: 0) {           if cities.count > 0 {             ForEach(cities) { city in               HStack {                 Text(city.header)                   .bold()                   .foregroundColor(.white)                   .textCase(.uppercase)                   .padding(.all, 8)                 Spacer()               }               .background(Color(UIColor(named: PrefTool.instance.getBoolean(Keyword.DARK_MODE) ? "DarkerGray" : "DarkGray")!))                             ForEach(city.businesses) { business in                 Text(business.name)                                   Divider()               }             }           }           else {             Text("Empty List")           }         }         .safeAreaInset(edge: .bottom, spacing: 0) {           if showFooter {             VStack {               Text("Footer")             }             .padding()             .frame(maxWidth: .infinity)             // The background will extend automatically to the edge             .background(Color.green)             .onBecomingVisible {               Task {                 do {                   let moreList = try await getMoreCities(index)                   showFooter = false                   if !moreList.isEmpty {                     citiesList?.append(contentsOf: moreList)                     showFooter = true                   }                 } catch {                   showFooter = false                 }               }             }           }         }       }     }   }       func getCities() async throws -> [City] {     let cachedIndex = index     html = try await Web.getRequest(url)     index = index + MAX_DISPLAY_PER_FETCH     self.citiesList = CityParser.getCities(html ?? "", cachedIndex, MAX_DISPLAY_PER_FETCH)     return self.citiesList ?? []   }       func getMoreCities(_ from: Int) async throws -> [City] {     let cachedIndex = index     index = index + MAX_DISPLAY_PER_FETCH     return CityParser.getCities(html ?? "", cachedIndex, MAX_DISPLAY_PER_FETCH)   }     }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’22
Reply to Merge An Array Item's Array Property Based On Property
@Babyj here is the code. currently, i am doing it the manual way. which for me is not ideal. what do you think? Is there a way to simplify it? the first initial fetch will not have duplicate city name. but the more list fetch for sure will have and that is the part where i wish to merge duplicate city names. import SwiftUI struct CityListView: View {       private let MAX_DISPLAY_PER_FETCH = 20   private var cityUrl: String?         @State private var citiesList: [City]?     @State private var html: String?     @State private var index = 0     @State private var showFooter = true       init(cities: [City]? = nil) {     self.citiesList = cities     setupData()   }       var body: some View {     if let citiesList {       content(citiesList)     }     else {       AsyncView(         operation: { try await getCities() },         content: { cities in           content(cities)         }       )     }   }       func content(_ cities: [City]) -> some View {     return GeometryReader { geometryProxy in       ScrollView {         LazyVStack(alignment: .leading, spacing: 0) {           if cities.count > 0 {             ForEach(cities) { city in               HStack {                 Text(city.header)                   .bold()                   .foregroundColor(.white)                   .textCase(.uppercase)                   .padding(.all, 8)                 Spacer()               }               .background(Color(UIColor(named: PrefTool.instance.getBoolean(Keyword.DARK_MODE) ? "DarkerGray" : "DarkGray")!))                             ForEach(city.businesses) { business in                 Text(business.name)                                   Divider()               }             }           }           else {             Text("Empty List")           }         }         .safeAreaInset(edge: .bottom, spacing: 0) {           if showFooter {             VStack {               Text("Footer")             }             .padding()             .frame(maxWidth: .infinity)             // The background will extend automatically to the edge             .background(Color.green)             .onBecomingVisible {               Task {                 do {                   let moreList = try await getMoreCities(index)                   if moreList.isEmpty { showFooter = false                     citiesList?.append(contentsOf: moreList)                   } else { for more in moreList {                       let index = citiesList?.firstIndex { $0.name == more.name } ?? -1                       if index >= 0 {                         citiesList?[index].businesses.append(contentsOf: more.businesses)                       }                       else {                         cities?.append(more)                       }                     } }                 } catch {                 }               }             }           }         }       }     }   }       func getCities() async throws -> [City] {     let cachedIndex = index     html = try await Web.getRequest(url)     index = index + MAX_DISPLAY_PER_FETCH     self.citiesList = CityParser.getCities(html ?? "", cachedIndex, MAX_DISPLAY_PER_FETCH)     return self.citiesList ?? []   }       func getMoreCities(_ from: Int) async throws -> [City] {     let cachedIndex = index     index = index + MAX_DISPLAY_PER_FETCH     return CityParser.getCities(html ?? "", cachedIndex, MAX_DISPLAY_PER_FETCH)   }     }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’22
Reply to How to Resize Placeholder in Kingfisher where loading icon is in the middle
Hi @claude31 hmm now that you mention it. Could be possible this might be KF's doing. I cleaned the image for better understanding The yellow border is the area where the placeholder is. But when the image is loaded, it is not equal. There are still extra spaces at the bottom. I tried both .fit and .fill but the result is the same. Could it be the yellow area is correct. that the height is adjusted based on the aspect ratio of the width? And that KF is the culprit displaying the downloaded image not fitting it to the area the placeholder was occupying?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’22
Reply to Why Is Bottom Sheet Full Screen? What is the workaround for Dynamic Height?
Hi. Ill paste my code below. The original post was more like a discussion question that is why I did not post any code. Currently I set it to a fixed height @State private var showFilter = false var body: some View { VStack { Button { showFilter.toggle() } label : { Text("show me") } } .sheet(isPresented: $showFilter) {       VStack {         Text("Filter options")           .padding([.bottom], 20)           .presentationDetents([.height(500)])                   ForEach(["All", "2.5+", "3.0+", "4.0+", "5.0+", "6.0+", "7.0+", "8.0+", "9.0+"], id: \.self) { filter in           Button { showFilter.toggle()           } label: {             Text(filter)           }           .padding([.top, .bottom], 8)         }       }     } } The list may be long but I could decide to just remove 5,6,7,8,9 or vice versa that I wish to have the sheet height set based on the contents. I will also check your suggestion.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’22
Reply to Anybody Use SwiftClipper Here? Can't Instantiate A Class Without Init.
@Claude31 @endecotp My goal is to create a convex hull to show the path of a typhoon. I did this in Android using gpcj https://github.com/ChristianLutz/gpcj and GrahamScan classes in Java. I think the GrahamScan source in Swift that I am using is ok, found here (pasting the link. too many source code classes if i paste them all here) https://github.com/raywenderlich/swift-algorithm-club/tree/master/Convex%20Hull I think the issue is somewhere in the SwiftClipper library since I get that error if the points result in an open path clipping and I cannot instantiate a PolyTree. So currently only the first convex hull is drawn but the rest result in that error message. The PolyTree class is in this link https://github.com/lhuanyu/SwiftClipper/blob/master/Sources/SwiftClipper/PolyNode.swift And as for using it .... here is the function func getHullPoints(_ points: [[CGPoint]]) -> [CGPoint] {     var hullPoints: [CGPoint] = []     if !points.isEmpty && points.count > 1 {       hullPoints = points[0]       var paths = Paths()       let clipper = Clipper()       for o in (1..<points.count) {         do {           paths.removeAll()           clipper.clear()           clipper.addPath(hullPoints, .subject, false)           clipper.addPath(points[o], .subject, false)           try clipper.execute(clipType: .difference, solution: &paths)           hullPoints = paths.first ?? []         } catch {           print(error)         }       }     }     return hullPoints   } Yep, sorry for the 1 letter variable. i just copied that from somewhere The error is triggered in try clipper.execute() with that error message about open path clipping and PolyTree is needed. So the issue is i cannot instantiate it since there is no public init. Is the only way for this to copy the source code to my project and place an init so i can instantiate it?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’22
Reply to Anybody Use SwiftClipper Here? Can't Instantiate A Class Without Init.
This is the graham scan in java that i used. i didnt know there is a thing called concave hull. i thought theyre convex only. frankly the easiest would have been to convert the libs i use to swift but still new to ios, i do not think i would be able to convert them easily so i opted to try and look for possible alternative libs. triple w dot ime.usp.br/~pf/sedgewick-wayne/algs4 then add GrahamScan dot java at the end of the url.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’22
Reply to Why overlay is not on top
I used your suggestion. I think this is more of an internal thing. I tried it with another kind of text the one case per people still has the same result. Cannot figure out why the per shouldnt be in the first line. but the red background clearly shows the text width extends to the end so the Per should be there. But since it's not, this is more of an internal logic inside how Text wraps the string I guess?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’22