I'm implementing a sheet between a web view and a view. The values ββin the sheet are always changing. The value of the sheet called by the view must be shared by the web view (or reverse). There is no problem when mounting the web view directly inside the view. The problem arises when mediating with 'let' expressions.
struct ItlnrView: View {
@State var activeSheet: **Bool** = false
.....
let webView = myWebView(web: nil, actSheet: **$activeSheet**, req: URLRequest(url: URL(string: "https://google.com")!)). <--- problem
var body: some View {
VStack {
webView
// myWebView(web: nil, actSheet: $activeSheet, req: URLRequest(url: URL(string: "https://google.com")!)) <--- no problem
}
.sheet(isPresented: $activeSheet) {
// code
}
}
}
struct myWebView: UIViewRepresentable {
let request: URLRequest
var webview: WKWebView?
@Binding var activeSheet: Bool
init(web: WKWebView?, actSheet: **Binding<Bool>**, req: URLRequest) {
self.webview = WKWebView()
self._activeSheet = actSheet
self.request = req
}
....
....
}
If I don't use let webView
and run myWebView(web:,actSheet:,req:)
in V/HStack directly, the sheet value is compatible/shared properly. But I must use/call by let webView
because I have to use the 'go back' and 'reload' functions of web view. So whenever I use let webView
, @State and @Binding then are incompatible.
In other words, $activeSheet
requires as a Binding value in let webView
, but @State value is appropriate when coding myWebView(web:,actSheet:,req:)
in Stack directly. I hope you to be understand my lacked question.