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

Commit

Permalink
Don't update page offset if not visible (#11602)
Browse files Browse the repository at this point in the history
fixes #10608
  • Loading branch information
PureWeen committed Aug 4, 2020
1 parent 9355d6b commit b38d590
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using System.Threading.Tasks;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

#if UITEST
using Xamarin.Forms.Core.UITests;
using Xamarin.UITest;
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[Category(UITestCategories.Shell)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 10608, "[Bug] [Shell] [iOS] Locked flyout causes application to freezes when quickly switching between tabs", PlatformAffected.iOS)]
public class Issue10608 : TestShell
{
public Issue10608()
{
}

protected override void Init()
{
FlyoutBehavior = FlyoutBehavior.Locked;

AddFlyoutItem("Click");
AddFlyoutItem("Between");
AddFlyoutItem("These Flyouts");
AddFlyoutItem("Really Fast");
AddFlyoutItem("If it doesn't");
AddFlyoutItem("Lock test has passed");

int i = 0;
foreach(var item in Items)
{
item.Items[0].AutomationId = $"FlyoutItem{i}";
item.Items[0].Items.Add(new ContentPage()
{
Title = "Page"
});

i++;
}

Items.Add(new MenuItem()
{
Text = "Let me click for you",
AutomationId = $"FlyoutItem{i}",
Command = new Command(async () =>
{
for (int j = 0; j < 5; j++)
{
CurrentItem = Items[0].Items[0];
await Task.Delay(10);
CurrentItem = Items[1].Items[0];
await Task.Delay(10);
}
CurrentItem = Items[0].Items[0];
})
});

Items[0].Items[0].Items[0].Title = "Tab 1";
Items[0].Items[0].Items[0].AutomationId = "Tab1AutomationId";
Items[1].Items[0].Items[0].Title = "Tab 2";
Items[1].Items[0].Items[0].AutomationId = "Tab2AutomationId";

Items[0].FlyoutDisplayOptions = FlyoutDisplayOptions.AsMultipleItems;
Items[1].FlyoutDisplayOptions = FlyoutDisplayOptions.AsMultipleItems;
}

#if UITEST
[Test]
[Category(UITestCategories.Shell)]
public void ShellWithTopTabsFreezesWhenNavigatingFlyoutItems()
{
RunningApp.Tap("FlyoutItem6");
RunningApp.Tap("FlyoutItem0");
for (int i = 0; i < 5; i++)
{
RunningApp.WaitForElement("Tab1AutomationId");
RunningApp.Tap("FlyoutItem0");
RunningApp.Tap("FlyoutItem1");
RunningApp.Tap("FlyoutItem0");
}

RunningApp.WaitForElement("Tab1AutomationId");
RunningApp.Tap("FlyoutItem1");
RunningApp.WaitForElement("Tab2AutomationId");
RunningApp.Tap("FlyoutItem0");
RunningApp.WaitForElement("Tab1AutomationId");
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue11374.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11430.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11247.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue10608.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml">
Expand Down
23 changes: 21 additions & 2 deletions Xamarin.Forms.Platform.Android/Renderers/ShellSectionRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ public override AView OnCreateView(LayoutInflater inflater, ViewGroup container,
_tablayout.Visibility = ViewStates.Gone;
}

_tablayout.LayoutChange += OnTabLayoutChange;

_tabLayoutAppearanceTracker = _shellContext.CreateTabLayoutAppearanceTracker(ShellSection);
_toolbarAppearanceTracker = _shellContext.CreateToolbarAppearanceTracker();

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

void OnTabLayoutChange(object sender, AView.LayoutChangeEventArgs e)
{
if (_disposed)
return;

var items = SectionController.GetItems();
for (int i = 0; i < _tablayout.TabCount; i++)
{
if (items.Count <= i)
break;

var tab = _tablayout.GetTabAt(i);

if(tab.View != null)
FastRenderers.AutomationPropertiesProvider.AccessibilitySettingsChanged(tab.View, items[i]);
}
}

void Destroy()
{
if (_rootView != null)
Expand All @@ -210,7 +230,7 @@ void Destroy()
_viewPager.Adapter = null;
adapter.Dispose();


_tablayout.LayoutChange -= OnTabLayoutChange;
_toolbarAppearanceTracker.Dispose();
_tabLayoutAppearanceTracker.Dispose();
_toolbarTracker.Dispose();
Expand Down Expand Up @@ -267,7 +287,6 @@ protected virtual void OnShellItemPropertyChanged(object sender, PropertyChanged
{
var newIndex = SectionController.GetItems().IndexOf(ShellSection.CurrentItem);


if (SectionController.GetItems().Count != _viewPager.ChildCount)
_viewPager.Adapter.NotifyDataSetChanged();

Expand Down
3 changes: 3 additions & 0 deletions Xamarin.Forms.Platform.iOS/Renderers/PageRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,9 @@ void UpdateUseSafeArea()
if (!IsPartOfShell && !Forms.IsiOS11OrNewer)
return;

if (IsPartOfShell && !_appeared)
return;

var tabThickness = _tabThickness;
if (!_isInItems)
tabThickness = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public override UICollectionViewCell GetCell(UICollectionView collectionView, NS
else
headerCell.Selected = false;

headerCell.SetAccessibilityProperties(shellContent);
return headerCell;
}

Expand Down

0 comments on commit b38d590

Please sign in to comment.