[listview] fixes for various null/empty DataTemplate#13146
Merged
rmarinho merged 2 commits intodotnet:mainfrom Feb 7, 2023
Merged
[listview] fixes for various null/empty DataTemplate#13146rmarinho merged 2 commits intodotnet:mainfrom
rmarinho merged 2 commits intodotnet:mainfrom
Conversation
Fixes: dotnet#11203 The following breaks XAML Hot Reload: 1. Setup a working `ListView` and `DataTemplate` 2. Delete the `DataTemplate`'s body (as if I'm about to type a completely new view there). 3. Trigger a XAML Hot Reload. This can happen automatically if you just pause typing. 4. MAUI crashes at runtime: in Android.Views.ViewGroup.Layout at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.Views.ViewGroup.cs:3369,5 in Microsoft.Maui.Controls.Handlers.Compatibility.VisualElementRenderer<Microsoft.Maui.Controls.ListView>.OnLayout at D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Android\VisualElementRenderer.cs:54,6 in Microsoft.Maui.Controls.Handlers.Compatibility.ListViewRenderer.OnLayout at D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\ListView\Android\ListViewRenderer.cs:298,4 You can also create this problem in C#, like I did in a unit test: listView.ItemTemplate = new DataTemplate(() => /* valid template */); listView.ItemTemplate = new DataTemplate(); // broken listView.ItemTemplate = new DataTemplate(() => null); //broken I could also get a slightly different crash: System.InvalidCastException: Specified cast is not valid. at Microsoft.Maui.Controls.Internals.TemplatedItemsList`2[[Microsoft.Maui.Controls.ItemsView`1[[Microsoft.Maui.Controls.Cell, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Controls.Cell, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].ActivateContent(Int32 index, Object item) The "invalid cast" appears to be due to the changes in c57858f. It returns a `new Label()` in some cases, which does not work with a `ListView`. You need a `Cell` instead of `View` in that case. The fixes appear to be in two places: * `VisualElementRenderer.OnLayout`: use `is`, also simplifies the code * `TemplatedItemsList.ActivateContent` : use `is` and call the default data template. Now my tests pass, and I can't reproduce the issue in XAML Hot Reload either!
mandel-macaque
approved these changes
Feb 6, 2023
Contributor
mandel-macaque
left a comment
There was a problem hiding this comment.
Looks good, maybe invert the if (I'm not a UI developer)
jsuarezruiz
approved these changes
Feb 7, 2023
rmarinho
requested changes
Feb 7, 2023
Member
rmarinho
left a comment
There was a problem hiding this comment.
Failing test on iOS
NavigatingBackViaBackButtonFiresNavigatedEvent
Member
Author
Member
@jonathanpeppers CI merges main before running tests. It looks like main broke with one of the merges from yesterday. Taking a look now |
Member
Author
|
@rmarinho so maybe we can merge this one? It seems like it should be an improvement, adding |
Contributor
rmarinho
approved these changes
Feb 7, 2023
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Change
Fixes #11203
The following breaks XAML Hot Reload:
Setup a working
ListViewandDataTemplateDelete the
DataTemplate's body (as if I'm about to type a completely new view there).Trigger a XAML Hot Reload. This can happen automatically if you just pause typing.
MAUI crashes at runtime:
You can also create this problem in C#, like I did in a unit test:
I could also get a slightly different crash:
The "invalid cast" appears to be due to the changes in c57858f. It returns a
new Label()in some cases, which does not work with aListView. You need aCellinstead ofViewin that case.The fixes appear to be in two places:
VisualElementRenderer.OnLayout: useis, also simplifies the codeTemplatedItemsList.ActivateContent: useisand call the default data template.Now my tests pass, and I can't reproduce the issue in XAML Hot Reload either!
Manually testing, I'm able to alternative commenting out the two XAML elements:
This didn't work before.
Issues Fixed
Fixes: #11203