[forms-devel] Fwd: Fixing SetNativeControl logic when replacing native controls
tonipetrina at hotmail.com
Sat Jul 9 16:13:12 UTC 2016
In the middle of writing the proposal and testing out the code that will fix the issue below I stumbled upon the following code in Xamarin.Forms.Platform.Android.AppCompat namespace:
public abstract class ViewRenderer<TView, TControl> : Android.ViewRenderer<TView, TControl> where TView : View where TControl : global::Android.Views.View
protected abstract TControl CreateNativeControl();
This is exactly what I am proposing, but pulled up to the Android.ViewRenderer class.
Should I continue writing my proposal and can I send pull request into the evolution repository or do we have to discuss it here first?
Begin forwarded message:
From: Toni Petrina <tonipetrina at hotmail.com>
Subject: [forms-devel] Fixing SetNativeControl logic when replacing native controls
Date: 2 July 2016 at 18:22:42 GMT+2
To: <forms-devel at lists.xamarin.com>
It is hard to replace a native control inside a renderer with your own. You cannot even replace ListView in Android because there are nasty NullRefs happening if you do so! Consider the following code:
var ctx = Context;
nativeListView = new AListView(ctx);
_refresh = new SwipeRefreshLayout(ctx);
If I want to use my subclass instead of Android.Widget.ListView, I have to reimplement entire ListViewRenderer which is impossible due to all internal classes. It would be much better if there is a method called GetNativeControll so that the above code looks more like:
protected override AListView GetNativeControl() => new AListView(Context);
var ctx = Context;
nativeListView = GetNativeControl();
This way I can override the default control to be used with my own subclass.
P.S. Not having markdown in email is frustrating!
forms-devel mailing list
forms-devel at lists.xamarin.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the forms-devel