From 27d48dc908b5d32c4a893f9a638926660a1d0b7b Mon Sep 17 00:00:00 2001 From: Eilon Lipton Date: Thu, 26 Sep 2019 14:26:43 -0700 Subject: [PATCH] Remove all generics from main APIs - They were almost entirely noise because the only place the generics mattered is on the [Native]ElementManager - To make writing generic ElementManagers easier, a new generic ElementManager was added --- .../BlaxamarinElementManager.cs | 17 ++++--- .../BlaxamarinRenderer.cs | 4 +- src/Blaxamarin.Framework/Elements/Button.cs | 2 +- .../Elements/ContentPage.cs | 2 +- src/Blaxamarin.Framework/Elements/Entry.cs | 2 +- .../Elements/Handlers/ButtonHandler.cs | 2 +- .../Elements/Handlers/ContentPageHandler.cs | 2 +- .../Elements/Handlers/DetailPageHandler.cs | 2 +- .../Elements/Handlers/ElementHandler.cs | 4 +- .../Elements/Handlers/EntryHandler.cs | 2 +- .../Elements/Handlers/InputViewHandler.cs | 2 +- .../Elements/Handlers/LabelHandler.cs | 2 +- .../Elements/Handlers/LayoutHandler.cs | 2 +- .../Handlers/MasterDetailPageHandler.cs | 2 +- .../Elements/Handlers/MasterPageHandler.cs | 2 +- .../Handlers/NavigableElementHandler.cs | 2 +- .../Elements/Handlers/PageHandler.cs | 2 +- .../Elements/Handlers/ScrollViewHandler.cs | 2 +- .../Elements/Handlers/StackLayoutHandler.cs | 2 +- .../Elements/Handlers/SwitchHandler.cs | 2 +- .../Elements/Handlers/TabbedPageHandler.cs | 2 +- .../Elements/Handlers/TemplatedPageHandler.cs | 2 +- .../Elements/Handlers/ViewHandler.cs | 2 +- .../Elements/Handlers/VisualElementHandler.cs | 2 +- src/Blaxamarin.Framework/Elements/Label.cs | 2 +- .../Elements/MasterDetailDetailPage.cs | 2 +- .../Elements/MasterDetailMasterPage.cs | 2 +- .../Elements/MasterDetailPage.cs | 2 +- src/Blaxamarin.Framework/Elements/Page.cs | 2 +- .../Elements/ScrollView.cs | 2 +- .../Elements/StackLayout.cs | 2 +- src/Blaxamarin.Framework/Elements/Switch.cs | 2 +- .../Elements/TabbedPage.cs | 2 +- .../BlinFormsElementManager.cs | 28 +++++----- src/BlinForms.Framework/BlinFormsRenderer.cs | 4 +- src/BlinForms.Framework/Controls/Button.cs | 6 +-- src/BlinForms.Framework/Controls/CheckBox.cs | 6 +-- src/BlinForms.Framework/Controls/Label.cs | 2 +- src/BlinForms.Framework/Controls/Panel.cs | 2 +- .../Controls/SplitContainer.cs | 2 +- .../Controls/SplitterPanel1.cs | 4 +- .../Controls/SplitterPanel2.cs | 4 +- src/BlinForms.Framework/Controls/TextBox.cs | 6 +-- src/Emblazon/ElementHandlerFactory.cs | 8 +-- src/Emblazon/ElementHandlerFactoryContext.cs | 8 +-- src/Emblazon/ElementHandlerRegistry.cs | 18 +++---- src/Emblazon/ElementManager.cs | 13 +++-- src/Emblazon/ElementManagerOfElementType.cs | 51 +++++++++++++++++++ src/Emblazon/EmblazonAdapter.cs | 30 +++++------ src/Emblazon/EmblazonRenderer.cs | 26 ++++++---- 50 files changed, 180 insertions(+), 123 deletions(-) create mode 100644 src/Emblazon/ElementManagerOfElementType.cs diff --git a/src/Blaxamarin.Framework/BlaxamarinElementManager.cs b/src/Blaxamarin.Framework/BlaxamarinElementManager.cs index 25df1b4..c009825 100644 --- a/src/Blaxamarin.Framework/BlaxamarinElementManager.cs +++ b/src/Blaxamarin.Framework/BlaxamarinElementManager.cs @@ -6,9 +6,12 @@ namespace Blaxamarin.Framework { internal class BlaxamarinElementManager : ElementManager { - public override bool IsParented(IXamarinFormsElementHandler handler) => handler.ElementControl.Parent != null; + protected override bool IsParented(IXamarinFormsElementHandler handler) + { + return handler.ElementControl.Parent != null; + } - public override void AddChildElement( + protected override void AddChildElement( IXamarinFormsElementHandler parentHandler, IXamarinFormsElementHandler childHandler, int physicalSiblingIndex) @@ -109,11 +112,10 @@ namespace Blaxamarin.Framework } } - public override int GetPhysicalSiblingIndex( + protected override int GetPhysicalSiblingIndex( IXamarinFormsElementHandler handler) { // TODO: What is the set of types that support child elements? Do they all need to be special-cased here? (Maybe...) - var nativeComponent = handler.ElementControl; switch (nativeComponent.Parent) @@ -154,9 +156,10 @@ namespace Blaxamarin.Framework } } - public override void RemoveElement(IXamarinFormsElementHandler handler) + protected override void RemoveElement(IXamarinFormsElementHandler handler) { // TODO: Need to make this logic more generic; not all parents are Layouts, not all children are Views + var control = handler.ElementControl; var physicalParent = control.Parent; if (physicalParent is Layout physicalParentAsLayout) @@ -166,9 +169,9 @@ namespace Blaxamarin.Framework } } - public override bool IsParentOfChild(IXamarinFormsElementHandler parentControl, IXamarinFormsElementHandler childControl) + protected override bool IsParentOfChild(IXamarinFormsElementHandler parentHandler, IXamarinFormsElementHandler childHandler) { - return childControl.ElementControl.Parent == parentControl.ElementControl; + return childHandler.ElementControl.Parent == parentHandler.ElementControl; } } } diff --git a/src/Blaxamarin.Framework/BlaxamarinRenderer.cs b/src/Blaxamarin.Framework/BlaxamarinRenderer.cs index 5beb9c9..3f0e576 100644 --- a/src/Blaxamarin.Framework/BlaxamarinRenderer.cs +++ b/src/Blaxamarin.Framework/BlaxamarinRenderer.cs @@ -5,7 +5,7 @@ using System.Diagnostics; namespace Blaxamarin.Framework { - public class BlaxamarinRenderer : EmblazonRenderer + public class BlaxamarinRenderer : EmblazonRenderer { public BlaxamarinRenderer(IServiceProvider serviceProvider, ILoggerFactory loggerFactory) : base(serviceProvider, loggerFactory) @@ -20,7 +20,7 @@ namespace Blaxamarin.Framework //MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } - protected override ElementManager CreateNativeControlManager() + protected override ElementManager CreateNativeControlManager() { return new BlaxamarinElementManager(); } diff --git a/src/Blaxamarin.Framework/Elements/Button.cs b/src/Blaxamarin.Framework/Elements/Button.cs index 083aca9..44e5b8c 100644 --- a/src/Blaxamarin.Framework/Elements/Button.cs +++ b/src/Blaxamarin.Framework/Elements/Button.cs @@ -9,7 +9,7 @@ namespace Blaxamarin.Framework.Elements { static Button() { - ElementHandlerRegistry + ElementHandlerRegistry .RegisterElementHandler