Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 0431f0e

Browse files
committed
[Controls] Add repo for issue #12497
1 parent 446e45f commit 0431f0e

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Xamarin.Forms.CustomAttributes;
4+
using Xamarin.Forms.Internals;
5+
6+
#if UITEST
7+
using Xamarin.Forms.Core.UITests;
8+
using Xamarin.UITest;
9+
using NUnit.Framework;
10+
#endif
11+
12+
namespace Xamarin.Forms.Controls.Issues
13+
{
14+
#if UITEST
15+
[Category(UITestCategories.ManualReview)]
16+
#endif
17+
[Preserve(AllMembers = true)]
18+
[Issue(IssueTracker.Github, 12497, "Calling Focus() on a WebView on UWP does not move the focus to the WebView", PlatformAffected.UWP)]
19+
public class Issue12497 : TestContentPage // or TestFlyoutPage, etc ...
20+
{
21+
bool _firstTimeOnAppearing = true;
22+
Button _button1;
23+
Button _button2;
24+
Button _button3;
25+
WebView _webView;
26+
27+
protected override void Init()
28+
{
29+
PopulatePage();
30+
}
31+
protected override void OnAppearing()
32+
{
33+
base.OnAppearing();
34+
35+
if (_firstTimeOnAppearing)
36+
{
37+
_firstTimeOnAppearing = false;
38+
39+
//PopulatePage();
40+
41+
// The following is just here as a convenience.
42+
// It's a nasty, hacky way of setting the initial focus,
43+
// that introduces a race condition. Good enough for
44+
// this repro sample though.
45+
Task.Run(async () =>
46+
{
47+
await Task.Delay(1000);
48+
if (_button1 != null)
49+
_button1.Focus();
50+
51+
});
52+
}
53+
}
54+
55+
void PopulatePage()
56+
{
57+
int defaultTabIndex = Int32.MaxValue; // UWP says this should be the max int. Xamarin.Forms docs say it should be 0;
58+
59+
_button1 = new Button
60+
{
61+
Text = "Button 1 (should be first in tab order)",
62+
TextColor = Color.Black,
63+
BackgroundColor = Color.White,
64+
TabIndex = defaultTabIndex,
65+
VerticalOptions = LayoutOptions.Start
66+
};
67+
68+
_webView = new WebView
69+
{
70+
BackgroundColor = Color.White,
71+
HorizontalOptions = LayoutOptions.Fill,
72+
TabIndex = defaultTabIndex,
73+
VerticalOptions = LayoutOptions.FillAndExpand,
74+
Source = new HtmlWebViewSource
75+
{
76+
Html = "<html><body>Hello (should be second in tab order)<br>1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>10<br>11<br>12<br>13<br>14<br>15<br>16<br>17<br>18<br>19<br>20<br>21<br>22<br>23<br>24<br>25<br>26<br>27<br>28<br>29</body></html>"
77+
}
78+
};
79+
80+
_button2 = new Button
81+
{
82+
Text = "Button 2 (should be third in tab order)",
83+
TextColor = Color.Black,
84+
BackgroundColor = Color.White,
85+
TabIndex = defaultTabIndex,
86+
VerticalOptions = LayoutOptions.End
87+
};
88+
89+
_button3 = new Button
90+
{
91+
Text = "Button 3 (press to set focus to WebView)",
92+
TextColor = Color.Black,
93+
BackgroundColor = Color.White,
94+
TabIndex = defaultTabIndex,
95+
VerticalOptions = LayoutOptions.End,
96+
Command = new Command(() =>
97+
{
98+
_webView.Focus(); // _button1.Focus();
99+
})
100+
};
101+
102+
Content = new StackLayout
103+
{
104+
HorizontalOptions = LayoutOptions.Fill,
105+
VerticalOptions = LayoutOptions.Fill,
106+
BackgroundColor = Color.Pink,
107+
Children =
108+
{
109+
_button1,
110+
_webView,
111+
_button2,
112+
_button3
113+
}
114+
};
115+
}
116+
}
117+
}

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,7 @@
871871
<Compile Include="$(MSBuildThisFileDirectory)Issue10699.cs" />
872872
<Compile Include="$(MSBuildThisFileDirectory)Issue11185.cs" />
873873
<Compile Include="$(MSBuildThisFileDirectory)Issue10307.cs" />
874+
<Compile Include="$(MSBuildThisFileDirectory)Issue12497.cs" />
874875
<Compile Include="$(MSBuildThisFileDirectory)_TemplateMarkup.xaml.cs">
875876
<DependentUpon>_TemplateMarkup.xaml</DependentUpon>
876877
<SubType>Code</SubType>

0 commit comments

Comments
 (0)