From 0162b1815c2a12f3600a508849c84087b8773fa7 Mon Sep 17 00:00:00 2001 From: Samantha Houts Date: Sat, 27 Apr 2019 12:15:39 -0700 Subject: [PATCH] [Android] Use Fast Renderers by Default (#5926) * [Android] Unseal FastRenderers * [Android] Flip experimental flag to legacy flag * Flip flag for testing both renderers & set up custom renderers for testing * Undo build arg change This reverts commit 8447fec03b4dff16d8ca96544ec83159670b80d7. * Fix whitespace * restore workaround for #2520 * Only use workaround for fast renderers (crashes legacy) fixes #5724 --- .../CustomRenderers.cs | 16 +++- .../DisposeLabelRenderer.cs | 7 +- .../FormsAppCompatActivity.cs | 8 +- .../_1909CustomRenderer.cs | 9 +- .../_5724CustomRenderers.cs | 98 ++++++++++++++++++++++ .../_60122ImageRenderer.cs | 10 ++- .../Issue5724.cs | 40 +++++++++ .../Xamarin.Forms.Controls.Issues.Shared.projitems | 1 + .../AppCompat/FormsAppCompatActivity.cs | 12 +-- .../FastRenderers/ButtonRenderer.cs | 13 ++- .../FastRenderers/ImageRenderer.cs | 9 +- .../FastRenderers/LabelRenderer.cs | 9 +- Xamarin.Forms.Platform.Android/Flags.cs | 2 +- 13 files changed, 203 insertions(+), 31 deletions(-) create mode 100644 Xamarin.Forms.ControlGallery.Android/_5724CustomRenderers.cs create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue5724.cs diff --git a/Xamarin.Forms.ControlGallery.Android/CustomRenderers.cs b/Xamarin.Forms.ControlGallery.Android/CustomRenderers.cs index cf0098f..1d41e2a 100644 --- a/Xamarin.Forms.ControlGallery.Android/CustomRenderers.cs +++ b/Xamarin.Forms.ControlGallery.Android/CustomRenderers.cs @@ -69,16 +69,28 @@ namespace Xamarin.Forms.ControlGallery.Android } } - public class AttachedStateEffectLabelRenderer : LabelRenderer + public class AttachedStateEffectLabelRenderer : +#if TEST_EXPERIMENTAL_RENDERERS + Platform.Android.FastRenderers.LabelRenderer +#else + LabelRenderer +#endif { public AttachedStateEffectLabelRenderer(Context context) : base(context) { } +#if TEST_EXPERIMENTAL_RENDERERS protected override void Dispose(bool disposing) { + foreach (var effect in Element.Effects.OfType()) + { + effect.Detached(Element); + } + base.Dispose(disposing); } +#endif } public class NativeDroidMasterDetail : Xamarin.Forms.Platform.Android.AppCompat.MasterDetailPageRenderer @@ -680,7 +692,7 @@ namespace Xamarin.Forms.ControlGallery.Android protected override void Dispose(bool disposing) { - if(disposing) + if (disposing) { ViewGroup.ViewTreeObserver.RemoveOnGlobalLayoutListener(this); _gridChild.SetOnTouchListener(null); diff --git a/Xamarin.Forms.ControlGallery.Android/DisposeLabelRenderer.cs b/Xamarin.Forms.ControlGallery.Android/DisposeLabelRenderer.cs index 4a6364c..3e97ee0 100644 --- a/Xamarin.Forms.ControlGallery.Android/DisposeLabelRenderer.cs +++ b/Xamarin.Forms.ControlGallery.Android/DisposeLabelRenderer.cs @@ -4,7 +4,12 @@ using Xamarin.Forms.Platform.Android; namespace Xamarin.Forms.ControlGallery.Android { #pragma warning disable 618 - public class DisposeLabelRenderer : LabelRenderer + public class DisposeLabelRenderer : +#if TEST_EXPERIMENTAL_RENDERERS + Platform.Android.FastRenderers.LabelRenderer +#else + LabelRenderer +#endif #pragma warning restore 618 { protected override void Dispose (bool disposing) diff --git a/Xamarin.Forms.ControlGallery.Android/FormsAppCompatActivity.cs b/Xamarin.Forms.ControlGallery.Android/FormsAppCompatActivity.cs index 4ab1eb1..2ee5a7c 100644 --- a/Xamarin.Forms.ControlGallery.Android/FormsAppCompatActivity.cs +++ b/Xamarin.Forms.ControlGallery.Android/FormsAppCompatActivity.cs @@ -41,12 +41,10 @@ namespace Xamarin.Forms.ControlGallery.Android base.OnCreate(bundle); #if TEST_EXPERIMENTAL_RENDERERS - // CollectionView lets us test CollectionView stuff until it's officially released - Forms.SetFlags("FastRenderers_Experimental"/*, "CollectionView_Experimental", "Shell_Experimental"*/); -#else // Fake_Flag is here so we can test for flag initialization issues - // CollectionView lets us test CollectionView stuff until it's officially released - Forms.SetFlags("Fake_Flag"/*, "CollectionView_Experimental", "Shell_Experimental" */); + Forms.SetFlags("Fake_Flag"/*, "CollectionView_Experimental", "Shell_Experimental"*/); +#else + Forms.SetFlags("UseLegacyRenderers"/*, "CollectionView_Experimental", "Shell_Experimental" */); #endif Forms.Init(this, bundle); diff --git a/Xamarin.Forms.ControlGallery.Android/_1909CustomRenderer.cs b/Xamarin.Forms.ControlGallery.Android/_1909CustomRenderer.cs index fbfc4e0..eda38cd 100644 --- a/Xamarin.Forms.ControlGallery.Android/_1909CustomRenderer.cs +++ b/Xamarin.Forms.ControlGallery.Android/_1909CustomRenderer.cs @@ -9,8 +9,13 @@ using Xamarin.Forms.Controls.Issues; [assembly: ExportRenderer(typeof(Issue1909.FlatButton), typeof(FlatButtonRenderer))] namespace Xamarin.Forms.ControlGallery.Android { - public class FlatButtonRenderer : ButtonRenderer - { + public class FlatButtonRenderer : +#if TEST_EXPERIMENTAL_RENDERERS + Platform.Android.FastRenderers.ButtonRenderer +#else + ButtonRenderer +#endif + { public FlatButtonRenderer(Context context) : base(context) { } diff --git a/Xamarin.Forms.ControlGallery.Android/_5724CustomRenderers.cs b/Xamarin.Forms.ControlGallery.Android/_5724CustomRenderers.cs new file mode 100644 index 0000000..5bbab9a --- /dev/null +++ b/Xamarin.Forms.ControlGallery.Android/_5724CustomRenderers.cs @@ -0,0 +1,98 @@ +using Android.Content; +using System; +using System.Linq; +using Xamarin.Forms; +using Xamarin.Forms.ControlGallery.Android; +using Xamarin.Forms.Platform.Android.AppCompat; +using Xamarin.Forms.Controls.Issues; +using System.ComponentModel; + +[assembly: ExportRenderer(typeof(Issue5724.CustomButton), typeof(CustomButtonRenderer5724))] +namespace Xamarin.Forms.ControlGallery.Android +{ + public class CustomButtonRenderer5724 : +#if TEST_EXPERIMENTAL_RENDERERS + Platform.Android.FastRenderers.ButtonRenderer +#else + ButtonRenderer +#endif + { + public CustomButtonRenderer5724(Context context) : base(context) + { + } + + protected override void OnElementChanged(Platform.Android.ElementChangedEventArgs