[Android] move runtime registration of renderers to its own method (#5946)

* move renderer registration to its own method

* - move to static
This commit is contained in:
Shane Neuville 2019-04-18 09:25:58 -06:00 коммит произвёл Rui Marinho
Родитель dbf4037a31
Коммит 6c0a9405a2
1 изменённых файлов: 40 добавлений и 29 удалений

Просмотреть файл

@ -82,6 +82,39 @@ namespace Xamarin.Forms.Platform.Android
} }
} }
static void RegisterHandler(Type target, Type handler, Type filter)
{
Type current = Registrar.Registered.GetHandlerType(target);
if (current != filter)
return;
Registrar.Registered.Register(target, handler);
}
// This is currently being used by the previewer please do not change or remove this
static void RegisterHandlers()
{
RegisterHandler(typeof(NavigationPage), typeof(NavigationPageRenderer), typeof(NavigationRenderer));
RegisterHandler(typeof(TabbedPage), typeof(TabbedPageRenderer), typeof(TabbedRenderer));
RegisterHandler(typeof(MasterDetailPage), typeof(MasterDetailPageRenderer), typeof(MasterDetailRenderer));
RegisterHandler(typeof(Switch), typeof(AppCompat.SwitchRenderer), typeof(SwitchRenderer));
RegisterHandler(typeof(Picker), typeof(AppCompat.PickerRenderer), typeof(PickerRenderer));
RegisterHandler(typeof(CarouselPage), typeof(AppCompat.CarouselPageRenderer), typeof(CarouselPageRenderer));
if (Forms.Flags.Contains(Flags.FastRenderersExperimental))
{
RegisterHandler(typeof(Button), typeof(FastRenderers.ButtonRenderer), typeof(ButtonRenderer));
RegisterHandler(typeof(Label), typeof(FastRenderers.LabelRenderer), typeof(LabelRenderer));
RegisterHandler(typeof(Image), typeof(FastRenderers.ImageRenderer), typeof(ImageRenderer));
RegisterHandler(typeof(Frame), typeof(FastRenderers.FrameRenderer), typeof(FrameRenderer));
}
else
{
RegisterHandler(typeof(Button), typeof(AppCompat.ButtonRenderer), typeof(ButtonRenderer));
RegisterHandler(typeof(Frame), typeof(AppCompat.FrameRenderer), typeof(FrameRenderer));
}
}
protected void LoadApplication(Application application) protected void LoadApplication(Application application)
{ {
if (!_activityCreated) if (!_activityCreated)
@ -91,26 +124,7 @@ namespace Xamarin.Forms.Platform.Android
if (!_renderersAdded) if (!_renderersAdded)
{ {
RegisterHandlerForDefaultRenderer(typeof(NavigationPage), typeof(NavigationPageRenderer), typeof(NavigationRenderer)); RegisterHandlers();
RegisterHandlerForDefaultRenderer(typeof(TabbedPage), typeof(TabbedPageRenderer), typeof(TabbedRenderer));
RegisterHandlerForDefaultRenderer(typeof(MasterDetailPage), typeof(MasterDetailPageRenderer), typeof(MasterDetailRenderer));
RegisterHandlerForDefaultRenderer(typeof(Switch), typeof(AppCompat.SwitchRenderer), typeof(SwitchRenderer));
RegisterHandlerForDefaultRenderer(typeof(Picker), typeof(AppCompat.PickerRenderer), typeof(PickerRenderer));
RegisterHandlerForDefaultRenderer(typeof(CarouselPage), typeof(AppCompat.CarouselPageRenderer), typeof(CarouselPageRenderer));
if (Forms.Flags.Contains(Flags.FastRenderersExperimental))
{
RegisterHandlerForDefaultRenderer(typeof(Button), typeof(FastRenderers.ButtonRenderer), typeof(ButtonRenderer));
RegisterHandlerForDefaultRenderer(typeof(Label), typeof(FastRenderers.LabelRenderer), typeof(LabelRenderer));
RegisterHandlerForDefaultRenderer(typeof(Image), typeof(FastRenderers.ImageRenderer), typeof(ImageRenderer));
RegisterHandlerForDefaultRenderer(typeof(Frame), typeof(FastRenderers.FrameRenderer), typeof(FrameRenderer));
}
else
{
RegisterHandlerForDefaultRenderer(typeof(Button), typeof(AppCompat.ButtonRenderer), typeof(ButtonRenderer));
RegisterHandlerForDefaultRenderer(typeof(Frame), typeof(AppCompat.FrameRenderer), typeof(FrameRenderer));
}
_renderersAdded = true; _renderersAdded = true;
} }
@ -345,13 +359,10 @@ namespace Xamarin.Forms.Platform.Android
_application.SendSleep(); _application.SendSleep();
} }
// This is currently being used by the previewer please do not change or remove this
void RegisterHandlerForDefaultRenderer(Type target, Type handler, Type filter) void RegisterHandlerForDefaultRenderer(Type target, Type handler, Type filter)
{ {
Type current = Registrar.Registered.GetHandlerType(target); RegisterHandler(target, handler, filter);
if (current != filter)
return;
Registrar.Registered.Register(target, handler);
} }
void SetMainPage() void SetMainPage()