New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TIMOB-25862] Parity: Support async Ti.UI.Webview.evalJS call on Android & iOS #9889
Conversation
@garymathews @hansemannn @jquick-axway |
TAG, | ||
"Synchronous evalJS is not available when running on the main thread. Please supply an additional callback function argument to be invoked with the result as it's only parameter, to be called when the result is available."); | ||
// FIXME This just times out on main thread! I don't know how else to get this to work... | ||
// EvalJSSyncRunnable future = new EvalJSSyncRunnable(view, code); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code hung just as if I didn't spin off a thread, probably because I have to block below on the get call and the Javascript APIs have to use the UI thread to complete. In other words, I don't think we can run a sync version on main/ui thread.
} | ||
|
||
// FIXME: Android is dumb and assumes no trailing semicolon! | ||
webview.evalJS('Ti.API.info("Hello, World!");"WebView.evalJS.TEST"', function (result) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Android implementation of evalJS leaves much to be desired. For one thing, it takes your input and appends:
+"";
So if you have a trailing semicolon (as you should!) it doesn't behave properly. Also, I think it may be double-escaping strings here? I'd expect the result to be 'WebView.evalJS.TEST'
not '"WebView.evalJS.TEST"'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welcome to Android. This is par for the course. Nothing is ever easy.
// When on Android 19+ we can use the builtin evalAsync method! | ||
if (Build.VERSION.SDK_INT >= 19) { | ||
final KrollFunction theCallback = callback; | ||
view.getWebView().evaluateJavascript(code, new ValueCallback<String>() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Google documents that evaluateJavascript()
must be called on the main UI thread here...
https://developer.android.com/reference/android/webkit/WebView.html#evaluateJavascript
I looked at Google's source code on github. It'll throw an exception if invoked on any other thread.
https://github.com/aosp-mirror/platform_frameworks_base/blob/master/core/java/android/webkit/WebView.java#L1053
…dd warning log for calling sync version when run-on-main-thread is true.
…or running built app (tidev#10318)
…k the request into a static map keyed by a globally incrementing int and then post/handleMessage to pull it out and run it in the UI
Generated by 🚫 dangerJS |
…oid & iOS (tidev#9889) * Add an async variant of Ti.UI.WebView.evalJS * Update docs to include async callback info to Ti.IOStream read/write * Handle evalJS in async fashion when not invoked from UI * Add Josh's thread/runnable for wrapping sync read/writes on main thread * Add async Ti.IOStream #read()/#write() to iOS
…oid & iOS (tidev#9889) * Add an async variant of Ti.UI.WebView.evalJS * Update docs to include async callback info to Ti.IOStream read/write * Handle evalJS in async fashion when not invoked from UI * Add Josh's thread/runnable for wrapping sync read/writes on main thread * Add async Ti.IOStream #read()/#write() to iOS
…oid & iOS (tidev#9889) * Add an async variant of Ti.UI.WebView.evalJS * Update docs to include async callback info to Ti.IOStream read/write * Handle evalJS in async fashion when not invoked from UI * Add Josh's thread/runnable for wrapping sync read/writes on main thread * Add async Ti.IOStream #read()/#write() to iOS
…oid & iOS (tidev#9889) * Add an async variant of Ti.UI.WebView.evalJS * Update docs to include async callback info to Ti.IOStream read/write * Handle evalJS in async fashion when not invoked from UI * Add Josh's thread/runnable for wrapping sync read/writes on main thread * Add async Ti.IOStream #read()/#write() to iOS
…oid & iOS (tidev#9889) * Add an async variant of Ti.UI.WebView.evalJS * Update docs to include async callback info to Ti.IOStream read/write * Handle evalJS in async fashion when not invoked from UI * Add Josh's thread/runnable for wrapping sync read/writes on main thread * Add async Ti.IOStream #read()/#write() to iOS
…oid & iOS (#9889) (#10347) * Add an async variant of Ti.UI.WebView.evalJS * Update docs to include async callback info to Ti.IOStream read/write * Handle evalJS in async fashion when not invoked from UI * Add Josh's thread/runnable for wrapping sync read/writes on main thread * Add async Ti.IOStream #read()/#write() to iOS
JIRA: https://jira.appcelerator.org/browse/TIMOB-25862
Description:
This is on both iOS and Android.