maui icon indicating copy to clipboard operation
maui copied to clipboard

[Android] CarouselView: Remove rounding from SizedItemContentView that results in off-by-one pixel error

Open filipnavara opened this issue 1 year ago • 7 comments

Description of Change

CarouselViewHandler on Android has a measurement logic that converts back and forth between sizes in different units (Context.FromPixels/Context.ToPixels). The logic in SizedItemContentView was inadvertently rounding the values, resulting in some size measurement having an off-by-one width on certain devices and emulators (eg. 1079 instead of 1080). This in turn resulted in the carousel being scrolled to incorrect item on re-measurement triggered from closing a modal page.

Before: carousel-before

After: carousel-after

Issues Fixed

filipnavara avatar Oct 21 '24 10:10 filipnavara

/azp run

rmarinho avatar Oct 21 '24 22:10 rmarinho

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Oct 21 '24 22:10 azure-pipelines[bot]

The AddItemsToCarouselViewWorks UITest is failing on Android.

I am not surprised it fails. I'm surprised it ever worked...

The item is added, which triggers MauiCarouselRecyclerView.CollectionItemsSourceChanged. This schedules the following code block to the dispatcher: https://github.com/dotnet/maui/blob/c21b5184d1894426ece6bd8a298d1aea7f0bb468/src/Controls/src/Core/Handlers/Items/Android/MauiCarouselRecyclerView.cs#L270-L288

Next, TestCarouselView.ScrollTo(5, animate: false); correctly scrolls the carousel to 5th item... ... which is then reset back by the dispatched code above.

Removing the delayed dispatch fixes this particular test. ~~I'm not sure what was it supposed to handle.~~ Unfortunately, this breaks this part of the logic: https://github.com/dotnet/maui/blob/c21b5184d1894426ece6bd8a298d1aea7f0bb468/src/Controls/src/Core/Handlers/Items/Android/MauiCarouselRecyclerView.cs#L263

filipnavara avatar Oct 23 '24 10:10 filipnavara

I made a pragmatic change that should fix the test.

filipnavara avatar Oct 23 '24 10:10 filipnavara

/azp run

rmarinho avatar Oct 25 '24 21:10 rmarinho

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Oct 25 '24 21:10 azure-pipelines[bot]

Seems like there was a lot of timeouts ... and a diff for the test above, which actually shows the fixed size: image

filipnavara avatar Oct 26 '24 16:10 filipnavara

Was there a specific reason why this got closed?

filipnavara avatar Jan 14 '25 12:01 filipnavara

@filipnavara sorry it was my fault I screwed up the force push I think . Can you reopen with your local copy ? Thanks

rmarinho avatar Jan 14 '25 12:01 rmarinho

@filipnavara sorry it was my fault I screwed up the force push I think . Can you reopen with your local copy ? Thanks

Gotcha. I'll reopen and force push a rebased version.

filipnavara avatar Jan 14 '25 12:01 filipnavara

We need to update images tests for CarouselView

rmarinho avatar Jan 15 '25 14:01 rmarinho

I wonder if this is still an issue after

PureWeen avatar Feb 10 '25 21:02 PureWeen

I wonder if this is still an issue after

The two PRs fixed unrelated issues even if they touched on the same topic.

filipnavara avatar Feb 10 '25 22:02 filipnavara

/azp run

rmarinho avatar Mar 06 '25 13:03 rmarinho

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Mar 06 '25 13:03 azure-pipelines[bot]

Needs to be update this screenshot on android for CarouselViewShouldRenderCorrectly

CarouselViewShouldRenderCorrectly

rmarinho avatar Mar 07 '25 01:03 rmarinho

Needs to be update this screenshot on android for CarouselViewShouldRenderCorrectly

Yeah, there was a conflict for this one after the last merge. :-/ I updated it.

filipnavara avatar Mar 07 '25 01:03 filipnavara

/azp run

rmarinho avatar Mar 07 '25 10:03 rmarinho

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Mar 07 '25 10:03 azure-pipelines[bot]

Is it possible to rebase and also add a UI test that replicates the issue?

I can rebase it but it will likely fail the UI tests again because of the changed baseline and the images will need to be updated. Frankly, it's becoming quite cumbersome doing this for several months now.

Replicating the issue with wrong scrolling may be a bit tricky. Replicating the wrong rounding resulting in wrongly sized items is already covered by existing tests.

filipnavara avatar Mar 12 '25 12:03 filipnavara

/azp run

rmarinho avatar Mar 18 '25 16:03 rmarinho

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Mar 18 '25 16:03 azure-pipelines[bot]

/azp run

rmarinho avatar Mar 20 '25 11:03 rmarinho

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Mar 20 '25 11:03 azure-pipelines[bot]

/azp run MAUI-DeviceTests-public

rmarinho avatar Mar 20 '25 12:03 rmarinho

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Mar 20 '25 12:03 azure-pipelines[bot]

/azp run MAUI-public

rmarinho avatar Mar 20 '25 12:03 rmarinho

/azp run MAUI-UITests-public

rmarinho avatar Mar 20 '25 12:03 rmarinho

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Mar 20 '25 12:03 azure-pipelines[bot]

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Mar 20 '25 12:03 azure-pipelines[bot]