I am trying to transfer data from a native iOS application to a React (non-responsive) web application running in UIWebView.
I get a string from a native viewcontroller and must "insert" it into the value of the <input> element inside the React component class. I gave the element a id like this:
render() { <div> ... <input id="iccid" type="text" name="iccid" pattern="\d*" onChange={this.iccidChanged.bind(this)} autoFocus /> ... </div> }
Then, using JavaScriptCore from iOS (Swift code), I run:
self.context = self.webView.valueForKeyPath("documentView.webView.mainFrame.javaScriptContext") as? JSContext self.context!.evaluateScript("document.getElementById('iccid').value='\(barcodeValue)';")
This seems to work, and I can see the value updated in the DOM inside the webview, the problem is that my React onChange function (which checks the value and state of the component component) does not work, because React does not interpret this as a change (possibly because behind the DOM and virtual DOM processing).
What is the proper way / best practice to update an element's value from iOS and make the React component behave the way the user typed it?
javascript ios reactjs swift uiwebview
mindbomb
source share