From a262fdc74f98d0aa70f17ff4e790d9163e3ac3f5 Mon Sep 17 00:00:00 2001 From: Mike Mostachetti Date: Wed, 22 Jul 2020 21:52:54 -0700 Subject: [PATCH] Android fix for focus change --- .../Issue9618.cs | 60 +++++++++++++++++++ ...rin.Forms.Controls.Issues.Shared.projitems | 3 +- .../Renderers/TableViewModelRenderer.cs | 2 - 3 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue9618.cs diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue9618.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue9618.cs new file mode 100644 index 00000000000..6c3d999ae2e --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue9618.cs @@ -0,0 +1,60 @@ +using System.Threading.Tasks; +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +#if UITEST +using Xamarin.Forms.Core.UITests; +using Xamarin.UITest; +using NUnit.Framework; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Github, 9618, "[Bug] Changing Text of TableSection changes focus.", PlatformAffected.All)] + public class Issue9618 : TestContentPage + { + public TableSection TableSectionToChange { get; set; } + public Editor EditorToFocus { get; set; } + + protected override void Init() + { + + var tableView = new TableView(); + var tableRoot = new TableRoot(); + + TableSectionToChange = new TableSection() { Title = "Change me" }; + var firstViewCell = new ViewCell(); + firstViewCell.View = new Label() { Text = "Hello" }; + + TableSectionToChange.Add(firstViewCell); + + var editorTableSection = new TableSection() { Title = "Editor Title" }; + var editorViewCell = new ViewCell(); + EditorToFocus = new Editor(); + + editorViewCell.View = EditorToFocus; + editorTableSection.Add(editorViewCell); + + tableRoot.Add(TableSectionToChange); + tableRoot.Add(editorTableSection); + tableView.Root = tableRoot; + + Content = tableView; + } + + protected override void OnAppearing() + { + base.OnAppearing(); + + Device.BeginInvokeOnMainThread(async () => + { + EditorToFocus.Focus(); + + await Task.Delay(4000); + + TableSectionToChange.Title = "Did I really lose focus?"; + }); + } + } +} \ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index f39a8e6cc69..170f46cdc6e 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -1439,6 +1439,7 @@ + @@ -2160,7 +2161,7 @@ Designer - MSBuild:Compile + MSBuild:UpdateDesignTimeXaml \ No newline at end of file diff --git a/Xamarin.Forms.Platform.Android/Renderers/TableViewModelRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/TableViewModelRenderer.cs index 34136aa02d0..5c5a502a9b3 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/TableViewModelRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/TableViewModelRenderer.cs @@ -160,8 +160,6 @@ public override AView GetView(int position, AView convertView, ViewGroup parent) _restoreFocus = null; } - else if (aview.HasFocus) - aview.ClearFocus(); return layout; }