locked
Custom android webview renderer - how to? RRS feed

  • Question

  • User45913 posted

    So I've been tweaking our custom android webview renderer without much luck. Instead of posting all code here, I maybe better like to wipe clean and restart. But if I do that, what are other people using to get this working correctly?

    First background on how the page is structured, we have a simple contentpage with a grid. Top is a webview loading local html content as string and underneath there is an entry and a button. Pressing the button will add text to the local html and through property binding we update that html to force a new load of the webview.

    So what do I need: * Extended webview control with field to hold the html string content so that we can use that in the custom renderer to load it * We need to be able to update the webview when the html string content changes * There has to be a way to do a scroll to bottom once the html content has been loaded * Invoke javascript that is injected in the html string content

    So far my version still has problems with reloads ( often data is not appearing ) or with the scroll to botton ( often not scrolling because triggered to soon before page has been rendered )

    Monday, October 9, 2017 12:43 PM

Answers

  • User240901 posted

    Seen you around the slack channel quite a bit. Feel free to have a look at my plugin if you want. I had the same issues a while ago when starting a project; so feel free to steal the code or use it as a basis.

    https://github.com/SKLn-Rad/Xam.Plugin.Webview

    Going through your list of things you need:

    1) You would probably need to evaluate some Javascript to get this. I normally call document.documentElement.innerHTML after the content has loaded. UWP has OnContentLoaded api's whereas Android you can just use OnNavigationComplete

    2) BindableProperties? then use OnPropertyChanged in the renderer to relaunch the page. Or do you mean just update parts of the DOM?

    3) Probably will also require Javascript injection...

    4) Android you can use JavascriptBridges, iOS you can use ScriptMessageHandlers, UWP you can use InvokeScript

    Hope this helps!

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, October 9, 2017 3:46 PM

All replies

  • User240901 posted

    Seen you around the slack channel quite a bit. Feel free to have a look at my plugin if you want. I had the same issues a while ago when starting a project; so feel free to steal the code or use it as a basis.

    https://github.com/SKLn-Rad/Xam.Plugin.Webview

    Going through your list of things you need:

    1) You would probably need to evaluate some Javascript to get this. I normally call document.documentElement.innerHTML after the content has loaded. UWP has OnContentLoaded api's whereas Android you can just use OnNavigationComplete

    2) BindableProperties? then use OnPropertyChanged in the renderer to relaunch the page. Or do you mean just update parts of the DOM?

    3) Probably will also require Javascript injection...

    4) Android you can use JavascriptBridges, iOS you can use ScriptMessageHandlers, UWP you can use InvokeScript

    Hope this helps!

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, October 9, 2017 3:46 PM
  • User45913 posted

    Hey @RyanDixon thx for the link! I'll create a sample app on GitHub and add your code to see how far I can get this working... I'll report back on the effort.

    Monday, October 9, 2017 6:37 PM