My code sets the navigation bar title it gets from web page, but everytime this causes the whole WKWebView to reload... The page is quite heavy so consumes a lot of time. Same behaviour when using button to set title.
struct TransitScreen: View, HandlerDelegate {
var urlRequest: URLRequest
@State var pageTitle = "Title 1"
var body: some View {
VStack {
KSWebView(urlRequest: urlRequest, delegate: self) // WKWebView using UIViewRepresentable
NavigationLink("Go", destination: Text("Some Data"))
Button(action: {
pageTitle = "replaced \(Date().toSeconds())"
}){
Text("Change title")
}
}.navigationBarTitle(Text(pageTitle))
.edgesIgnoringSafeArea(.top)
}
func process(data: String){
pageTitle = data
}
}
Is there anyway to stop this from happening? or another method to update navigationBarTitle?