This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [Core, UWP, Android] support TabStop/TabIndex * removing linq * add iOS / MacOS implementation * add WPF implementation fixes UWP implementation * - addressing comments - improve test - optimizations - added previous tab direction in same tab group * addressing comments * [Android] support tabstop for pickers * - moving shared code to a static class - removed reflection * ITabStop -> changed to internal, renamed, added in to fastRenderers * Update ITabStop to be public
- Loading branch information
Pavel Yakovlev
authored and
Jason Smith
committed
Sep 13, 2018
1 parent
ad8ac34
commit cceee9d
Showing
25 changed files
with
735 additions
and
59 deletions.
There are no files selected for viewing
244 changes: 244 additions & 0 deletions
244
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/GitHub1700.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,244 @@ | ||
using System.Collections.Generic; | ||
using Xamarin.Forms.CustomAttributes; | ||
using Xamarin.Forms.Internals; | ||
|
||
namespace Xamarin.Forms.Controls.Issues | ||
{ | ||
[Preserve(AllMembers = true)] | ||
[Issue(IssueTracker.Github, 1700, "Desktop: TabStop/TabIndex support (for multiple Views)", PlatformAffected.All)] | ||
public class GitHub1700 : TestContentPage | ||
{ | ||
IList<View> listViews; | ||
|
||
void IndexDesc() | ||
{ | ||
int index = 100500; | ||
foreach (var item in listViews) | ||
{ | ||
if (item is Button but && but.Text.StartsWith("TabIndex")) | ||
continue; | ||
item.TabIndex = index--; | ||
} | ||
} | ||
|
||
void IndexNegative() | ||
{ | ||
int index = -100; | ||
foreach (var item in listViews) | ||
{ | ||
if (item is Button but && but.Text.StartsWith("TabIndex")) | ||
continue; | ||
item.TabIndex = index++; | ||
} | ||
} | ||
|
||
protected override void Init() | ||
{ | ||
var actionGrid = new Grid() | ||
{ | ||
Padding = new Thickness(10), | ||
BackgroundColor = Color.Aquamarine | ||
}; | ||
actionGrid.AddChild(new Button() | ||
{ | ||
Text = "Index desc", | ||
Command = new Command(() => IndexDesc()) | ||
}, 0, 0); | ||
actionGrid.AddChild(new Button() | ||
{ | ||
Text = "All indexes equal 0", | ||
Command = new Command(() => listViews.ForEach(c => c.TabIndex = 0)) | ||
}, 1, 0); | ||
actionGrid.AddChild(new Button() | ||
{ | ||
Text = "Negative indexes", | ||
Command = new Command(() => IndexNegative()) | ||
}, 2, 0); | ||
actionGrid.AddChild(new Button() | ||
{ | ||
Text = "TabStops = True", | ||
Command = new Command(() => listViews.ForEach(c => c.IsTabStop = true)) | ||
}, 0, 1); | ||
actionGrid.AddChild(new Button() | ||
{ | ||
Text = "TabStops = False", | ||
Command = new Command(() => listViews.ForEach(c => c.IsTabStop = false)) | ||
}, 1, 1); | ||
actionGrid.AddChild(new Button() | ||
{ | ||
Text = "TabStops every second", | ||
Command = new Command(() => | ||
{ | ||
for (int i = 0; i < listViews.Count; i++) | ||
listViews[i].IsTabStop = i % 2 == 0; | ||
}) | ||
}, 2, 1); | ||
|
||
var pickerStopped = new Picker | ||
{ | ||
Title = $"[+] Picker - Tab stop enable", | ||
IsTabStop = true | ||
}; | ||
var pickerNotStopped = new Picker | ||
{ | ||
Title = "[-] Picker - Tab stop disable", | ||
IsTabStop = false | ||
}; | ||
for (var i = 1; i < 3; i++) { | ||
pickerNotStopped.Items.Add("Sample Option " + i); | ||
pickerStopped.Items.Add("Sample Option " + i); | ||
} | ||
|
||
var stack = new StackLayout | ||
{ | ||
Children = | ||
{ | ||
actionGrid, | ||
pickerStopped, | ||
pickerNotStopped, | ||
new Button | ||
{ | ||
Text = $"TabIndex 90", | ||
IsTabStop = true, | ||
TabIndex = 90 | ||
}, | ||
new Button | ||
{ | ||
Text = $"TabIndex 100", | ||
IsTabStop = true, | ||
TabIndex = 100 | ||
}, | ||
new Button | ||
{ | ||
Text = $"TabIndex 100", | ||
IsTabStop = true, | ||
TabIndex = 100 | ||
}, | ||
new Button | ||
{ | ||
Text = $"TabIndex 90", | ||
IsTabStop = true, | ||
TabIndex = 90 | ||
}, | ||
new Button | ||
{ | ||
Text = $"[+] Button - TabStop enable", | ||
IsTabStop = true | ||
}, | ||
new Button | ||
{ | ||
Text = "Button - Non stop", | ||
IsTabStop = false | ||
}, | ||
new DatePicker | ||
{ | ||
IsTabStop = true | ||
}, | ||
new DatePicker | ||
{ | ||
IsTabStop = false | ||
}, | ||
new Editor | ||
{ | ||
Text = $"[+] Editor - Tab stop enable", | ||
IsTabStop = true | ||
}, | ||
new Editor | ||
{ | ||
Text = "Editor - Non stop", | ||
IsTabStop = false | ||
}, | ||
new Entry | ||
{ | ||
Text = $"[+] Entry - Tab stop enable", | ||
IsTabStop = true | ||
}, | ||
new Entry | ||
{ | ||
Text = "Entry - Non stop", | ||
IsTabStop = false | ||
}, | ||
new ProgressBar | ||
{ | ||
IsTabStop = true, | ||
HeightRequest = 40, | ||
Progress = 80 | ||
}, | ||
new ProgressBar | ||
{ | ||
IsTabStop = false, | ||
HeightRequest = 40, | ||
Progress = 40 | ||
}, | ||
new SearchBar | ||
{ | ||
Text = $"[+] SearchBar - TabStop enable", | ||
IsTabStop = true | ||
}, | ||
new SearchBar | ||
{ | ||
Text = "SearchBar - TabStop disable", | ||
IsTabStop = false | ||
}, | ||
new Slider | ||
{ | ||
IsTabStop = true | ||
}, | ||
new Slider | ||
{ | ||
IsTabStop = false | ||
}, | ||
new Stepper | ||
{ | ||
IsTabStop = true | ||
}, | ||
new Stepper | ||
{ | ||
IsTabStop = false | ||
}, | ||
new Switch | ||
{ | ||
IsTabStop = true | ||
}, | ||
new Switch | ||
{ | ||
IsTabStop = false | ||
}, | ||
new TimePicker | ||
{ | ||
IsTabStop = true | ||
}, | ||
new TimePicker | ||
{ | ||
IsTabStop = false | ||
}, | ||
} | ||
}; | ||
|
||
listViews = stack.Children; | ||
|
||
foreach (var item in listViews) | ||
{ | ||
item.Focused += (_, e) => | ||
{ | ||
BackgroundColor = e.VisualElement.IsTabStop ? Color.Transparent : Color.OrangeRed; | ||
Title = $"{e.VisualElement.TabIndex} - " + (e.VisualElement.IsTabStop ? "[+]" : "WRONG"); | ||
e.VisualElement.Scale = 0.7; | ||
}; | ||
item.Unfocused += (_, e) => | ||
{ | ||
BackgroundColor = Color.Transparent; | ||
Title = string.Empty; | ||
e.VisualElement.Scale = 1; | ||
}; | ||
} | ||
|
||
IndexDesc(); | ||
|
||
Content = new ScrollView() | ||
{ | ||
Content = stack | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using System.Collections.Generic; | ||
using Xamarin.Forms.Internals; | ||
|
||
namespace Xamarin.Forms | ||
{ | ||
public static class TabIndexExtensions | ||
{ | ||
public static IDictionary<int, List<VisualElement>> GetTabIndexesOnParentPage(this VisualElement element, out int countChildrensWithTabStopWithoutThis) | ||
{ | ||
countChildrensWithTabStopWithoutThis = 0; | ||
|
||
Element parentPage = element.Parent; | ||
while (parentPage != null && !(parentPage is Page)) | ||
parentPage = parentPage.Parent; | ||
|
||
var descendantsOnPage = parentPage?.VisibleDescendants(); | ||
if (descendantsOnPage == null) | ||
return null; | ||
|
||
var childrensWithTabStop = new List<VisualElement>(); | ||
foreach (var descendant in descendantsOnPage) | ||
{ | ||
if (descendant is VisualElement visualElement && visualElement.IsTabStop) | ||
childrensWithTabStop.Add(visualElement); | ||
} | ||
if (!childrensWithTabStop.Contains(element)) | ||
return null; | ||
|
||
countChildrensWithTabStopWithoutThis = childrensWithTabStop.Count - 1; | ||
return childrensWithTabStop.GroupToDictionary(c => c.TabIndex); | ||
} | ||
|
||
public static VisualElement FindNextElement(this VisualElement element, bool forwardDirection, IDictionary<int, List<VisualElement>> tabIndexes, ref int tabIndex) | ||
{ | ||
var tabGroup = tabIndexes[tabIndex]; | ||
if (!forwardDirection) | ||
{ | ||
// search prev element in same TabIndex group | ||
var prevSubIndex = tabGroup.IndexOf(element) - 1; | ||
if (prevSubIndex >= 0 && prevSubIndex < tabGroup.Count) | ||
{ | ||
return tabGroup[prevSubIndex]; | ||
} | ||
else // search prev element in prev TabIndex group | ||
{ | ||
var smallerMax = int.MinValue; | ||
var tabIndexesMax = int.MinValue; | ||
foreach (var index in tabIndexes.Keys) | ||
{ | ||
if (index < tabIndex && smallerMax < index) | ||
smallerMax = index; | ||
if (tabIndexesMax < index) | ||
tabIndexesMax = index; | ||
} | ||
tabIndex = smallerMax != int.MinValue ? smallerMax : tabIndexesMax; | ||
return tabIndexes[tabIndex][0]; | ||
} | ||
} | ||
else // Forward | ||
{ | ||
// search next element in same TabIndex group | ||
var nextSubIndex = tabGroup.IndexOf(element) + 1; | ||
if (nextSubIndex > 0 && nextSubIndex < tabGroup.Count) | ||
{ | ||
return tabGroup[nextSubIndex]; | ||
} | ||
else // search next element in next TabIndex group | ||
{ | ||
var biggerMin = int.MaxValue; | ||
var tabIndexesMin = int.MaxValue; | ||
foreach (var index in tabIndexes.Keys) | ||
{ | ||
if (index > tabIndex && biggerMin > index) | ||
biggerMin = index; | ||
if (tabIndexesMin > index) | ||
tabIndexesMin = index; | ||
} | ||
tabIndex = biggerMin != int.MaxValue ? biggerMin : tabIndexesMin; | ||
return tabIndexes[tabIndex][0]; | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.