hey chris i need a help in swiftui
So this is the actual code so i need help in WebView
So WebView works perfect but i want to change url by clicking button in navigation button can be this possible
import SwiftUI
import WebKit
import UIKit
struct ContentView: View {
@State var showMenu = false
@State private var selection: Int? = nil
@State var refresh: Bool = false
var api = “https://google.com/”
let endpoint = “”
var body: some View {
NavigationView {
VStack {
WebView(request: URLRequest(url: URL(string : api + endpoint)!))
}.navigationBarTitle(Text(""), displayMode: .inline)
.navigationBarItems(leading: HStack{ Button(action:{
}){
Image(“test2”)
.foregroundColor(Color.black)
.padding(.top, 5.0)
.animation(.linear)
}},
trailing: HStack{ Button(action:{}){
Image(“test2”)
.foregroundColor(Color.black)
};
Button(action:{}){
Image(“test2”)
.foregroundColor(Color.black)
};
Button(action:{}){
Image(“test2”)
.foregroundColor(Color.black)
}
}
) }
};func onAppear(){
UINavigationBar.appearance().barTintColor = UIColor(red: 0, green: 100/255, blue: 205/255, alpha: 1)
UINavigationBar.appearance().tintColor = UIColor.white
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
}
}
struct WebView : UIViewRepresentable {
// static is only for demo, this can be some external model
static var cache = URL: WKWebView
let request: URLRequest
func makeUIView(context: Context) -> WKWebView {
guard let url = request.url else { fatalError() }
if let webView = WebView.cache[url] {
return webView
}
let webView = WKWebView()
WebView.cache[url] = webView
return webView
}
func updateUIView(_ uiView: WKWebView, context: Context) {
if uiView.url == nil {
uiView.load(request)
}
}
}
so this is code