Skip to content

Commit b4035d7

Browse files
authored
[release/9.0.1xx-rc2] Fix collectionview tests rc2 (#25045)
* [testing] Enable test again * [testing] Enable CollectionViewHandler2 on UITests * Try new changes * try new fix * [iOS] Dont call InitialUpdatePosition on attach, wait for LayoutSubViews * Try update when navigating back * Try this * Add missing usings * Try this * Fix more stuff * Fix test on mac * Try again * Ignore tests on windows and android * Use the ItemsView position on compare * Try this * Fix * Cleanup * Fix test naming * Cleanup * try skip android install on public bots * Update device-tests-steps.yml * Use our bots
1 parent 632fca6 commit b4035d7

18 files changed

+307
-156
lines changed

Diff for: eng/pipelines/common/device-tests-steps.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ steps:
3131
platform: macos
3232
skipXcode: ${{ or(eq(parameters.platform, 'android'), eq(parameters.platform, 'windows')) }}
3333
skipProvisioning: ${{ eq(parameters.platform, 'windows') }}
34-
skipAndroidImages : ${{ eq(parameters.platform, 'ios') }}
35-
skipAndroidSdks: ${{ eq(parameters.platform, 'ios') }}
34+
skipAndroidImages : ${{ or(eq(parameters.platform, 'ios'), eq(parameters.platform, 'catalyst')) }}
35+
skipAndroidSdks: ${{ or(eq(parameters.platform, 'ios'), eq(parameters.platform, 'catalyst')) }}
3636
provisionatorChannel: ${{ parameters.provisionatorChannel }}
3737

3838
- pwsh: ./build.ps1 --target=dotnet --configuration="Release" --verbosity=diagnostic

Diff for: eng/pipelines/device-tests.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,17 @@ parameters:
7272
- name: iosPool
7373
type: object
7474
default:
75-
name: $(iosTestsVmPool)
76-
vmImage: $(iosTestsVmImage)
75+
name: $(androidTestsVmPool)
76+
vmImage: $(androidTestsVmImage)
7777
demands:
7878
- macOS.Name -equals Sonoma
7979
- macOS.Architecture -equals x64
80-
80+
8181
- name: catalystPool
8282
type: object
8383
default:
84-
name: $(iosTestsVmPool)
85-
vmImage: $(iosTestsVmImage)
84+
name: $(androidTestsVmPool)
85+
vmImage: $(androidTestsVmImage)
8686
demands:
8787
- macOS.Name -equals Sonoma
8888
- macOS.Architecture -equals x64

Diff for: src/Controls/src/Core/Handlers/Items/iOS/ObservableItemsSource.cs

+22-3
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,29 @@ protected virtual NSIndexPath[] CreateIndexesFrom(int startIndex, int count)
178178
return IndexPathHelpers.GenerateIndexPathRange(_section, startIndex, count);
179179
}
180180

181+
private protected virtual bool ShouldReload(NotifyCollectionChangedEventArgs args)
182+
{
183+
if (args.Action == NotifyCollectionChangedAction.Remove)
184+
{
185+
// INCC implementation isn't giving us enough information to know where the removed items were in the
186+
// collection. So the best we can do is a ReloadData()
187+
var startIndex = args.OldStartingIndex;
188+
if (startIndex < 0)
189+
{
190+
return true;
191+
}
192+
}
193+
return false;
194+
}
195+
181196
void Add(NotifyCollectionChangedEventArgs args)
182197
{
198+
if (ShouldReload(args))
199+
{
200+
Reload();
201+
return;
202+
}
203+
183204
var count = args.NewItems.Count;
184205
Count += count;
185206
var startIndex = args.NewStartingIndex > -1 ? args.NewStartingIndex : IndexOf(args.NewItems[0]);
@@ -192,10 +213,8 @@ void Remove(NotifyCollectionChangedEventArgs args)
192213
{
193214
var startIndex = args.OldStartingIndex;
194215

195-
if (startIndex < 0)
216+
if (ShouldReload(args))
196217
{
197-
// INCC implementation isn't giving us enough information to know where the removed items were in the
198-
// collection. So the best we can do is a ReloadData()
199218
Reload();
200219
return;
201220
}

Diff for: src/Controls/src/Core/Handlers/Items2/CarouselViewHandler2.iOS.cs

+45-31
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ protected override UICollectionViewLayout SelectLayout()
4949

5050
var layout = new UICollectionViewCompositionalLayout((sectionIndex, environment) =>
5151
{
52+
if (VirtualView is null)
53+
{
54+
return null;
55+
}
5256
double sectionMargin = 0.0;
5357
if (!IsHorizontal)
5458
{
@@ -77,57 +81,67 @@ protected override UICollectionViewLayout SelectLayout()
7781
var group = IsHorizontal ? NSCollectionLayoutGroup.GetHorizontalGroup(groupSize, item, 1) :
7882
NSCollectionLayoutGroup.GetVerticalGroup(groupSize, item, 1);
7983

80-
int currentPosition = 0;
81-
8284
// Create our section layout
8385
var section = NSCollectionLayoutSection.Create(group: group);
8486
section.InterGroupSpacing = itemSpacing;
8587
section.OrthogonalScrollingBehavior = UICollectionLayoutSectionOrthogonalScrollingBehavior.GroupPagingCentered;
8688
section.VisibleItemsInvalidationHandler = (items, offset, env) =>
8789
{
90+
//This will allow us to SetPosition when we are scrolling the items
91+
//based on the current page
8892
var page = (offset.X + sectionMargin) / env.Container.ContentSize.Width;
8993

90-
// Check if we are at the beginning or end of the page
91-
if (Math.Abs(page % 1) <= (double.Epsilon * 100) && Controller.ItemsSource.ItemCount > 0)
94+
// Check if we not are at the beginning or end of the page and if we have items
95+
if (Math.Abs(page % 1) > (double.Epsilon * 100) || Controller.ItemsSource.ItemCount <= 0)
9296
{
93-
var pageIndex = (int)page;
97+
return;
98+
}
99+
100+
var pageIndex = (int)page;
101+
var carouselPosition = pageIndex;
102+
103+
var cv2Controller = (CarouselViewController2)Controller;
94104

95-
if (ItemsView.Loop)
105+
//If we are looping, we need to get the correct position
106+
if (ItemsView.Loop)
107+
{
108+
var maxIndex = (Controller.ItemsSource as ILoopItemsViewSource).LoopCount - 1;
109+
110+
//To mimic looping, we needed to modify the ItemSource and inserted a new item at the beginning and at the end
111+
if (pageIndex == maxIndex)
96112
{
97-
var maxIndex = (Controller.ItemsSource as Items.ILoopItemsViewSource).LoopCount - 1;
113+
//When at last item, we need to change to 2nd item, so we can scroll right or left
114+
pageIndex = 1;
115+
}
116+
else if (pageIndex == 0)
117+
{
118+
//When at first item, need to change to one before last, so we can scroll right or left
119+
pageIndex = maxIndex - 1;
120+
}
98121

99-
//To mimic looping, we needed to modify the ItemSource and inserted a new item at the beginning and at the end
100-
if (pageIndex == maxIndex)
101-
{
102-
//When at last item, we need to change to 2nd item, so we can scroll right or left
103-
pageIndex = 1;
104-
}
105-
else if (pageIndex == 0)
122+
//since we added one item at the beginning of our ItemSource, we need to subtract one
123+
carouselPosition = pageIndex - 1;
124+
125+
if (ItemsView.Position != carouselPosition)
126+
{
127+
//If we are updating the ItemsSource, we don't want to scroll the CollectionView
128+
if (cv2Controller.IsUpdating())
106129
{
107-
//When at first item, need to change to one before last, so we can scroll right or left
108-
pageIndex = maxIndex - 1;
130+
return;
109131
}
110132

111-
//since we added one item at the beginning, we need to subtract one
112-
var realPage = pageIndex - 1;
133+
var goToIndexPath = cv2Controller.GetScrollToIndexPath(carouselPosition);
113134

114-
if (currentPosition != realPage)
115-
{
116-
currentPosition = realPage;
117-
var pageNumberIndex = NSIndexPath.FromRowSection(pageIndex, 0);
118-
Controller.CollectionView.ScrollToItem(pageNumberIndex, UICollectionViewScrollPosition.Left, false);
135+
//This will move the carousel to fake the loop
136+
Controller.CollectionView.ScrollToItem(NSIndexPath.FromItemSection(pageIndex, 0), UICollectionViewScrollPosition.Left, false);
119137

120-
//Update the CarouselView position
121-
(Controller as CarouselViewController2)?.SetPosition(realPage);
122-
}
123-
}
124-
else
125-
{
126-
(Controller as CarouselViewController2)?.SetPosition((int)page);
127138
}
128139
}
129-
};
140+
141+
//Update the CarouselView position
142+
cv2Controller?.SetPosition(carouselPosition);
130143

144+
};
131145
return section;
132146
});
133147

Diff for: src/Controls/src/Core/Handlers/Items2/ItemsViewHandler2.iOS.cs

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public ItemsViewHandler2(PropertyMapper mapper = null) : base(mapper ?? ItemsVie
4040
protected override void DisconnectHandler(UIView platformView)
4141
{
4242
ItemsView.ScrollToRequested -= ScrollToRequested;
43+
_layout = null;
44+
Controller?.DisposeItemsSource();
4345
base.DisconnectHandler(platformView);
4446
}
4547

0 commit comments

Comments
 (0)