{
_isSelected = value;
- if (_isSelected)
- {
- EnsureSelectionStates();
- }
+ SetSelectionStates(_isSelected);
ItemView.Activated = _isSelected;
OnSelectedChanged();
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()