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

Commit

Permalink
Fix semaphore issues updating CollectionView on iOS (#13119) fixes #1…
Browse files Browse the repository at this point in the history
…1853 fixes #12080

* Remove all the semaphore workaround stuff and fix the extra GetCell calls that
were messing up the internal UICollectionView bookkeeping; fixes #11853

* Include the unit test project in the filter

* Prevent adds to uninitialized CollectionViews on iOS

* Pull in initialization fixes from 5.0.0

* Remove scroll requirement for 11224 test
  • Loading branch information
hartez authored Dec 16, 2020
1 parent 43d5751 commit 626f756
Show file tree
Hide file tree
Showing 10 changed files with 333 additions and 171 deletions.
8 changes: 1 addition & 7 deletions .Xamarin.Forms.iOS.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
"solution": {
"path": "Xamarin.Forms.sln",
"projects": [
"EmbeddingTestBeds\\Embedding.XF\\Embedding.XF.csproj",
"EmbeddingTestBeds\\Embedding.iOS\\Embedding.iOS.csproj",
"PagesGallery\\PagesGallery.iOS\\PagesGallery.iOS.csproj",
"PagesGallery\\PagesGallery\\PagesGallery.csproj",
"Stubs\\Xamarin.Forms.Platform.iOS\\Xamarin.Forms.Platform.iOS (Forwarders).csproj",
"XFCorePostProcessor.Tasks\\XFCorePostProcessor.Tasks.csproj",
"Xamarin.Flex\\Xamarin.Flex.shproj",
Expand All @@ -23,12 +19,10 @@
"Xamarin.Forms.Maps\\Xamarin.Forms.Maps.csproj",
"Xamarin.Forms.Material.iOS\\Xamarin.Forms.Material.iOS.csproj",
"Xamarin.Forms.Pages.Azure\\Xamarin.Forms.Pages.Azure.csproj",
"Xamarin.Forms.Pages.UnitTests\\Xamarin.Forms.Pages.UnitTests.csproj",
"Xamarin.Forms.Pages\\Xamarin.Forms.Pages.csproj",
"Xamarin.Forms.Platform.iOS.UnitTests\\Xamarin.Forms.Platform.iOS.UnitTests.csproj",
"Xamarin.Forms.Platform.iOS\\Xamarin.Forms.Platform.iOS.csproj",
"Xamarin.Forms.Platform\\Xamarin.Forms.Platform.csproj",
"Xamarin.Forms.Sandbox.iOS\\Xamarin.Forms.Sandbox.iOS.csproj",
"Xamarin.Forms.Sandbox\\Xamarin.Forms.Sandbox.csproj",
"Xamarin.Forms.Xaml.Design\\Xamarin.Forms.Xaml.Design.csproj",
"Xamarin.Forms.Xaml.UnitTests\\Xamarin.Forms.Xaml.UnitTests.csproj",
"Xamarin.Forms.Xaml\\Xamarin.Forms.Xaml.csproj"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,4 +441,9 @@
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties XamarinHotReloadWrongLinkerErrorInfoBarXamarinFormsControlGalleryiOSHideInfoBar="True" />
</VisualStudio>
</ProjectExtensions>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ public Issue11224()
else
ResultLabel.Text = "The test has failed";
};

carousel.PropertyChanged += (sender, args) => {
if (args.PropertyName == CarouselView.IsVisibleProperty.PropertyName)
{
if (carousel.IsVisible && carousel.Position == 3)
{
ResultLabel.Text = "The test has passed";
}
}
};
#endif
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8" ?>
<controls:TestContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:controls="clr-namespace:Xamarin.Forms.Controls"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Xamarin.Forms.Controls.Issues.Issue11853">
<ContentPage.Content>
<Grid RowDefinitions="Auto,320,*">
<StackLayout BackgroundColor="LightGoldenrodYellow">
<Frame BackgroundColor="#2196F3" Padding="24" CornerRadius="0">
<StackLayout>
<Label Text="Repro CollectionView crash on iOS" HorizontalTextAlignment="Center" TextColor="White" FontSize="36"/>
</StackLayout>
</Frame>
<Button Text="Run" AutomationId="Run" HorizontalOptions="Start" Command="{Binding TestCommand}" />
</StackLayout>

<ScrollView Grid.Row="1">
<CollectionView
HeightRequest="50" IsVisible="{Binding IsListVisible}"
ItemsSource="{Binding Items}">
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout Padding="20,30,20,0">
<Label Text="{Binding Text}" TextColor="DeepPink" FontSize="Body"/>
<BoxView HeightRequest="1" BackgroundColor="LightPink" Margin="0,30,0,0" />
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</ScrollView>

</Grid>
</ContentPage.Content>
</controls:TestContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using System.Threading.Tasks;
using Xamarin.Forms.Xaml;
using System.ComponentModel;
using System.Linq;
using System.Windows.Input;

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

namespace Xamarin.Forms.Controls.Issues
{
[Issue(IssueTracker.Github, 11853, "[Bug][iOS] Concurrent issue leading to crash in SemaphoreSlim.Release in ObservableItemsSource",
PlatformAffected.iOS)]
#if UITEST
[NUnit.Framework.Category(UITestCategories.CollectionView)]
#endif
public partial class Issue11853 : TestContentPage
{
const string Run = "Run";

protected override void Init() { }

public Issue11853()
{
#if APP
InitializeComponent();
#endif
BindingContext = new _11853ViewModel();
}

#if UITEST
[Test]
public void JustWhalingAwayOnTheCollectionViewWithAddsAndClearsShouldNotCrash()
{
RunningApp.WaitForElement(Run);
RunningApp.Tap(Run);
Task.Delay(5000).Wait();
RunningApp.Tap(Run);
Task.Delay(5000).Wait();

// If we can still find the button, then we didn't crash
RunningApp.WaitForElement(Run);
}
#endif

public class _11853Item
{
public string Text { get; set; }
}

public class _11853ViewModel : INotifyPropertyChanged
{
private bool isListVisible;
public event PropertyChangedEventHandler PropertyChanged;

public bool IsListVisible
{
get => isListVisible;
set
{
isListVisible = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsListVisible)));
}
}

public ObservableCollection<_11853Item> Items { get; }
public ICommand TestCommand { get; }

public _11853ViewModel()
{
Items = new ObservableCollection<_11853Item>();
TestCommand = new Command(async () =>
{
var items = CreateItems(10, 0).ToList().First();
var items2 = CreateItems(10, 0).ToList().Skip(1).First();
int iterations = 1000; //10000;
for (var i = 0; i < iterations; i++)
{
await Task.Delay(1);
Items.Add(items);
await Task.Delay(2);
Items.Add(items2);
await Task.Delay(2);
Items.Clear();
await Task.Delay(2);
Items.Add(items);
Items.Add(items2);
await Task.Delay(2);
}
});
}

IEnumerable<_11853Item> CreateItems(int count, int batch)
{
var i = 0;
while (count-- > 0)
yield return new _11853Item { Text = $"Item {i++} Batch {batch}" };
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)CollectionViewGroupTypeIssue.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11853.xaml.cs">
<DependentUpon>Issue11853.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue12153.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue10324.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Github9536.xaml.cs">
Expand Down Expand Up @@ -2265,4 +2269,10 @@
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue11853.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
</Project>
Loading

0 comments on commit 626f756

Please sign in to comment.