From 0dd61b71ec33c566ddcdf0fcb3aa2ec177b67399 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Thu, 31 Jan 2019 01:44:23 +0200 Subject: [PATCH] [Material] + [Android, iOS] Refactored and fixed lots of button layout issues (#4967) * [Android] Refactored and fixed lots of button layout issues - All text, image and content layout logic has been extracted into a separate manager - Fixed the issue buttons with just an image changing size - Fixed a few button padding issues (still needs another look) - Fixed the issue with the content layout changes not updating the actual button layout - Fixed image positioning for all (not legacy) buttons - Material button no longer uses material image layout as it overrides the custom positioning - Fixed a few other issues where properties don't change the native button, or layouts break the positioning of the image * [Button] Fixed a whole bunch of issues - added a platform specific "BorderAdjustsPadding" to Android and iOS to prevent border overlap - added a new gallery with all sorts of buttons - improvements to the Android button layout manager - fixed to the Android button measure/layout process * [Android] [Button] The preservation of default padding is now a flag * [iOS] [Button] Extracted all the layout logic for the classic button - yet to update Material button to use this - fixed a few issues with the iOS layout - content layout changes were not updating the control - top/bottom did not respect spacing - the native control trimmed text in the getter, so use the value from the element * Removing the platform specifics as they were the wrong property - the property is part of the renderer implementation - Material button on iOS still needs implementing * Updated the material button to use the layout manager - the iOS layout logic needs some more investigation * remove old comments * A fix for when there is no text and some backwards compatibility * Added a more realistic set of values * Restrict the material button border to 1px. See #4951. * Fixed that issue with the buttons and the padding... - Removed the inset so that layout is accurate - set the padding to 8dp to match that of iOS and Material - set the minimum height to 36 according to Material (it was 48dp, with 12dp total inset, and, 48-12=36) * Update Xamarin.Forms.Core/Button.cs Co-Authored-By: mattleibow * Don't add members to the public type * [Material] Added a button to change text size in the demo page * appcompat regression fixes * move state checks around * fix bad merge * adding delay to ui tests --- .../Bugzilla39821.cs | 2 +- .../Bugzilla41415.cs | 4 +- .../Issue2482.cs | 2 +- Xamarin.Forms.Controls/CoreGallery.cs | 4 + .../ButtonBorderBackgroundGalleryPage.xaml | 101 ++++++ .../ButtonBorderBackgroundGalleryPage.xaml.cs | 56 ++++ .../GalleryPages/ButtonLayoutGalleryPage.xaml | 129 ++++++++ .../GalleryPages/ButtonLayoutGalleryPage.xaml.cs | 195 ++++++++++++ Xamarin.Forms.Controls/ThicknessConverter.cs | 36 +++ Xamarin.Forms.Core/Button.cs | 3 +- Xamarin.Forms.Core/Thickness.cs | 2 +- Xamarin.Forms.Core/VisualElement.cs | 2 +- .../MaterialButtonRenderer.cs | 199 +++--------- .../AppCompat/ButtonRenderer.cs | 228 ++----------- .../{FastRenderers => }/ButtonElementManager.cs | 18 +- .../ButtonLayoutManager.cs | 301 ++++++++++++++++++ Xamarin.Forms.Platform.Android/Extensions.cs | 4 + .../FastRenderers/ButtonRenderer.cs | 198 +++--------- .../IButtonLayoutRenderer.cs | 12 + .../Material/MaterialButtonRenderer.cs | 187 ++--------- .../Resources/values/styles.xml | 7 +- .../Xamarin.Forms.Platform.Android.csproj | 4 +- .../Extensions/Extensions.cs | 4 + .../Renderers/ButtonLayoutManager.cs | 353 +++++++++++++++++++++ .../Renderers/ButtonRenderer.cs | 167 ++-------- .../Renderers/IButtonLayoutRenderer.cs | 14 + .../Xamarin.Forms.Platform.iOS.csproj | 2 + 27 files changed, 1406 insertions(+), 828 deletions(-) create mode 100644 Xamarin.Forms.Controls/GalleryPages/ButtonBorderBackgroundGalleryPage.xaml create mode 100644 Xamarin.Forms.Controls/GalleryPages/ButtonBorderBackgroundGalleryPage.xaml.cs create mode 100644 Xamarin.Forms.Controls/GalleryPages/ButtonLayoutGalleryPage.xaml create mode 100644 Xamarin.Forms.Controls/GalleryPages/ButtonLayoutGalleryPage.xaml.cs create mode 100644 Xamarin.Forms.Controls/ThicknessConverter.cs rename Xamarin.Forms.Platform.Android/{FastRenderers => }/ButtonElementManager.cs (66%) create mode 100644 Xamarin.Forms.Platform.Android/ButtonLayoutManager.cs create mode 100644 Xamarin.Forms.Platform.Android/IButtonLayoutRenderer.cs create mode 100644 Xamarin.Forms.Platform.iOS/Renderers/ButtonLayoutManager.cs create mode 100644 Xamarin.Forms.Platform.iOS/Renderers/IButtonLayoutRenderer.cs diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39821.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39821.cs index 443eff1..58bca78 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39821.cs +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39821.cs @@ -123,7 +123,7 @@ namespace Xamarin.Forms.Controls.Issues public void DoesNotCrash() { RunningApp.Tap(q => q.Marked("Animate")); - RunningApp.WaitForElement(q => q.Marked("Success")); + RunningApp.WaitForElement(q => q.Marked("Success"), timeout:TimeSpan.FromSeconds(25)); } #endif } diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41415.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41415.cs index a8c8f03..978292b 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41415.cs +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41415.cs @@ -102,12 +102,12 @@ namespace Xamarin.Forms.Controls.Issues RunningApp.Tap(q => q.Marked(ButtonText)); RunningApp.WaitForElement(q => q.Marked("x: 100")); RunningApp.WaitForElement(q => q.Marked("y: 100")); - RunningApp.WaitForElement(q => q.Marked("z: True")); + RunningApp.WaitForElement(q => q.Marked("z: True"), timeout: TimeSpan.FromSeconds(25)); RunningApp.WaitForElement(q => q.Marked("a: True")); RunningApp.Tap(q => q.Marked(ButtonText)); RunningApp.WaitForElement(q => q.Marked("x: 200")); RunningApp.WaitForElement(q => q.Marked("y: 100")); - RunningApp.WaitForElement(q => q.Marked("z: True")); + RunningApp.WaitForElement(q => q.Marked("z: True"), timeout: TimeSpan.FromSeconds(25)); RunningApp.WaitForElement(q => q.Marked("a: False")); } diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2482.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2482.cs index c98a3f4..71e01b9 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2482.cs +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2482.cs @@ -75,7 +75,7 @@ namespace Xamarin.Forms.Controls.Issues { RunningApp.WaitForElement(ButtonId); RunningApp.DoubleTap(ButtonId); - RunningApp.WaitForElement(Success); + RunningApp.WaitForElement(Success, timeout: TimeSpan.FromSeconds(25)); } #endif } diff --git a/Xamarin.Forms.Controls/CoreGallery.cs b/Xamarin.Forms.Controls/CoreGallery.cs index 2e28552..f0edad6 100644 --- a/Xamarin.Forms.Controls/CoreGallery.cs +++ b/Xamarin.Forms.Controls/CoreGallery.cs @@ -306,6 +306,10 @@ namespace Xamarin.Forms.Controls new GalleryPageFactory(() => new ContextActionsGallery (tableView: true), "ContextActions Table Gallery"), new GalleryPageFactory(() => new CoreBoxViewGalleryPage(), "BoxView Gallery"), new GalleryPageFactory(() => new ButtonCoreGalleryPage(), "Button Gallery"), + new GalleryPageFactory(() => new ButtonLayoutGalleryPage(), "Button Layout Gallery"), + new GalleryPageFactory(() => new ButtonLayoutGalleryPage(VisualMarker.Material), "Button Layout Gallery (Material)"), + new GalleryPageFactory(() => new ButtonBorderBackgroundGalleryPage(), "Button Border & Background Gallery"), + new GalleryPageFactory(() => new ButtonBorderBackgroundGalleryPage(VisualMarker.Material), "Button Border & Background Gallery (Material)"), new GalleryPageFactory(() => new DatePickerCoreGalleryPage(), "DatePicker Gallery"), new GalleryPageFactory(() => new EditorCoreGalleryPage(), "Editor Gallery"), new GalleryPageFactory(() => new FrameCoreGalleryPage(), "Frame Gallery"), diff --git a/Xamarin.Forms.Controls/GalleryPages/ButtonBorderBackgroundGalleryPage.xaml b/Xamarin.Forms.Controls/GalleryPages/ButtonBorderBackgroundGalleryPage.xaml new file mode 100644 index 0000000..b0bf156 --- /dev/null +++ b/Xamarin.Forms.Controls/GalleryPages/ButtonBorderBackgroundGalleryPage.xaml @@ -0,0 +1,101 @@ + + + + + + + + + + + +