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.