Howdy I want to change the worth of the binding variable ‘click on’ as soon as the onReady block within the html is executed. I can talk from swift to html by utilizing consider java script. However how do I talk from the onReady within the html to swift to alter the bools val? I attempted making a coordinator class however
struct SmartReelView: UIViewRepresentable {
let hyperlink: String
@Binding var isPlaying: Bool
@Binding var click on: Bool //variable to be adjustments
func makeUIView(context: Context) -> WKWebView {
let webConfiguration = WKWebViewConfiguration()
webConfiguration.allowsInlineMediaPlayback = true
let webView = WKWebView(body: .zero, configuration: webConfiguration)
loadInitialContent(in: webView)
return webView
}
func updateUIView(_ uiView: WKWebView, context: Context) {
let jsString = "isPlaying = ((isPlaying) ? "true" : "false"); watchPlayingState();"
uiView.evaluateJavaScript(jsString, completionHandler: nil)
}
personal func loadInitialContent(in webView: WKWebView) {
let embedHTML = """
<model>
physique {
margin: 0;
background-color: black;
}
.iframe-container iframe {
high: 0;
left: 0;
width: 100%;
peak: 100%;
}
</model>
<div class="iframe-container">
<div id="participant"></div>
</div>
<script>
var tag = doc.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = doc.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var participant;
var isPlaying = true;
perform onYouTubeIframeAPIReady() {
participant = new YT.Participant('participant', {
width: '100%',
videoId: '(hyperlink)',
playerVars: { 'playsinline': 1, 'controls': 0},
occasions: {
'onReady': perform(occasion) {
//change right here
},
'onStateChange': perform(occasion) {
if (occasion.knowledge === YT.PlayerState.ENDED) {
participant.seekTo(0);
participant.playVideo();
}
}
}
});
}
perform watchPlayingState() {
if (isPlaying) {
participant.playVideo();
} else {
participant.pauseVideo();
}
}
</script>
"""
webView.scrollView.isScrollEnabled = false
webView.loadHTMLString(embedHTML, baseURL: nil)
}
}