From 6afa6f74a0107a720050a5ecf05480d40f69d5a2 Mon Sep 17 00:00:00 2001 From: Pavel Yakovlev Date: Thu, 13 Dec 2018 21:53:10 +0300 Subject: [PATCH 1/2] [UWP] the ScrollView does not gain focus --- .../Issue4653.cs | 74 +++++++++++++++++++ ...rin.Forms.Controls.Issues.Shared.projitems | 1 + .../VisualElementRenderer.cs | 2 +- 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue4653.cs diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue4653.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue4653.cs new file mode 100644 index 00000000000..4b5ec0f2251 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue4653.cs @@ -0,0 +1,74 @@ +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Github, 4653, "IsTabStop property not working when Grid contains ScrollView", PlatformAffected.UWP)] + public class Issue4653 : TestContentPage + { + protected override void Init() + { + var grid = new Grid() + { + Padding = new Thickness(10), + BackgroundColor = Color.Aquamarine, + IsTabStop = false + }; + grid.AddChild(new Button + { + Text = "Toggle Grid IsTabStop", + Command = new Command(() => grid.IsTabStop = !grid.IsTabStop) + }, 0, 0); + grid.AddChild(new Button + { + Text = "IsTabStop: false", + IsTabStop = false + }, 1, 0); + + var buttonInSctoolView = new Button + { + Text = "Button inside tadded ScrollView", + IsTabStop = false + }; + buttonInSctoolView.Command = new Command(() => { + buttonInSctoolView.IsTabStop = !buttonInSctoolView.IsTabStop; + buttonInSctoolView.Text = $"IsTabStop: {buttonInSctoolView.IsTabStop}"; + }); + + grid.AddChild(new ScrollView + { + Content = buttonInSctoolView + }, 0, 1); + + grid.AddChild(new Entry + { + Text = "entry" + }, 1, 1); + + int col = 2; + grid.AddChild(new Button + { + Text = "Add default button", + IsTabStop = false, + Command = new Command(() => grid.AddChild(new Button { Text = "default" }, 0, ++col)) + }, 0, 2); + + int colNonTabbed = 2; + grid.AddChild(new Button + { + Text = "Add non tabbed button", + IsTabStop = true, + Command = new Command(() => grid.AddChild(new Button { Text = "non tabbed", IsTabStop = false }, 1, ++colNonTabbed)) + }, 1, 2); + + Content = new StackLayout + { + Children = + { + grid + } + }; + } + } +} \ 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 8d4bc099f84..6816dc2459f 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 @@ -82,6 +82,7 @@ + diff --git a/Xamarin.Forms.Platform.UAP/VisualElementRenderer.cs b/Xamarin.Forms.Platform.UAP/VisualElementRenderer.cs index 5d5e8c3932e..842a069626c 100644 --- a/Xamarin.Forms.Platform.UAP/VisualElementRenderer.cs +++ b/Xamarin.Forms.Platform.UAP/VisualElementRenderer.cs @@ -155,7 +155,7 @@ public void SetElement(VisualElement element) OnElementChanged(new ElementChangedEventArgs(oldElement, Element)); - if (_control != null && this is ITabStopOnDescendants) + if (_control != null && (this is ITabStopOnDescendants || this is ScrollViewRenderer)) { _control.GotFocus += OnGotFocus; _control.GettingFocus += OnGettingFocus; From b2d3e46e0895a305d28225cd06124367574a1b50 Mon Sep 17 00:00:00 2001 From: Pavel Yakovlev Date: Fri, 21 Dec 2018 15:13:27 +0300 Subject: [PATCH 2/2] address comments --- Xamarin.Forms.Platform.UAP/IDontGetFocus.cs | 6 ++++++ Xamarin.Forms.Platform.UAP/ITabStopOnDescendants.cs | 2 +- Xamarin.Forms.Platform.UAP/ScrollViewRenderer.cs | 2 +- Xamarin.Forms.Platform.UAP/VisualElementRenderer.cs | 2 +- .../Xamarin.Forms.Platform.UAP.csproj | 1 + 5 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 Xamarin.Forms.Platform.UAP/IDontGetFocus.cs diff --git a/Xamarin.Forms.Platform.UAP/IDontGetFocus.cs b/Xamarin.Forms.Platform.UAP/IDontGetFocus.cs new file mode 100644 index 00000000000..4def28f5d16 --- /dev/null +++ b/Xamarin.Forms.Platform.UAP/IDontGetFocus.cs @@ -0,0 +1,6 @@ +namespace Xamarin.Forms.Platform.UWP +{ + public interface IDontGetFocus + { + } +} diff --git a/Xamarin.Forms.Platform.UAP/ITabStopOnDescendants.cs b/Xamarin.Forms.Platform.UAP/ITabStopOnDescendants.cs index 4209fa68726..91992f210c3 100644 --- a/Xamarin.Forms.Platform.UAP/ITabStopOnDescendants.cs +++ b/Xamarin.Forms.Platform.UAP/ITabStopOnDescendants.cs @@ -1,6 +1,6 @@ namespace Xamarin.Forms.Platform.UWP { - public interface ITabStopOnDescendants + public interface ITabStopOnDescendants: IDontGetFocus { } } diff --git a/Xamarin.Forms.Platform.UAP/ScrollViewRenderer.cs b/Xamarin.Forms.Platform.UAP/ScrollViewRenderer.cs index 06de39212ff..e05a20610da 100644 --- a/Xamarin.Forms.Platform.UAP/ScrollViewRenderer.cs +++ b/Xamarin.Forms.Platform.UAP/ScrollViewRenderer.cs @@ -8,7 +8,7 @@ namespace Xamarin.Forms.Platform.UWP { - public class ScrollViewRenderer : ViewRenderer + public class ScrollViewRenderer : ViewRenderer, IDontGetFocus { VisualElement _currentView; bool _checkedForRtlScroll = false; diff --git a/Xamarin.Forms.Platform.UAP/VisualElementRenderer.cs b/Xamarin.Forms.Platform.UAP/VisualElementRenderer.cs index 842a069626c..e8069520f7c 100644 --- a/Xamarin.Forms.Platform.UAP/VisualElementRenderer.cs +++ b/Xamarin.Forms.Platform.UAP/VisualElementRenderer.cs @@ -155,7 +155,7 @@ public void SetElement(VisualElement element) OnElementChanged(new ElementChangedEventArgs(oldElement, Element)); - if (_control != null && (this is ITabStopOnDescendants || this is ScrollViewRenderer)) + if (_control != null && this is IDontGetFocus) { _control.GotFocus += OnGotFocus; _control.GettingFocus += OnGettingFocus; diff --git a/Xamarin.Forms.Platform.UAP/Xamarin.Forms.Platform.UAP.csproj b/Xamarin.Forms.Platform.UAP/Xamarin.Forms.Platform.UAP.csproj index d660e956f68..6143729fc0c 100644 --- a/Xamarin.Forms.Platform.UAP/Xamarin.Forms.Platform.UAP.csproj +++ b/Xamarin.Forms.Platform.UAP/Xamarin.Forms.Platform.UAP.csproj @@ -49,6 +49,7 @@ +