diff --git a/Xamarin.Forms.Platform.Tizen/Native/CollectionView/CollectionView.cs b/Xamarin.Forms.Platform.Tizen/Native/CollectionView/CollectionView.cs index 21ef1531377..ea0dc02e3e9 100644 --- a/Xamarin.Forms.Platform.Tizen/Native/CollectionView/CollectionView.cs +++ b/Xamarin.Forms.Platform.Tizen/Native/CollectionView/CollectionView.cs @@ -34,6 +34,7 @@ public class CollectionView : EBox, ICollectionViewController, IRotaryInteractio SmartEvent _scrollAnimationStop; SmartEvent _scrollAnimationStart; bool _isScrollAnimationStarted; + bool _allowFocusOnItem; public event EventHandler Scrolled; @@ -52,6 +53,9 @@ public CollectionView(EvasObject parent) : base(parent) _scrollAnimationStop = new SmartEvent(Scroller, ThemeConstants.Scroller.Signals.StopScrollAnimation); _scrollAnimationStop.On += OnScrollStopped; + Scroller.DragStart += OnDragStart; + Scroller.KeyDown += OnKeyDown; + _innerLayout = new EBox(parent); _innerLayout.SetLayoutCallback(OnInnerLayout); _innerLayout.Show(); @@ -306,6 +310,8 @@ ViewHolder ICollectionViewController.RealizeView(int index) _innerLayout.PackEnd(holder); } + holder.AllowItemFocus = _allowFocusOnItem; + Adaptor.SetBinding(holder.Content, index); _viewHolderIndexTable[holder] = index; if (index == SelectedItemIndex) @@ -325,6 +331,7 @@ void OnItemStateChanged(object sender, EventArgs e) if (holder.State == ViewHolderState.Focused && FocusedItemScrollPosition != ScrollToPosition.MakeVisible) { + Device.BeginInvokeOnMainThread(() => { if (holder.State == ViewHolderState.Focused && _viewHolderIndexTable.TryGetValue(holder, out int itemIndex)) @@ -363,6 +370,7 @@ void ICollectionViewController.UnrealizeView(ViewHolder view) Adaptor.UnBinding(view.Content); view.ResetState(); view.Hide(); + _pool.AddRecyclerView(view); if (_lastSelectedViewHolder == view) { @@ -661,6 +669,18 @@ void OnScrolled(object sender, EventArgs e) } } + void OnKeyDown(object sender, EvasKeyEventArgs e) + { + _allowFocusOnItem = true; + UpdateAllowFocusOnItem(_allowFocusOnItem); + } + + void OnDragStart(object sender, EventArgs e) + { + _allowFocusOnItem = false; + UpdateAllowFocusOnItem(_allowFocusOnItem); + } + void SendScrolledEvent() { var args = new ItemsViewScrolledEventArgs(); @@ -733,6 +753,14 @@ void RemoveEmptyView() Adaptor.RemoveNativeView(_emptyView); _emptyView = null; } + + void UpdateAllowFocusOnItem(bool allowFocus) + { + foreach (var holer in _viewHolderIndexTable) + { + holer.Key.AllowItemFocus = allowFocus; + } + } } public interface ICollectionViewController diff --git a/Xamarin.Forms.Platform.Tizen/Native/CollectionView/ViewHolder.cs b/Xamarin.Forms.Platform.Tizen/Native/CollectionView/ViewHolder.cs index 8a6c9572137..9913c09ea9a 100644 --- a/Xamarin.Forms.Platform.Tizen/Native/CollectionView/ViewHolder.cs +++ b/Xamarin.Forms.Platform.Tizen/Native/CollectionView/ViewHolder.cs @@ -19,6 +19,7 @@ public class ViewHolder : Box ViewHolderState _state; bool _isSelected; bool _isFocused; + bool _focusable; public ViewHolder(EvasObject parent) : base(parent) { @@ -54,6 +55,20 @@ public EvasObject Content } } + public bool AllowItemFocus + { + get => _focusable; + set + { + _focusable = value; + if (!value && _focusArea.IsFocused) + { + _focusArea.SetFocus(false); + } + _focusArea.AllowFocus(_focusable); + } + } + public ViewHolderState State { get { return _state; } @@ -93,6 +108,7 @@ protected void Initialize(EvasObject parent) _focusArea.KeyUp += OnKeyUp; _focusArea.RepeatEvents = true; _focusArea.Show(); + _focusArea.AllowFocus(_focusable); PackEnd(_focusArea); Show();