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

Commit caab66b

Browse files
authored
Disable focus on Item when touch swipe was used (#13907)
1 parent 4b59b6f commit caab66b

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

Xamarin.Forms.Platform.Tizen/Native/CollectionView/CollectionView.cs

+28
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class CollectionView : EBox, ICollectionViewController, IRotaryInteractio
3434
SmartEvent _scrollAnimationStop;
3535
SmartEvent _scrollAnimationStart;
3636
bool _isScrollAnimationStarted;
37+
bool _allowFocusOnItem;
3738

3839
public event EventHandler<ItemsViewScrolledEventArgs> Scrolled;
3940

@@ -52,6 +53,9 @@ public CollectionView(EvasObject parent) : base(parent)
5253
_scrollAnimationStop = new SmartEvent(Scroller, ThemeConstants.Scroller.Signals.StopScrollAnimation);
5354
_scrollAnimationStop.On += OnScrollStopped;
5455

56+
Scroller.DragStart += OnDragStart;
57+
Scroller.KeyDown += OnKeyDown;
58+
5559
_innerLayout = new EBox(parent);
5660
_innerLayout.SetLayoutCallback(OnInnerLayout);
5761
_innerLayout.Show();
@@ -306,6 +310,8 @@ ViewHolder ICollectionViewController.RealizeView(int index)
306310
_innerLayout.PackEnd(holder);
307311
}
308312

313+
holder.AllowItemFocus = _allowFocusOnItem;
314+
309315
Adaptor.SetBinding(holder.Content, index);
310316
_viewHolderIndexTable[holder] = index;
311317
if (index == SelectedItemIndex)
@@ -325,6 +331,7 @@ void OnItemStateChanged(object sender, EventArgs e)
325331

326332
if (holder.State == ViewHolderState.Focused && FocusedItemScrollPosition != ScrollToPosition.MakeVisible)
327333
{
334+
328335
Device.BeginInvokeOnMainThread(() =>
329336
{
330337
if (holder.State == ViewHolderState.Focused && _viewHolderIndexTable.TryGetValue(holder, out int itemIndex))
@@ -363,6 +370,7 @@ void ICollectionViewController.UnrealizeView(ViewHolder view)
363370
Adaptor.UnBinding(view.Content);
364371
view.ResetState();
365372
view.Hide();
373+
366374
_pool.AddRecyclerView(view);
367375
if (_lastSelectedViewHolder == view)
368376
{
@@ -661,6 +669,18 @@ void OnScrolled(object sender, EventArgs e)
661669
}
662670
}
663671

672+
void OnKeyDown(object sender, EvasKeyEventArgs e)
673+
{
674+
_allowFocusOnItem = true;
675+
UpdateAllowFocusOnItem(_allowFocusOnItem);
676+
}
677+
678+
void OnDragStart(object sender, EventArgs e)
679+
{
680+
_allowFocusOnItem = false;
681+
UpdateAllowFocusOnItem(_allowFocusOnItem);
682+
}
683+
664684
void SendScrolledEvent()
665685
{
666686
var args = new ItemsViewScrolledEventArgs();
@@ -733,6 +753,14 @@ void RemoveEmptyView()
733753
Adaptor.RemoveNativeView(_emptyView);
734754
_emptyView = null;
735755
}
756+
757+
void UpdateAllowFocusOnItem(bool allowFocus)
758+
{
759+
foreach (var holer in _viewHolderIndexTable)
760+
{
761+
holer.Key.AllowItemFocus = allowFocus;
762+
}
763+
}
736764
}
737765

738766
public interface ICollectionViewController

Xamarin.Forms.Platform.Tizen/Native/CollectionView/ViewHolder.cs

+16
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class ViewHolder : Box
1919
ViewHolderState _state;
2020
bool _isSelected;
2121
bool _isFocused;
22+
bool _focusable;
2223

2324
public ViewHolder(EvasObject parent) : base(parent)
2425
{
@@ -54,6 +55,20 @@ public EvasObject Content
5455
}
5556
}
5657

58+
public bool AllowItemFocus
59+
{
60+
get => _focusable;
61+
set
62+
{
63+
_focusable = value;
64+
if (!value && _focusArea.IsFocused)
65+
{
66+
_focusArea.SetFocus(false);
67+
}
68+
_focusArea.AllowFocus(_focusable);
69+
}
70+
}
71+
5772
public ViewHolderState State
5873
{
5974
get { return _state; }
@@ -93,6 +108,7 @@ protected void Initialize(EvasObject parent)
93108
_focusArea.KeyUp += OnKeyUp;
94109
_focusArea.RepeatEvents = true;
95110
_focusArea.Show();
111+
_focusArea.AllowFocus(_focusable);
96112

97113
PackEnd(_focusArea);
98114
Show();

0 commit comments

Comments
 (0)