[Tizen] Support VisualState on Items of CollectionView (#12281) fixes #12225

* Support VisualState on Items of CollectionView

* Remove unused theme constants
This commit is contained in:
Seungkeun Lee 2020-09-29 03:20:46 +09:00 коммит произвёл GitHub
Родитель b37651630a
Коммит cb95ccbee1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 58 добавлений и 73 удалений

Просмотреть файл

@ -14,14 +14,6 @@ namespace Xamarin.Forms.Platform.Tizen.Native
public EScroller Scroll => base.Scroller;
protected override ViewHolder CreateViewHolder()
{
return new ViewHolder(this)
{
FocusedColor = ThemeConstants.CarouselView.ColorClass.DefaultFocusedColor,
SelectedColor = ThemeConstants.CarouselView.ColorClass.DefaultSelectedColor,
};
}
ESize ICollectionViewController.GetItemSize(int widthConstraint, int heightConstraint)
{
return AllocatedSize;

Просмотреть файл

@ -287,6 +287,7 @@ namespace Xamarin.Forms.Platform.Tizen.Native
var content = Adaptor.CreateNativeView(index, this);
holder = CreateViewHolder();
holder.RequestSelected += OnRequestItemSelection;
holder.StateUpdated += OnItemStateChanged;
holder.Content = content;
holder.ViewCategory = Adaptor.GetViewCategory(index);
_innerLayout.PackEnd(holder);
@ -301,15 +302,22 @@ namespace Xamarin.Forms.Platform.Tizen.Native
return holder;
}
void OnItemStateChanged(object sender, EventArgs e)
{
if (sender is ViewHolder holder && holder.Content != null)
{
Adaptor?.UpdateViewState(holder.Content, holder.State);
}
}
void OnRequestItemSelection(object sender, EventArgs e)
{
if (SelectionMode == CollectionViewSelectionMode.None)
return;
if (_lastSelectedViewHolder != null)
{
_lastSelectedViewHolder.State = ViewHolderState.Normal;
_lastSelectedViewHolder.ResetState();
}
_lastSelectedViewHolder = sender as ViewHolder;
@ -377,7 +385,7 @@ namespace Xamarin.Forms.Platform.Tizen.Native
{
if (_lastSelectedViewHolder != null)
{
_lastSelectedViewHolder.State = ViewHolderState.Normal;
_lastSelectedViewHolder.ResetState();
_lastSelectedViewHolder = null;
}
_selectedItemIndex = -1;

Просмотреть файл

@ -27,6 +27,10 @@ namespace Xamarin.Forms.Platform.Tizen.Native
ItemSelected?.Invoke(this, new SelectedItemChangedEventArgs(this[index], index));
}
public virtual void UpdateViewState(EvasObject view, ViewHolderState state)
{
}
public void RequestItemSelected(object item)
{
if (CollectionView != null)

Просмотреть файл

@ -51,16 +51,16 @@ namespace Xamarin.Forms.Platform.Tizen.Native
protected View _headerCache;
protected View _footerCache;
public ItemTemplateAdaptor(ItemsView itemsView) : base(itemsView.ItemsSource)
{
ItemTemplate = itemsView.ItemTemplate;
_itemsView = itemsView;
}
bool IsSelectable { get; }
public ItemTemplateAdaptor(ItemsView itemsView) : this(itemsView, itemsView.ItemsSource, itemsView.ItemTemplate) { }
protected ItemTemplateAdaptor(ItemsView itemsView, IEnumerable items, DataTemplate template) : base(items)
{
ItemTemplate = template;
_itemsView = itemsView;
IsSelectable = itemsView is SelectableItemsView;
}
protected DataTemplate ItemTemplate { get; set; }
@ -212,6 +212,27 @@ namespace Xamarin.Forms.Platform.Tizen.Native
return _footerCache?.Measure(Forms.ConvertToScaledDP(widthConstraint), Forms.ConvertToScaledDP(heightConstraint)).Request.ToPixel() ?? new ESize(0, 0);
}
public override void UpdateViewState(EvasObject view, ViewHolderState state)
{
base.UpdateViewState(view, state);
if (_nativeFormsTable.TryGetValue(view, out View formsView))
{
switch (state)
{
case ViewHolderState.Focused:
VisualStateManager.GoToState(formsView, VisualStateManager.CommonStates.Focused);
break;
case ViewHolderState.Normal:
VisualStateManager.GoToState(formsView, VisualStateManager.CommonStates.Normal);
break;
case ViewHolderState.Selected:
if (IsSelectable)
VisualStateManager.GoToState(formsView, VisualStateManager.CommonStates.Selected);
break;
}
}
}
protected virtual View CreateHeaderView()
{
if (_itemsView is StructuredItemsView structuredItemsView)

Просмотреть файл

@ -1,6 +1,5 @@
using System;
using ElmSharp;
using ERectangle = ElmSharp.Rectangle;
using EColor = ElmSharp.Color;
@ -11,14 +10,15 @@ namespace Xamarin.Forms.Platform.Tizen.Native
{
Normal,
Selected,
Focused,
}
public class ViewHolder : Box
{
ERectangle _background;
Button _focusArea;
EvasObject _content;
ViewHolderState _state;
bool _isSelected;
public ViewHolder(EvasObject parent) : base(parent)
{
@ -26,26 +26,13 @@ namespace Xamarin.Forms.Platform.Tizen.Native
}
public object ViewCategory { get; set; }
[Obsolete("FocusedColor is obsolete. Use VisualStateManager")]
public EColor FocusedColor { get; set; }
[Obsolete("SelectedColor is obsolete. Use VisualStateManager")]
public EColor SelectedColor { get; set; }
EColor EffectiveFocusedColor => FocusedColor == EColor.Default ? ThemeConstants.CollectionView.ColorClass.DefaultFocusedColor : FocusedColor;
EColor EffectiveSelectedColor => SelectedColor == EColor.Default ? ThemeConstants.CollectionView.ColorClass.DefaultSelectedColor : SelectedColor;
EColor FocusSelectedColor
{
get
{
var color1 = EffectiveFocusedColor;
var color2 = EffectiveSelectedColor;
return new EColor(
(color1.R + color2.R) / 2,
(color1.G + color2.G) / 2,
(color1.B + color2.B) / 2,
(color1.A + color2.A) / 2);
}
}
public EvasObject Content
{
get
@ -61,7 +48,7 @@ namespace Xamarin.Forms.Platform.Tizen.Native
_content = value;
if (_content != null)
{
PackAfter(_content, _background);
PackEnd(_content);
_content.StackBelow(_focusArea);
}
}
@ -77,30 +64,19 @@ namespace Xamarin.Forms.Platform.Tizen.Native
}
}
public event EventHandler Selected;
public event EventHandler RequestSelected;
public event EventHandler StateUpdated;
public void ResetState()
{
State = ViewHolderState.Normal;
_background.Color = EColor.Transparent;
}
protected void SendSelected()
{
Selected?.Invoke(this, EventArgs.Empty);
}
protected void Initialize(EvasObject parent)
{
SetLayoutCallback(OnLayout);
_background = new ERectangle(parent)
{
Color = EColor.Transparent
};
_background.Show();
_focusArea = new Button(parent);
_focusArea.Color = EColor.Transparent;
_focusArea.BackgroundColor = EColor.Transparent;
@ -112,9 +88,7 @@ namespace Xamarin.Forms.Platform.Tizen.Native
_focusArea.RepeatEvents = true;
_focusArea.Show();
PackEnd(_background);
PackEnd(_focusArea);
FocusedColor = EColor.Default;
Show();
}
@ -122,11 +96,11 @@ namespace Xamarin.Forms.Platform.Tizen.Native
{
if (_focusArea.IsFocused)
{
_background.Color = State == ViewHolderState.Selected ? FocusSelectedColor : EffectiveFocusedColor;
State = ViewHolderState.Focused;
}
else
{
_background.Color = State == ViewHolderState.Selected ? EffectiveSelectedColor : EColor.Transparent;
State = _isSelected ? ViewHolderState.Selected : ViewHolderState.Normal;
}
}
@ -137,7 +111,6 @@ namespace Xamarin.Forms.Platform.Tizen.Native
protected virtual void OnLayout()
{
_background.Geometry = Geometry;
_focusArea.Geometry = Geometry;
if (_content != null)
{
@ -147,14 +120,12 @@ namespace Xamarin.Forms.Platform.Tizen.Native
protected virtual void UpdateState()
{
if (State == ViewHolderState.Normal)
{
_background.Color = _focusArea.IsFocused ? EffectiveFocusedColor : EColor.Transparent;
} else
{
_background.Color = _focusArea.IsFocused ? FocusSelectedColor : SelectedColor;
SendSelected();
}
if (State == ViewHolderState.Selected)
_isSelected = true;
else if (State == ViewHolderState.Normal)
_isSelected = false;
StateUpdated?.Invoke(this, EventArgs.Empty);
}

Просмотреть файл

@ -580,17 +580,6 @@ namespace Xamarin.Forms.Platform.Tizen
}
#endregion
#region CollectionView
public class CollectionView
{
public class ColorClass
{
public static readonly EColor DefaultFocusedColor = EColor.FromRgba(244, 244, 244, 200);
public static readonly EColor DefaultSelectedColor = EColor.FromRgba(227, 242, 253, 200);
}
}
#endregion
#region CarouselView
public class CarouselView
{