Skip to content

Commit 492ed23

Browse files
CopilotSuthiYuvaraj
andcommitted
Fix Android CollectionView template handlers to always call UpdateAdapter for dynamic template changes
Co-authored-by: SuthiYuvaraj <[email protected]>
1 parent 330bff7 commit 492ed23

File tree

1 file changed

+2
-26
lines changed

1 file changed

+2
-26
lines changed

src/Controls/src/Core/Handlers/Items/StructuredItemsViewHandler.Android.cs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,12 @@ public partial class StructuredItemsViewHandler<TItemsView> : ItemsViewHandler<T
1414

1515
public static void MapHeaderTemplate(StructuredItemsViewHandler<TItemsView> handler, StructuredItemsView itemsView)
1616
{
17-
// Only call UpdateAdapter if adapter is not yet set up, otherwise the adapter's property listener handles it
18-
var recyclerView = handler.PlatformView as IMauiRecyclerView<TItemsView>;
19-
if (recyclerView != null)
20-
{
21-
// Check if this is a RecyclerView and if the adapter is already set
22-
if (handler.PlatformView is RecyclerView androidRecyclerView && androidRecyclerView.GetAdapter() != null)
23-
{
24-
// Adapter is already set, the adapter's property change listener will handle this more efficiently
25-
return;
26-
}
27-
// Adapter not set yet, need to use UpdateAdapter for initial setup
28-
recyclerView.UpdateAdapter();
29-
}
17+
(handler.PlatformView as IMauiRecyclerView<TItemsView>)?.UpdateAdapter();
3018
}
3119

3220
public static void MapFooterTemplate(StructuredItemsViewHandler<TItemsView> handler, StructuredItemsView itemsView)
3321
{
34-
// Only call UpdateAdapter if adapter is not yet set up, otherwise the adapter's property listener handles it
35-
var recyclerView = handler.PlatformView as IMauiRecyclerView<TItemsView>;
36-
if (recyclerView != null)
37-
{
38-
// Check if this is a RecyclerView and if the adapter is already set
39-
if (handler.PlatformView is RecyclerView androidRecyclerView && androidRecyclerView.GetAdapter() != null)
40-
{
41-
// Adapter is already set, the adapter's property change listener will handle this more efficiently
42-
return;
43-
}
44-
// Adapter not set yet, need to use UpdateAdapter for initial setup
45-
recyclerView.UpdateAdapter();
46-
}
22+
(handler.PlatformView as IMauiRecyclerView<TItemsView>)?.UpdateAdapter();
4723
}
4824

4925
public static void MapItemsLayout(StructuredItemsViewHandler<TItemsView> handler, StructuredItemsView itemsView)

0 commit comments

Comments
 (0)