Skip to content
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

Expose starting and finished load events in WebView #303

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Expose starting and finished load events in WebView #303

wants to merge 2 commits into from

Conversation

pietrodicaprio
Copy link

@pietrodicaprio pietrodicaprio commented Jan 19, 2021

Exposing OnNavigationStarting and OnNavigationFinished in razor in order to execute actions on top of the base events.

Disclaimer:
the method I used is probably not the best one. Is the first time I code on such kind of project and I'm not sure about how all the stuff is working in behind scenes.

This PR is not intended to be a final approach but mostly a rise of hand about a need I have on this framework.
Is then the method is acceptable, well, I'm happier :)

P.S.
I didn't create a branch on the latest commit because I can't update my Android project dependencies for it :(

@dnfadmin
Copy link

dnfadmin commented Jan 19, 2021

CLA assistant check
All CLA requirements met.

@pietrodicaprio pietrodicaprio changed the title Expose starting and finished load events Expose starting and finished load events in WebView Jan 19, 2021
@Eilon
Copy link
Member

Eilon commented Jan 20, 2021

Hi @pietrodicaprio thank you for the PR! I think that adding support for these events would be great!

There's a pattern for mapping from Blazor events to Mobile Blazor Bindings / Xamarin.Forms events for registration and also making sure they can get un-registered.

You can see an example of this with the Button's Clicked event:

I think that to fully support the events we should try to follow this pattern.

Would you be able to update the PR with this pattern?

@pietrodicaprio
Copy link
Author

Hi @Eilon , I saw it but did not completely understood how it is working. I'll give it a try today and eventually push here.
Thank you for the hint!

@pietrodicaprio
Copy link
Author

pietrodicaprio commented Jan 21, 2021

I'm trying to follow the pattern but I'm having a strange issue:
while the framework project builds without issue, I'm not able to bind the event as I'm supposed to.

If I want to bind the existing OnWebMessageReceived I have these options:
image
and I can simply bind a void with a string as argument.

Buf if I want to bind the new OnNavigationFinished I have these options:
image
and when I bind a new method that has an object and an Uri as argument I have the error:
CS1503 Argument 2: cannot convert from 'method group' to 'EventCallback'

I pushed the new code in this PR in order to have, if possible, a review from you

@pietrodicaprio
Copy link
Author

Interesting thing: after closing, reopening, closing, leaving the project away for a couple of hours, opening again, binding a function that has only Uri as parameter (instead of object, Uri) and trying to compile ignoring the error highlighted by Intellisense: it just works 😅

Now the question is: why my VS / Intellisense can't get the updated metadata in order to provide the proper suggestion?
Did I made anything wrong in the code?

@Eilon
Copy link
Member

Eilon commented Jan 21, 2021

It looks like you're using a VS extension for Intellisense or another IDE? Is that ReSharper or something else? You could try disabling that and see what the built-in Intellisense shows up. Maybe that's the issue?

@Eilon
Copy link
Member

Eilon commented Jan 21, 2021

BTW sometimes closing & re-opening is the only fix anyway because of how things get cached. Or even doing git clean -xdf to delete all temporary/generated files in the build.

@pietrodicaprio
Copy link
Author

pietrodicaprio commented Jan 21, 2021

I confirm that I have ReSharper. Solved by deleting the .vs folders and executing the git command you provided, thank you for the suggestion!

I confirm that the code works and Intellisense is updated. 🎉

There is only one thing I don't understand: why Xamarin.Forms.WebView calls 2 times the SendNavigated method (that causes a "double call" to the OnNavigationFinished event) at every single page change? Is there a reason behind?
I evaluated to put some check in place, in this project, to avoid double calls but then is risky for page refresh, redirects etc.

Said that, if the code matches your expectation I have nothing to add right now.
Let me know!

Base automatically changed from master to main March 16, 2021 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants