-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat(android): webview injectEventBindings method for external pages #13835
base: master
Are you sure you want to change the base?
Conversation
android/modules/ui/src/java/ti/modules/titanium/ui/WebViewProxy.java
Outdated
Show resolved
Hide resolved
android/modules/ui/src/java/ti/modules/titanium/ui/WebViewProxy.java
Outdated
Show resolved
Hide resolved
android/modules/ui/src/java/ti/modules/titanium/ui/widget/webview/TiUIWebView.java
Outdated
Show resolved
Hide resolved
android/modules/ui/src/java/ti/modules/titanium/ui/widget/webview/TiWebViewBinding.java
Outdated
Show resolved
Hide resolved
|
||
For iOS check the example in <Titanium.UI.WebView.addScriptMessageHandler>. | ||
<b>iOS</b>: | ||
For iOS have a look at the example in <Titanium.UI.WebView.addScriptMessageHandler> for custom handler names or if you run the manual evalJS version |
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.
Parity is important. If iOS uses addScriptMessageHandler()
, then either Android should match or we should deprecate addScriptMessageHandler()
and add injectEventBindings()
to iOS and have addScriptMessageHandler()
call it so we don't break backwards compatibility.
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.
Parity would be good. I just didn't know how to integrate the injectEventBindings()
in ObjectivC 😊 That's why I wanted to keep the evalJS example since that is working on both platforms. window.webkit.messageHandlers.yourHandlerName
is not available in the Android webview so we can't directly map that.
The default Ti way to communicate from webview -> app is still Ti.App.fireEvent
and that is cross-platform. The docs were just always wrong saying that you can't use it with external URL, you could always inject that code with evalJS (or if it is your external page: just put the file on your server and load it right away) 😄
I'll try to see if I can add the iOS part!
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.
Wow, this PR is looking good! We can dive into the iOS stuff during our meeting. Great job!
🤔 I broke it after merging master....strange. Master is still building fine, this PR is failing. Checking at the moment. edit: fixed. Code was in there twice |
in the last "to arrow function" change on parameter was missed causing it the return an error.
Adding
injectEventBindings
to the Android webview so you don't have to run a custom evalJS script yourself in the app to inject the event bindings into external pages.minified
bindings.js.min
againI still keep the example in the docs if you want to add it manually in case you'll need to make changes (but with less code!). For iOS it is not needed since you can use
window.webkit.messageHandlers.yourHandlerName.postMessage...
to communicate with the app right away. The manual evalJS code could be used for iOS too!Before
After clicking the button:
Then you can add other scripts that will fire
Ti.App.fireEvents()
to your page.