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

Commit 626f756

Browse files
authored
Fix semaphore issues updating CollectionView on iOS (#13119) fixes #11853 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
1 parent 43d5751 commit 626f756

File tree

10 files changed

+333
-171
lines changed

10 files changed

+333
-171
lines changed

.Xamarin.Forms.iOS.slnf

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
"solution": {
33
"path": "Xamarin.Forms.sln",
44
"projects": [
5-
"EmbeddingTestBeds\\Embedding.XF\\Embedding.XF.csproj",
6-
"EmbeddingTestBeds\\Embedding.iOS\\Embedding.iOS.csproj",
7-
"PagesGallery\\PagesGallery.iOS\\PagesGallery.iOS.csproj",
8-
"PagesGallery\\PagesGallery\\PagesGallery.csproj",
95
"Stubs\\Xamarin.Forms.Platform.iOS\\Xamarin.Forms.Platform.iOS (Forwarders).csproj",
106
"XFCorePostProcessor.Tasks\\XFCorePostProcessor.Tasks.csproj",
117
"Xamarin.Flex\\Xamarin.Flex.shproj",
@@ -23,12 +19,10 @@
2319
"Xamarin.Forms.Maps\\Xamarin.Forms.Maps.csproj",
2420
"Xamarin.Forms.Material.iOS\\Xamarin.Forms.Material.iOS.csproj",
2521
"Xamarin.Forms.Pages.Azure\\Xamarin.Forms.Pages.Azure.csproj",
26-
"Xamarin.Forms.Pages.UnitTests\\Xamarin.Forms.Pages.UnitTests.csproj",
2722
"Xamarin.Forms.Pages\\Xamarin.Forms.Pages.csproj",
23+
"Xamarin.Forms.Platform.iOS.UnitTests\\Xamarin.Forms.Platform.iOS.UnitTests.csproj",
2824
"Xamarin.Forms.Platform.iOS\\Xamarin.Forms.Platform.iOS.csproj",
2925
"Xamarin.Forms.Platform\\Xamarin.Forms.Platform.csproj",
30-
"Xamarin.Forms.Sandbox.iOS\\Xamarin.Forms.Sandbox.iOS.csproj",
31-
"Xamarin.Forms.Sandbox\\Xamarin.Forms.Sandbox.csproj",
3226
"Xamarin.Forms.Xaml.Design\\Xamarin.Forms.Xaml.Design.csproj",
3327
"Xamarin.Forms.Xaml.UnitTests\\Xamarin.Forms.Xaml.UnitTests.csproj",
3428
"Xamarin.Forms.Xaml\\Xamarin.Forms.Xaml.csproj"

Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,4 +441,9 @@
441441
</ItemGroup>
442442
<ItemGroup />
443443
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
444+
<ProjectExtensions>
445+
<VisualStudio>
446+
<UserProperties XamarinHotReloadWrongLinkerErrorInfoBarXamarinFormsControlGalleryiOSHideInfoBar="True" />
447+
</VisualStudio>
448+
</ProjectExtensions>
444449
</Project>

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue11224.xaml.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ public Issue11224()
3535
else
3636
ResultLabel.Text = "The test has failed";
3737
};
38+
39+
carousel.PropertyChanged += (sender, args) => {
40+
if (args.PropertyName == CarouselView.IsVisibleProperty.PropertyName)
41+
{
42+
if (carousel.IsVisible && carousel.Position == 3)
43+
{
44+
ResultLabel.Text = "The test has passed";
45+
}
46+
}
47+
};
3848
#endif
3949
}
4050

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<controls:TestContentPage xmlns="http://xamarin.com/schemas/2014/forms"
3+
xmlns:controls="clr-namespace:Xamarin.Forms.Controls"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
5+
x:Class="Xamarin.Forms.Controls.Issues.Issue11853">
6+
<ContentPage.Content>
7+
<Grid RowDefinitions="Auto,320,*">
8+
<StackLayout BackgroundColor="LightGoldenrodYellow">
9+
<Frame BackgroundColor="#2196F3" Padding="24" CornerRadius="0">
10+
<StackLayout>
11+
<Label Text="Repro CollectionView crash on iOS" HorizontalTextAlignment="Center" TextColor="White" FontSize="36"/>
12+
</StackLayout>
13+
</Frame>
14+
<Button Text="Run" AutomationId="Run" HorizontalOptions="Start" Command="{Binding TestCommand}" />
15+
</StackLayout>
16+
17+
<ScrollView Grid.Row="1">
18+
<CollectionView
19+
HeightRequest="50" IsVisible="{Binding IsListVisible}"
20+
ItemsSource="{Binding Items}">
21+
<CollectionView.ItemTemplate>
22+
<DataTemplate>
23+
<StackLayout Padding="20,30,20,0">
24+
<Label Text="{Binding Text}" TextColor="DeepPink" FontSize="Body"/>
25+
<BoxView HeightRequest="1" BackgroundColor="LightPink" Margin="0,30,0,0" />
26+
</StackLayout>
27+
</DataTemplate>
28+
</CollectionView.ItemTemplate>
29+
</CollectionView>
30+
</ScrollView>
31+
32+
</Grid>
33+
</ContentPage.Content>
34+
</controls:TestContentPage>
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
4+
using System.Text;
5+
using Xamarin.Forms.CustomAttributes;
6+
using Xamarin.Forms.Internals;
7+
using System.Threading.Tasks;
8+
using Xamarin.Forms.Xaml;
9+
using System.ComponentModel;
10+
using System.Linq;
11+
using System.Windows.Input;
12+
13+
#if UITEST
14+
using Xamarin.UITest;
15+
using NUnit.Framework;
16+
using Xamarin.Forms.Core.UITests;
17+
#endif
18+
19+
namespace Xamarin.Forms.Controls.Issues
20+
{
21+
[Issue(IssueTracker.Github, 11853, "[Bug][iOS] Concurrent issue leading to crash in SemaphoreSlim.Release in ObservableItemsSource",
22+
PlatformAffected.iOS)]
23+
#if UITEST
24+
[NUnit.Framework.Category(UITestCategories.CollectionView)]
25+
#endif
26+
public partial class Issue11853 : TestContentPage
27+
{
28+
const string Run = "Run";
29+
30+
protected override void Init() { }
31+
32+
public Issue11853()
33+
{
34+
#if APP
35+
InitializeComponent();
36+
#endif
37+
BindingContext = new _11853ViewModel();
38+
}
39+
40+
#if UITEST
41+
[Test]
42+
public void JustWhalingAwayOnTheCollectionViewWithAddsAndClearsShouldNotCrash()
43+
{
44+
RunningApp.WaitForElement(Run);
45+
RunningApp.Tap(Run);
46+
Task.Delay(5000).Wait();
47+
RunningApp.Tap(Run);
48+
Task.Delay(5000).Wait();
49+
50+
// If we can still find the button, then we didn't crash
51+
RunningApp.WaitForElement(Run);
52+
}
53+
#endif
54+
55+
public class _11853Item
56+
{
57+
public string Text { get; set; }
58+
}
59+
60+
public class _11853ViewModel : INotifyPropertyChanged
61+
{
62+
private bool isListVisible;
63+
public event PropertyChangedEventHandler PropertyChanged;
64+
65+
public bool IsListVisible
66+
{
67+
get => isListVisible;
68+
set
69+
{
70+
isListVisible = value;
71+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsListVisible)));
72+
}
73+
}
74+
75+
public ObservableCollection<_11853Item> Items { get; }
76+
public ICommand TestCommand { get; }
77+
78+
public _11853ViewModel()
79+
{
80+
Items = new ObservableCollection<_11853Item>();
81+
TestCommand = new Command(async () =>
82+
{
83+
var items = CreateItems(10, 0).ToList().First();
84+
var items2 = CreateItems(10, 0).ToList().Skip(1).First();
85+
86+
int iterations = 1000; //10000;
87+
88+
for (var i = 0; i < iterations; i++)
89+
{
90+
await Task.Delay(1);
91+
Items.Add(items);
92+
93+
await Task.Delay(2);
94+
Items.Add(items2);
95+
await Task.Delay(2);
96+
97+
Items.Clear();
98+
await Task.Delay(2);
99+
100+
Items.Add(items);
101+
Items.Add(items2);
102+
await Task.Delay(2);
103+
}
104+
105+
});
106+
}
107+
108+
IEnumerable<_11853Item> CreateItems(int count, int batch)
109+
{
110+
var i = 0;
111+
while (count-- > 0)
112+
yield return new _11853Item { Text = $"Item {i++} Batch {batch}" };
113+
}
114+
}
115+
}
116+
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
</PropertyGroup>
1111
<ItemGroup>
1212
<Compile Include="$(MSBuildThisFileDirectory)CollectionViewGroupTypeIssue.cs" />
13+
<Compile Include="$(MSBuildThisFileDirectory)Issue11853.xaml.cs">
14+
<DependentUpon>Issue11853.xaml</DependentUpon>
15+
<SubType>Code</SubType>
16+
</Compile>
1317
<Compile Include="$(MSBuildThisFileDirectory)Issue12153.cs" />
1418
<Compile Include="$(MSBuildThisFileDirectory)Issue10324.cs" />
1519
<Compile Include="$(MSBuildThisFileDirectory)Github9536.xaml.cs">
@@ -2265,4 +2269,10 @@
22652269
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
22662270
</EmbeddedResource>
22672271
</ItemGroup>
2272+
<ItemGroup>
2273+
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue11853.xaml">
2274+
<SubType>Designer</SubType>
2275+
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
2276+
</EmbeddedResource>
2277+
</ItemGroup>
22682278
</Project>

0 commit comments

Comments
 (0)