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 ?
Post
Replies
Boosts
Views
Activity
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.
Weird that the solution was to onclude 2 permission. it never worked when i first added it.
later on i tried to do it again and all of a sudden it worked.
can you please share your code? i am also looking for this.
added note is i already tried erasing content or simulator, the permission category in the info plist are there (its a swiftui project)
sadly no location swrvices in simulators even until ios16 so i couldnt even try to manually change it.
this is irritating. I cant post a json sample even though i already trimmed it
Ill answer my own question. I think the url needs to be populated instead of the %f.
I am actully confused why there is no collapse button to show/hide the sidebar in NavigationSplitView. Tutorials show it but when i copy the code and run it, there is no collapse button. Only the navigation links are shown full width and height. the detail view is nowhere to be seen.
Hmm seems this was my mistake
outputting geoJson as
print(String(data: geoJson!, encoding: .utf8)!)
results in
{"features":[],"type":"FeatureCollection"}
Removed the first question instead since this is solved.
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?
Changed to focus on only On Case Per People text sample.
I wanted to make it work with LazyHGrid or LazyVGrid but I decided to go with the simplest one available. Just VStack and put a Spacer() in between.
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.
@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?
it is supposed to be in the .execute method. :polytree parameter and instead of instantiating paths = Paths() it should be paths= PolyTree() but gives a compile time error because there is no init in the class.