Post

Replies

Boosts

Views

Activity

Reply to TabView Reloads all Tab
Seems that even with a simple view, the component in the tab still gets reloaded @State private var currentTab = 0         var body: some View {     TabView(selection: $currentTab) {       Text("he")         .tabItem {           Label("boo", systemImage: "bird")         }         .tag(0)               LAVAView()         .tabItem {           Label(StringTool.localize("lava"), systemImage: "bird")         }         .tag(1)     } my lava view containst just a text struct LAVAView: View {     init() {     print("init lava view")   }       var body: some View {     Text("hello world")   } } Thoughts @claude31 ?
Nov ’22
Reply to TabView Reloads all Tab
This is the tab struct struct AtlasTabView: View {       @EnvironmentObject var appData: AppData   @State var reload = false       private var urlRequest: URLRequest?       init() {     setupData()   }       var body: some View {     TabView {       ValleyFaultSystemTiView()       .tabItem {         Label("tab 1", systemImage: "waveform.path.ecg")       }               WebView(request: urlRequest!)         .tabItem {           Label("tab 2", systemImage: "waveform.path.ecg.rectangle")         }               Text("temp")       .tabItem {         Label("tab 3", systemImage: "bird")       }     }   } } This is my web view struct struct WebView : UIViewRepresentable {       let request: URLRequest   let reload = false       func makeUIView(context: Context) -> WKWebView {     return WKWebView()   }       func updateUIView(_ uiView: WKWebView, context: Context) {     guard context.coordinator.needsToLoadURL else { return }     uiView.load(URLRequest(url: request.url!))   }       func makeCoordinator() -> WebView.Coordinator {     Coordinator()   }   class Coordinator {     var needsToLoadURL = true   } } And this is the 1st tab struct struct ValleyFaultSystemTiView: View, FeaturesNeeded {       @EnvironmentObject var appData: AppData   @ObservedObject private var locationManager = LocationManager()       @State private var cameraPosition: GMSCameraPosition?   @State private var coordinateBounds: GMSCoordinateBounds?   @State private var circlePopulations = [GMSCircle]()   @State private var markerShelters = [GMSMarker]()   @State private var polylinesOfFault = [GMSPolyline]()   @State private var polylines = [GMSPolyline]()   @State private var selectedMarker: GMSMarker?       var body: some View {     MapView(       circles: circlePopulations,       markers: markerShelters,       polylines: polylines,       cameraPosition: cameraPosition,       selectedMarker: selectedMarker,       coordinateBounds: coordinateBounds     )     .onAppear() {              if let path = Bundle.main.path(forResource: "test", ofType: "kml") {         do {           // process markers here         } catch {           print(error)         }       }       else {         print("file not found")       }     }   } } @Claude31 I am not sure if the right place is in onAppear since this is in a tab. But if i switch to tab 3, the print code will still be executed inside the // process markers here comment. Currrently, I am getting data from a resource file in the project (problem persists). Once i can fix avoiding having to reload each tab when switching, i will get the data from a url.
Nov ’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?
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.
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?
Oct ’22