hnabbasi hnabbasi - 1 month ago 10x
iOS Question

Prism Xamarin Forms CustomRenderer causing navigation issue in iOS

I am using a custom Label in my Xaml that has a custom renderer. This seems to work fine in Android, but not in iOS.

Repro: Run the app in iOS. Tap Home to go to Home page. Tap Login. A modal Login page will show up with a switch. Toggle (or not) switch and tap Done. Back in Home page, it checks for results in INavigationAware.OnNavigatedTo() and displays a dialog box. In iOS, however, it is not getting called when I use XfLabel that has custom renderer. Not using a custom renderer will result in correct behavior.

Is XF's ExportRenderer mechanism messing with Prism's DI somehow on iOS?

Prism.Forms (6.2)

XF (2.3)

Sample code:


For anyone having this issue. It was an oversight in my custom renderer, as pointed out by Brian Lagunas as well. Instead of updating the native control in OnElementChanged(), I was updating the XF Element.

Should update the native control, like this

Control.TextColor = UIColor.Purple; // iOS


Control.SetTextColor(Android.Graphics.Color.Purple); // Android

Instead of

Element.TextColor = Color.Purple;

Moral of this story: Haste makes Waste ;)