I have a custom renderer for a DatePicker. However the OnElementPropertyChanged
event is being fired during Dispose of the view on iOS (doesn't seem to happen on the Android build), causing a segfault (null pointer dereference).
public class OptionalDatePickerRenderer : DatePickerRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<DatePicker> e)
{
base.OnElementChanged(e);
this.Control.Placeholder = "Date of Birth";
SetText();
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == "Date" || e.PropertyName == DatePicker.FormatProperty.PropertyName)
{
SetText();
}
}
void SetText()
{
// date currently set on the optional date picker (date known to model)
var date = Element.Date;
if (date == Element.MinimumDate)
Control.Text = "";
}
}
What should I be doing differently?