[Android] Remove ripple effect on CollectionView item when SelectionMode is None...
authoradrianknight89 <adrianknight89@outlook.com>
Sun, 29 Sep 2019 21:41:35 +0000 (16:41 -0500)
committerRui Marinho <me@ruimarinho.net>
Sun, 29 Sep 2019 21:41:35 +0000 (22:41 +0100)
* fix ripple effect

* revert changes in core

Xamarin.Forms.Platform.Android/CollectionView/SelectableItemsViewRenderer.cs
Xamarin.Forms.Platform.Android/CollectionView/SelectableViewHolder.cs

index 6ae702b..1a52687 100644 (file)
@@ -27,10 +27,7 @@ namespace Xamarin.Forms.Platform.Android
                        {
                                _isSelected = value;
 
-                               if (_isSelected)
-                               {
-                                       EnsureSelectionStates();
-                               }
+                               SetSelectionStates(_isSelected);
 
                                ItemView.Activated = _isSelected;
                                OnSelectedChanged();
@@ -56,27 +53,20 @@ namespace Xamarin.Forms.Platform.Android
                        Clicked?.Invoke(this, adapterPosition);
                }
 
-               void EnsureSelectionStates()
+               void SetSelectionStates(bool isSelected)
                {
-                       if (_selectedDrawable != null)
-                       {
-                               return;
-                       }
-
                        if (Forms.IsMarshmallowOrNewer)
                        {
                                // We're looking for the foreground ripple effect, which is not available on older APIs
                                // Limiting this to Marshmallow and newer, because View.setForeground() is not available on lower APIs
-                               _selectableItemDrawable = GetSelectableItemDrawable();
+                               _selectableItemDrawable = !isSelected ? null : (_selectableItemDrawable ?? GetSelectableItemDrawable());
+
                                ItemView.Foreground = _selectableItemDrawable;
                        }
 
-                       _selectedDrawable = GetSelectedDrawable();
-                               
-                       if (_selectedDrawable != null)
-                       {
-                               ItemView.Background = _selectedDrawable;
-                       }
+                       _selectedDrawable = !isSelected ? null : (_selectedDrawable ?? GetSelectedDrawable());
+
+                       ItemView.Background = _selectedDrawable;
                }
 
                Drawable GetSelectedDrawable()