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

Commit b38d590

Browse files
authored
Don't update page offset if not visible (#11602)
fixes #10608
1 parent 9355d6b commit b38d590

File tree

5 files changed

+123
-2
lines changed

5 files changed

+123
-2
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
using System.Threading.Tasks;
2+
using Xamarin.Forms.CustomAttributes;
3+
using Xamarin.Forms.Internals;
4+
5+
#if UITEST
6+
using Xamarin.Forms.Core.UITests;
7+
using Xamarin.UITest;
8+
using NUnit.Framework;
9+
#endif
10+
11+
namespace Xamarin.Forms.Controls.Issues
12+
{
13+
#if UITEST
14+
[Category(UITestCategories.Shell)]
15+
#endif
16+
[Preserve(AllMembers = true)]
17+
[Issue(IssueTracker.Github, 10608, "[Bug] [Shell] [iOS] Locked flyout causes application to freezes when quickly switching between tabs", PlatformAffected.iOS)]
18+
public class Issue10608 : TestShell
19+
{
20+
public Issue10608()
21+
{
22+
}
23+
24+
protected override void Init()
25+
{
26+
FlyoutBehavior = FlyoutBehavior.Locked;
27+
28+
AddFlyoutItem("Click");
29+
AddFlyoutItem("Between");
30+
AddFlyoutItem("These Flyouts");
31+
AddFlyoutItem("Really Fast");
32+
AddFlyoutItem("If it doesn't");
33+
AddFlyoutItem("Lock test has passed");
34+
35+
int i = 0;
36+
foreach(var item in Items)
37+
{
38+
item.Items[0].AutomationId = $"FlyoutItem{i}";
39+
item.Items[0].Items.Add(new ContentPage()
40+
{
41+
Title = "Page"
42+
});
43+
44+
i++;
45+
}
46+
47+
Items.Add(new MenuItem()
48+
{
49+
Text = "Let me click for you",
50+
AutomationId = $"FlyoutItem{i}",
51+
Command = new Command(async () =>
52+
{
53+
for (int j = 0; j < 5; j++)
54+
{
55+
CurrentItem = Items[0].Items[0];
56+
await Task.Delay(10);
57+
CurrentItem = Items[1].Items[0];
58+
await Task.Delay(10);
59+
}
60+
61+
CurrentItem = Items[0].Items[0];
62+
})
63+
});
64+
65+
Items[0].Items[0].Items[0].Title = "Tab 1";
66+
Items[0].Items[0].Items[0].AutomationId = "Tab1AutomationId";
67+
Items[1].Items[0].Items[0].Title = "Tab 2";
68+
Items[1].Items[0].Items[0].AutomationId = "Tab2AutomationId";
69+
70+
Items[0].FlyoutDisplayOptions = FlyoutDisplayOptions.AsMultipleItems;
71+
Items[1].FlyoutDisplayOptions = FlyoutDisplayOptions.AsMultipleItems;
72+
}
73+
74+
#if UITEST
75+
[Test]
76+
[Category(UITestCategories.Shell)]
77+
public void ShellWithTopTabsFreezesWhenNavigatingFlyoutItems()
78+
{
79+
RunningApp.Tap("FlyoutItem6");
80+
RunningApp.Tap("FlyoutItem0");
81+
for (int i = 0; i < 5; i++)
82+
{
83+
RunningApp.WaitForElement("Tab1AutomationId");
84+
RunningApp.Tap("FlyoutItem0");
85+
RunningApp.Tap("FlyoutItem1");
86+
RunningApp.Tap("FlyoutItem0");
87+
}
88+
89+
RunningApp.WaitForElement("Tab1AutomationId");
90+
RunningApp.Tap("FlyoutItem1");
91+
RunningApp.WaitForElement("Tab2AutomationId");
92+
RunningApp.Tap("FlyoutItem0");
93+
RunningApp.WaitForElement("Tab1AutomationId");
94+
}
95+
#endif
96+
}
97+
}

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
@@ -1444,6 +1444,7 @@
14441444
<Compile Include="$(MSBuildThisFileDirectory)Issue11374.xaml.cs" />
14451445
<Compile Include="$(MSBuildThisFileDirectory)Issue11430.cs" />
14461446
<Compile Include="$(MSBuildThisFileDirectory)Issue11247.cs" />
1447+
<Compile Include="$(MSBuildThisFileDirectory)Issue10608.cs" />
14471448
</ItemGroup>
14481449
<ItemGroup>
14491450
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml">

Xamarin.Forms.Platform.Android/Renderers/ShellSectionRenderer.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ public override AView OnCreateView(LayoutInflater inflater, ViewGroup container,
191191
_tablayout.Visibility = ViewStates.Gone;
192192
}
193193

194+
_tablayout.LayoutChange += OnTabLayoutChange;
195+
194196
_tabLayoutAppearanceTracker = _shellContext.CreateTabLayoutAppearanceTracker(ShellSection);
195197
_toolbarAppearanceTracker = _shellContext.CreateToolbarAppearanceTracker();
196198

@@ -199,6 +201,24 @@ public override AView OnCreateView(LayoutInflater inflater, ViewGroup container,
199201
return _rootView = root;
200202
}
201203

204+
void OnTabLayoutChange(object sender, AView.LayoutChangeEventArgs e)
205+
{
206+
if (_disposed)
207+
return;
208+
209+
var items = SectionController.GetItems();
210+
for (int i = 0; i < _tablayout.TabCount; i++)
211+
{
212+
if (items.Count <= i)
213+
break;
214+
215+
var tab = _tablayout.GetTabAt(i);
216+
217+
if(tab.View != null)
218+
FastRenderers.AutomationPropertiesProvider.AccessibilitySettingsChanged(tab.View, items[i]);
219+
}
220+
}
221+
202222
void Destroy()
203223
{
204224
if (_rootView != null)
@@ -210,7 +230,7 @@ void Destroy()
210230
_viewPager.Adapter = null;
211231
adapter.Dispose();
212232

213-
233+
_tablayout.LayoutChange -= OnTabLayoutChange;
214234
_toolbarAppearanceTracker.Dispose();
215235
_tabLayoutAppearanceTracker.Dispose();
216236
_toolbarTracker.Dispose();
@@ -267,7 +287,6 @@ protected virtual void OnShellItemPropertyChanged(object sender, PropertyChanged
267287
{
268288
var newIndex = SectionController.GetItems().IndexOf(ShellSection.CurrentItem);
269289

270-
271290
if (SectionController.GetItems().Count != _viewPager.ChildCount)
272291
_viewPager.Adapter.NotifyDataSetChanged();
273292

Xamarin.Forms.Platform.iOS/Renderers/PageRenderer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,9 @@ void UpdateUseSafeArea()
396396
if (!IsPartOfShell && !Forms.IsiOS11OrNewer)
397397
return;
398398

399+
if (IsPartOfShell && !_appeared)
400+
return;
401+
399402
var tabThickness = _tabThickness;
400403
if (!_isInItems)
401404
tabThickness = 0;

Xamarin.Forms.Platform.iOS/Renderers/ShellSectionRootHeader.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public override UICollectionViewCell GetCell(UICollectionView collectionView, NS
104104
else
105105
headerCell.Selected = false;
106106

107+
headerCell.SetAccessibilityProperties(shellContent);
107108
return headerCell;
108109
}
109110

0 commit comments

Comments
 (0)