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

[iOS] Fix when removing current last Item on CarouselView #12837

Merged
merged 17 commits into from
Dec 3, 2020
Merged

Conversation

rmarinho
Copy link
Member

Description of Change

When adding test for #12574 I saw that when we are removing the current last item sometimes the scroll to the previous position wasn't happening, this was related to ReloadingVisibleItems that is need when using the Loop feature, so we can update the UI when cell is removed. Adding a small delay will make the collection reload and then set the CollectionView to the correct position

Issues Resolved

API Changes

None

Platforms Affected

  • iOS

Behavioral/Visual Changes

Remove the last item should then show the previous item

Before/After Screenshots

Not applicable

Testing Procedure

Issue12574 should pass on iOS

PR Checklist

  • Targets the correct branch
  • Tests are passing (or failures are unrelated)

@rmarinho rmarinho requested a review from hartez November 18, 2020 13:07
Copy link
Contributor

@jsuarezruiz jsuarezruiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to remove the latest item:

=================================================================
	Managed Stacktrace:
=================================================================
	  at <unknown> <0xffffffff>
	  at ObjCRuntime.Messaging:void_objc_msgSend_IntPtr_IntPtr <0x0010d>
	  at UIKit.UICollectionView:PerformBatchUpdates <0x00432>
	  at Xamarin.Forms.Platform.iOS.ObservableItemsSource:BatchUpdate <0x002d4>
	  at <Remove>d__35:MoveNext <0x00b5a>
	  at System.Runtime.CompilerServices.AsyncTaskMethodBuilder:Start <0x001be>
	  at Xamarin.Forms.Platform.iOS.ObservableItemsSource:Remove <0x00262>
	  at <CollectionChanged>d__31:MoveNext <0x0050a>
	  at System.Runtime.CompilerServices.AsyncTaskMethodBuilder:Start <0x001be>
	  at Xamarin.Forms.Platform.iOS.ObservableItemsSource:CollectionChanged <0x00262>
	  at <CollectionChanged>d__30:MoveNext <0x006b2>
	  at System.Runtime.CompilerServices.AsyncVoidMethodBuilder:Start <0x001be>
	  at Xamarin.Forms.Platform.iOS.ObservableItemsSource:CollectionChanged <0x002e2>
	  at System.Collections.ObjectModel.ObservableCollection`1:OnCollectionChanged <0x000fa>
	  at System.Collections.ObjectModel.ObservableCollection`1:OnCollectionChanged <0x00103>
	  at System.Collections.ObjectModel.ObservableCollection`1:RemoveItem <0x0018a>
	  at System.Collections.ObjectModel.Collection`1:Remove <0x001e8>
	  at Xamarin.Forms.Controls.Issues.ViewModelIssue12574:ExecuteRemoveItemsCommand <0x0012a>
	  at Xamarin.Forms.Controls.Issues.ViewModelIssue12574:<.ctor>b__12_1 <0x00072>
	  at <>c__DisplayClass4_0:<.ctor>b__0 <0x00074>
	  at Xamarin.Forms.Command:Execute <0x0008c>
	  at Xamarin.Forms.ButtonElement:ElementClicked <0x001a7>
	  at Xamarin.Forms.Button:SendClicked <0x0007a>
	  at Xamarin.Forms.Platform.iOS.ButtonElementManager:OnButtonTouchUpInside <0x000ec>
	  at Xamarin.Forms.Platform.iOS.ButtonRenderer:OnButtonTouchUpInside <0x000ba>
	  at UIKit.UIControlEventProxy:Activated <0x000b1>
	  at System.Object:runtime_invoke_void__this__ <0x001a5>
	  at <unknown> <0xffffffff>
	  at UIKit.UIApplication:UIApplicationMain <0x00254>
	  at UIKit.UIApplication:Main <0x000b2>
	  at UIKit.UIApplication:Main <0x00132>
	  at UIKit.UIApplication:Main <0x002aa>
	  at Xamarin.Forms.ControlGallery.iOS.Application:Main <0x0009a>
	  at <Module>:runtime_invoke_void_object <0x001a8>
=================================================================

@rmarinho
Copy link
Member Author

@jsuarezruiz can you give me the steps to reproduce ?

I tried load the issue, and click remove until no items are available
I also tried go to the last item and click remove

@hartez hartez self-assigned this Nov 25, 2020
@hartez hartez removed their request for review December 3, 2020 02:25
Copy link
Contributor

@jsuarezruiz jsuarezruiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

12574

{
public static class IndexPathHelpers
{
public static NSIndexPath[] GenerateIndexPathRange(int section, int startIndex, int count)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add some specific tests to this helper?

public static NSIndexPath[] GenerateLoopedIndexPathRange(int section, int sectionCount, int iterations, int startIndex, int count)
{
var result = new NSIndexPath[iterations * count];
var step = sectionCount / iterations;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interactions could be zero here?

@@ -527,7 +527,14 @@ public override bool ShouldInvalidateLayoutForBoundsChange(CGRect newBounds)
return base.ShouldInvalidateLayoutForBoundsChange(newBounds);
}

UpdateConstraints(CollectionView.AdjustedContentInset.InsetRect(newBounds).Size);
if (Forms.IsiOS11OrNewer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

}
}

async Task CollectionChanged(NotifyCollectionChangedEventArgs args)
void CollectionChanged(NotifyCollectionChangedEventArgs args)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are some issues related to "SIGABRT: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index", I wonder if this change can impact on those issues. We could do a quick review of them after merging this PR.

@rmarinho rmarinho merged commit 2dfbf5f into 5.0.0 Dec 3, 2020
@rmarinho rmarinho deleted the fix-12574test branch December 3, 2020 12:54
@samhouts samhouts added this to the 5.0.0 milestone Dec 8, 2020
pictos pushed a commit to pictos/Xamarin.Forms that referenced this pull request Dec 30, 2020
)

* [iOS] Fix when removing current last Item on CarouselView

* [Uitests] Try fix test for 12574

* [iOS] Fix scroll when removing item on CarouselView

* [iOS] Use CollectionView.PerformBatchUpdates to scroll to item after CollectionView reloads it's items

* [iOS] Set Reload next to Scroll to better understand the logic between the 2

* [iOS] Fix for reload items and wait for iOS12 and iOS11

* Provide pre and post update events for CarouselView to do its bookkeeping

* Remove animation after item removal

* [Controls] Fix sample 12574

* [UITests] Enable test

* Remove performBatchUpdates calls to prevent data disparity;

* Remove async stuff from ObservableGroupedSource

* Fix reload race condition with deletion/insertion of groups

* Reset current item and position when ItemsSource resets

* Update ObservableSource count before invoking Carousel's changed handler;
Reset position/current item on ItemsSource update
Don't update position until drag is released

* Clean up unnecessary ReloadRequired stuff

* Handle UICollectionView internal accounting edge cases

Co-authored-by: E.Z. Hart <hartez@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants