Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WKWebView wait for DOM rendering before triggering native code

I have a hybrid iOS app which contains a WKWebView, and I have a JavaScript function callNative can call Objective C native code in the main thread.

In my JavaScript, I have the following structure

modifyDOM(); // e.g. .show(), and .hide() stuff
callNative('animateWKWebViewFrame');

For some reason, animateWKWebViewFrame (native code) is called before modifyDOM completes and is fully rendered. (This causes a visual glitch.)

How can I force full rendering of DOM modifications before calling native code?

like image 592
Randomblue Avatar asked May 01 '15 10:05

Randomblue


1 Answers

I am assuming that you are using jQuery because of your comment saying modifyDOM calls show() and hide(). If that is the case, then you should rely on the complete parameter to provide a function that will, in turn, make the call to your native code.

The relevant documentation is here :
http://api.jquery.com/hide/#hide-duration-complete
http://api.jquery.com/show/#show-duration-complete

And finally, here is some sample code :

function modifyDOM()
{
  someElement.show(400, function() {callNative('animateWKWebViewFrame');});
}
like image 50
Dalzhim Avatar answered Oct 07 '22 18:10

Dalzhim