Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Disable focus on Item when touch swipe was used (#13907)
Browse files Browse the repository at this point in the history
  • Loading branch information
myroot authored Mar 3, 2021
1 parent 4b59b6f commit caab66b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class CollectionView : EBox, ICollectionViewController, IRotaryInteractio
SmartEvent _scrollAnimationStop;
SmartEvent _scrollAnimationStart;
bool _isScrollAnimationStarted;
bool _allowFocusOnItem;

public event EventHandler<ItemsViewScrolledEventArgs> Scrolled;

Expand All @@ -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();
Expand Down Expand Up @@ -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)
Expand All @@ -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))
Expand Down Expand Up @@ -363,6 +370,7 @@ void ICollectionViewController.UnrealizeView(ViewHolder view)
Adaptor.UnBinding(view.Content);
view.ResetState();
view.Hide();

_pool.AddRecyclerView(view);
if (_lastSelectedViewHolder == view)
{
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions Xamarin.Forms.Platform.Tizen/Native/CollectionView/ViewHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class ViewHolder : Box
ViewHolderState _state;
bool _isSelected;
bool _isFocused;
bool _focusable;

public ViewHolder(EvasObject parent) : base(parent)
{
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -93,6 +108,7 @@ protected void Initialize(EvasObject parent)
_focusArea.KeyUp += OnKeyUp;
_focusArea.RepeatEvents = true;
_focusArea.Show();
_focusArea.AllowFocus(_focusable);

PackEnd(_focusArea);
Show();
Expand Down

0 comments on commit caab66b

Please sign in to comment.