[forms-devel] Fwd: Fixing SetNativeControl logic when replacing native controls
Toni Petrina
tonipetrina at hotmail.com
Sat Jul 9 16:13:12 UTC 2016
Hi everyone,
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?
Cheers
Toni Petrina
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>
Hi,
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);
_refresh.SetOnRefreshListener(this);
_refresh.AddView(nativeListView, LayoutParams.MatchParent);
SetNativeControl(nativeListView, _refresh);
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.
Cheers
Toni Petrina
P.S. Not having markdown in email is frustrating!
_______________________________________________
forms-devel mailing list
forms-devel at lists.xamarin.com
http://lists.ximian.com/mailman/listinfo/forms-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/forms-devel/attachments/20160709/3806d535/attachment.html>
More information about the forms-devel
mailing list