Reputation: 349
I have created a HybridWebView according to https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/custom-renderer/hybridwebview/ and created a native ios WKWebView. Now I want to add custom controls to go Back/Forward/Home in Forms but I am not sure what is the recommended way to make a call from my Xamarin forms view into my native view to for example trigger the GoBack() of the ios WKWebView browser?
Should I try to call into my native implementation or should the native view listen to events from the forms view?
Upvotes: 2
Views: 574
Reputation: 426
You would need to use the Xamarin MessagingCenter functionalities. It follows the publish-subscribe pattern. What you can do is publish a message in your Xamarin PCL and from your native projects you will have to subscribe to these published messages that comes from a Xamarin PCL trigger/event.
Sample code:
In your PCL you will have something like this:
MessagingCenter.Subscribe<MainPage> (this, "Hi", (sender) => {
// do something whenever the "Hi" message is sent
});
And in your native project something like this:
MessagingCenter.Send<MainPage> (this, "Hi");
Upvotes: 2