-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CollectionView with EmptyView and EmptyViewTemplate for Data template selector throws an exception #25418
Conversation
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
/rebase |
5f86a88
to
c20e876
Compare
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
/rebase |
c20e876
to
e8c0a38
Compare
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
/rebase |
de94bea
to
d95cb8d
Compare
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
@@ -567,7 +567,7 @@ protected virtual void HandleFormsElementMeasureInvalidated(VisualElement formsE | |||
internal void UpdateView(object view, DataTemplate viewTemplate, ref UIView uiView, ref VisualElement formsElement) | |||
{ | |||
// Is view set on the ItemsView? | |||
if (view is null && viewTemplate is null) | |||
if (view is null && (viewTemplate is null || viewTemplate is DataTemplateSelector)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the PR description:
"The exception occurred because the RealizeView method in the ItemsViewController file was attempting to create and render a view when both EmptyView and EmptyViewTemplate were defined in the CollectionView, with a DataTemplateSelector for the EmptyViewTemplate. The original code did not account for the scenario where the viewTemplate was a DataTemplateSelector."
In the case of using a DataTemplateSelector, here
viewTemplate = viewTemplate.SelectDataTemplate(view, itemsView); |
should select the correct template, and then get the content to create the handler and the PlatformView.
Is the SelectTemplate method returning null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsuarezruiz ,
In this case, the SelectTemplate method itself isn't returning null. Instead, the exception occurs immediately afterward, when the selected viewTemplate is used in CreateContent. This happens because, on the initial render, there's no template available to select, resulting in viewTemplate being null. This leads to an exception when CreateContent is called with an empty or unassigned DataTemplateSelector.
Let me know if further clarification is needed!
… for Data template selector" page throws an exception
10bf138
to
d701ce3
Compare
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
Changes Addressed
Root Cause
The exception occurred because the
RealizeView
method in theItemsViewController
file was attempting to create and render a view when bothEmptyView
andEmptyViewTemplate
were defined in theCollectionView
, with aDataTemplateSelector
for theEmptyViewTemplate
. The original code did not account for the scenario where theviewTemplate
was aDataTemplateSelector
. In this case, theRealizeView
method expected aDataTemplate
to be directly provided, leading to anull
reference issue when trying to use theviewTemplate
. This caused an exception when it encountered aDataTemplateSelector
, which should dynamically choose the correct template based on the input data.Description of Change
The fix introduced an additional condition to handle cases where the
viewTemplate
is aDataTemplateSelector
. This ensures that when theview
is null and theviewTemplate
is either null or aDataTemplateSelector
, the logic correctly bypasses attempting to realize a non-existent view. This fix code prevents the exception by ensuring that the method can handleDataTemplateSelector
cases, avoiding invalid template realization, and allowing theCollectionView
to display the appropriate empty view template without errors.Tested the behaviour in the following platforms
Issues Fixed
Fixes #25224
Screenshots
iOS:
Mac: