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-25277] Android: Implement onLink callback for Ti.UI.WebView #9459
Conversation
@hansemannn Maybe we could add this to iOS for parity? |
We should call it "link", so without the EDIT: Sorry, didn't see it's a property. But even that, we should move all event-related properties to real events, otherwise it confuses the developer and makes it more difficult to use in Alloy (via manual controller reference). EDIT 2: I saw your comment on the JIRA - that's exactly what I would do. And it's cross-platform already. The wildcard |
I can't make it an event since it requires an immediate return value (similar to |
But using the existing API's, they should do that already if I got that correct? iOS uses a delegate-method that returns something as well, so checking for the blacklisted URL's changes the return-value. Exposing this as a property would not be possible on iOS and also wouldn't make sense since the above reasons. |
It sounds like the ultimate goal here is to provide an opportunity to cancel URL navigation and do something native instead. I'd like to share my experience regarding this. How this is implemented now, the On iOS, our Titanium On Android, the equivalent to iOS' So... I'm wondering if the real solution here is to tweak our "beforeload" event to provide this functionality. On Android, "beforeload" technically happens when the next URL has already started and not before it loads like how it is on iOS. But that said, I think it was made this way on purpose on Android to work-around JavaScript URL navigation detection mentioned above. However, we can still tweak our Android code to trigger a "beforeload" via the Java Anyways, that's my 2 cents. |
The issue with I think in this scenario @hansemannn The workaround posted on JIRA, although works, isn't intended for this behavior. It's also not cross-platform as the |
You know what, I think I got my Android methods mixed up. I meant WebViewClient.shouldOverrideUrlLoading(), not |
Ahh, I do. But I intercept those before they reach |
72ddf8a
to
1496f67
Compare
Tests:
Generated by 🚫 dangerJS |
@garymathews I've updated the docs to fix the validation error. Let me know if something else should be revisited. |
@garymathews , @jquick-axway , Can anyone of you please fix the lint errors. Thanks !! |
apidoc/Titanium/UI/WebView.yml
Outdated
@@ -551,7 +551,7 @@ properties: | |||
type: Callback<Boolean> | |||
platforms: [android] | |||
since: "7.2.0" |
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.
Needs to be changed to 7.3.0
FR Passed.
Studio Ver: 5.1.0.201804230827 |
Waiting for CR to pass. |
@garymathews, @lokeshchdhry, I'm worried that this might crash if "tiapp.xml" property "run-on-main-thread" is set to Edit: |
@garymathews , @jquick-axway , Are we making any changes to this PR ? |
Bumping to 7.4.0 to be merged with an equivalent iOS implementation per https://jira.appcelerator.org/browse/TIMOB-26063 cc @hansemannn Also to be merged in same released as Windows PR: appcelerator/titanium_mobile_windows#1211 |
I would still disagree with the interface design here. We have something very similar with the "blacklisturl" event already, which is cross-platform and works today already. Can't we just get the URL from there, cancel the HTTP request and live a happy life? |
@jquick-axway Could you write a test case that reproduces the threading issue with the |
Okay. I've verified that the For everyone's info, the @hansemannn, do we have something similar on iOS? |
} | ||
} | ||
} | ||
|
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.
There's one issue here. The onPageStarted()
method gets called after the HTTP request was sent. If you set up the URL to use a customer URL scheme that was intended to be overridden by onlink
, then the WebView will display an "unknown url scheme" error page.
I'm able to reproduce this issue with the following:
var window = Ti.UI.createWindow();
var webView = Ti.UI.createWebView({
html: '<!DOCTYPE html><html><body><a href="myapp:HelloWorld">Tap this link</a></body></html>',
onlink: function(e) {
Ti.API.info("@@@ onlink() invoked. url: " + e.url);
var endTime = new Date();
endTime.setTime(endTime.getTime() + 1000);
while (endTime >= new Date()) {}
return (e.url !== "myapp:HelloWorld");
},
});
window.add(webView);
window.open();
The above issue can be solved by using the WebViewClient.shouldOverrideUrlLoading() method instead. But the downside to using this method (based on what I remember) is that it only gets called when tapping/clicking on links. It does not get called for URLs invoked in JavaScript within the webpage (and I know iOS' UIWebView does not have this limitation). But this might be okay since we've named the property onlink
.
@jquick-axway @garymathews Is this PR ready to merge? iOS was just merged. |
@hansemannn, there is 1 issue left which I've posted above. |
6bdc7ba
to
f4c962e
Compare
Updated PR |
a7aa162
to
7631683
Compare
Generated by 🚫 dangerJS |
FR Passed. Studio Ver: 5.1.2.201810080801 |
onlink
callback property forTitanium.UI.WebView
true
orfalse
as a condition for loading the linkTEST CASE
JIRA Ticket