diff --git a/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.cs b/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.cs index b10fa478b7d2..cded4e8b8df7 100644 --- a/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.cs +++ b/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.cs @@ -28,7 +28,10 @@ public ItemsViewHandler(PropertyMapper mapper = null) : base(mapper ?? ItemsView [Controls.ItemsView.EmptyViewTemplateProperty.PropertyName] = MapEmptyViewTemplate, [Controls.ItemsView.FlowDirectionProperty.PropertyName] = MapFlowDirection, [Controls.ItemsView.IsVisibleProperty.PropertyName] = MapIsVisible, - [Controls.ItemsView.ItemsUpdatingScrollModeProperty.PropertyName] = MapItemsUpdatingScrollMode + [Controls.ItemsView.ItemsUpdatingScrollModeProperty.PropertyName] = MapItemsUpdatingScrollMode, + #if IOS + [nameof(IView.IsEnabled)] = MapIsEnabled, + #endif }; } } diff --git a/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.iOS.cs b/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.iOS.cs index 846728b101da..6dbd5964a012 100644 --- a/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.iOS.cs +++ b/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.iOS.cs @@ -97,6 +97,11 @@ protected virtual void UpdateLayout() Controller?.UpdateLayout(_layout); } + internal static void MapIsEnabled(ItemsViewHandler handler, ItemsView itemsView) + { + (handler.Controller as SelectableItemsViewController)?.UpdateSelectionMode(); + } + protected virtual void ScrollToRequested(object sender, ScrollToRequestEventArgs args) { using (var indexPath = DetermineIndex(args)) diff --git a/src/Controls/src/Core/Handlers/Items/iOS/SelectableItemsViewController.cs b/src/Controls/src/Core/Handlers/Items/iOS/SelectableItemsViewController.cs index 1f00d0f482e1..95881a777273 100644 --- a/src/Controls/src/Core/Handlers/Items/iOS/SelectableItemsViewController.cs +++ b/src/Controls/src/Core/Handlers/Items/iOS/SelectableItemsViewController.cs @@ -25,7 +25,7 @@ protected override UICollectionViewDelegateFlowLayout CreateDelegator() // _Only_ called if the user initiates the selection change; will not be called for programmatic selection public override void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath) { - if (ItemsView?.ItemsSource is null) + if (ItemsView?.ItemsSource is null || !ItemsView.IsExplicitlyEnabled) { return; } @@ -35,7 +35,7 @@ public override void ItemSelected(UICollectionView collectionView, NSIndexPath i // _Only_ called if the user initiates the selection change; will not be called for programmatic selection public override void ItemDeselected(UICollectionView collectionView, NSIndexPath indexPath) { - if (ItemsView?.ItemsSource is null) + if (ItemsView?.ItemsSource is null || !ItemsView.IsExplicitlyEnabled) { return; } @@ -185,6 +185,7 @@ internal void UpdatePlatformSelection() internal void UpdateSelectionMode() { var mode = ItemsView.SelectionMode; + var isEnabled = ItemsView.IsExplicitlyEnabled; switch (mode) { @@ -194,13 +195,13 @@ internal void UpdateSelectionMode() ClearsSelectionOnViewWillAppear = true; break; case SelectionMode.Single: - CollectionView.AllowsSelection = true; + CollectionView.AllowsSelection = isEnabled; CollectionView.AllowsMultipleSelection = false; ClearsSelectionOnViewWillAppear = false; break; case SelectionMode.Multiple: - CollectionView.AllowsSelection = true; - CollectionView.AllowsMultipleSelection = true; + CollectionView.AllowsSelection = isEnabled; + CollectionView.AllowsMultipleSelection = isEnabled; ClearsSelectionOnViewWillAppear = false; break; } diff --git a/src/Controls/src/Core/Handlers/Items2/ItemsViewHandler2.iOS.cs b/src/Controls/src/Core/Handlers/Items2/ItemsViewHandler2.iOS.cs index 8f55ca5eb2d0..581a6352a517 100644 --- a/src/Controls/src/Core/Handlers/Items2/ItemsViewHandler2.iOS.cs +++ b/src/Controls/src/Core/Handlers/Items2/ItemsViewHandler2.iOS.cs @@ -33,7 +33,8 @@ public ItemsViewHandler2(PropertyMapper mapper = null) : base(mapper ?? ItemsVie [Controls.ItemsView.EmptyViewTemplateProperty.PropertyName] = MapEmptyViewTemplate, [Controls.ItemsView.FlowDirectionProperty.PropertyName] = MapFlowDirection, [Controls.ItemsView.IsVisibleProperty.PropertyName] = MapIsVisible, - [Controls.ItemsView.ItemsUpdatingScrollModeProperty.PropertyName] = MapItemsUpdatingScrollMode + [Controls.ItemsView.ItemsUpdatingScrollModeProperty.PropertyName] = MapItemsUpdatingScrollMode, + [nameof(IView.IsEnabled)] = MapIsEnabled }; UICollectionViewLayout _layout; @@ -121,6 +122,11 @@ public static void MapIsVisible(ItemsViewHandler2 handler, ItemsView handler.Controller?.UpdateVisibility(); } + internal static void MapIsEnabled(ItemsViewHandler2 handler, ItemsView itemsView) + { + (handler.Controller as SelectableItemsViewController2)?.UpdateSelectionMode(); + } + public static void MapItemsUpdatingScrollMode(ItemsViewHandler2 handler, ItemsView itemsView) { if (handler.ItemsView is StructuredItemsView structuredItemsView && structuredItemsView.ItemsLayout is ItemsLayout itemsLayout) diff --git a/src/Controls/src/Core/Handlers/Items2/iOS/SelectableItemsViewController2.cs b/src/Controls/src/Core/Handlers/Items2/iOS/SelectableItemsViewController2.cs index cc02ddde501e..d8bf2ab69cd1 100644 --- a/src/Controls/src/Core/Handlers/Items2/iOS/SelectableItemsViewController2.cs +++ b/src/Controls/src/Core/Handlers/Items2/iOS/SelectableItemsViewController2.cs @@ -26,7 +26,7 @@ protected override UICollectionViewDelegateFlowLayout CreateDelegator() // _Only_ called if the user initiates the selection change; will not be called for programmatic selection public override void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath) { - if (ItemsView?.ItemsSource is null) + if (ItemsView?.ItemsSource is null || !ItemsView.IsExplicitlyEnabled) { return; } @@ -36,7 +36,7 @@ public override void ItemSelected(UICollectionView collectionView, NSIndexPath i // _Only_ called if the user initiates the selection change; will not be called for programmatic selection public override void ItemDeselected(UICollectionView collectionView, NSIndexPath indexPath) { - if (ItemsView?.ItemsSource is null) + if (ItemsView?.ItemsSource is null || !ItemsView.IsExplicitlyEnabled) { return; } @@ -186,6 +186,7 @@ internal void UpdatePlatformSelection() internal void UpdateSelectionMode() { var mode = ItemsView.SelectionMode; + var isEnabled = ItemsView.IsExplicitlyEnabled; switch (mode) { @@ -195,13 +196,13 @@ internal void UpdateSelectionMode() ClearsSelectionOnViewWillAppear = true; break; case SelectionMode.Single: - CollectionView.AllowsSelection = true; + CollectionView.AllowsSelection = isEnabled; CollectionView.AllowsMultipleSelection = false; ClearsSelectionOnViewWillAppear = false; break; case SelectionMode.Multiple: - CollectionView.AllowsSelection = true; - CollectionView.AllowsMultipleSelection = true; + CollectionView.AllowsSelection = isEnabled; + CollectionView.AllowsMultipleSelection = isEnabled; ClearsSelectionOnViewWillAppear = false; break; } diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue20274.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue20274.xaml new file mode 100644 index 000000000000..e16b14c3a8e4 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue20274.xaml @@ -0,0 +1,27 @@ + + + + +