From d7bfb0cb7bdbea47a09c228550e64541184fe9b9 Mon Sep 17 00:00:00 2001 From: Pavel Yakovlev Date: Sat, 19 Jan 2019 21:19:03 +0300 Subject: [PATCH] [UWP] Fixes IsTabStop property in Layouts (#4703) * [UWP] the ScrollView does not gain focus * address comments fixes #4653 --- .../Issue4653.cs | 74 ++++++++++++++++++++++ .../Xamarin.Forms.Controls.Issues.Shared.projitems | 1 + Xamarin.Forms.Platform.UAP/IDontGetFocus.cs | 6 ++ .../ITabStopOnDescendants.cs | 2 +- Xamarin.Forms.Platform.UAP/ScrollViewRenderer.cs | 2 +- .../VisualElementRenderer.cs | 2 +- .../Xamarin.Forms.Platform.UAP.csproj | 1 + 7 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue4653.cs create mode 100644 Xamarin.Forms.Platform.UAP/IDontGetFocus.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 0000000..4b5ec0f --- /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 91a8c9b..65b5df1 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 @@ -85,6 +85,7 @@ + diff --git a/Xamarin.Forms.Platform.UAP/IDontGetFocus.cs b/Xamarin.Forms.Platform.UAP/IDontGetFocus.cs new file mode 100644 index 0000000..4def28f --- /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 4209fa6..91992f2 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 c049a5d..378c6c0 100644 --- a/Xamarin.Forms.Platform.UAP/ScrollViewRenderer.cs +++ b/Xamarin.Forms.Platform.UAP/ScrollViewRenderer.cs @@ -8,7 +8,7 @@ using UwpScrollBarVisibility = Windows.UI.Xaml.Controls.ScrollBarVisibility; 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 5d5e8c3..e806952 100644 --- a/Xamarin.Forms.Platform.UAP/VisualElementRenderer.cs +++ b/Xamarin.Forms.Platform.UAP/VisualElementRenderer.cs @@ -155,7 +155,7 @@ namespace Xamarin.Forms.Platform.UWP OnElementChanged(new ElementChangedEventArgs(oldElement, Element)); - if (_control != null && this is ITabStopOnDescendants) + 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 14d9c45..be4065b 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 @@ + -- 2.7.4