Closed axa88 closed 3 years ago
Hello @axa88 ,
I had the same problem but, I have found a workaround for that. The native control provides us with the GetItemByPosition method, which returns a list item on a given position on the screen. Thanks to that method, I can obtain the middle item on the screen immediately after the ScrollAnimationStopped event has been raised.
Workaround:
CustomControl
namespace FocusItemListView.Controls
{
public class MyCustomListView : CircleListView
{
public event EventHandler<int> ItemHighlighted;
public void NotifyHighlightedItem(object item, int itemIndex)
{
ItemHighlighted?.Invoke(item, itemIndex);
}
}
}
CustomRenderer
[assembly: ExportRenderer(typeof(MyCustomListView), typeof(MyCustomListViewRenderer))]
namespace FocusItemListView.Renderers
{
public class MyCustomListViewRenderer : CircleListViewRenderer
{
new MyCustomListView Element => base.Element as MyCustomListView;
protected override void OnElementReady()
{
base.OnElementReady();
Control.ScrollAnimationStopped += OnScrollAnimationStopped;
}
private void OnScrollAnimationStopped(object sender, EventArgs arrgs)
{
GenListItem item = Control.GetItemByPosition(180, 180, out int pos);
if (item.Data is NListView.ItemContext itemContext && pos == 0)
{
var obj = itemContext.Cell.BindingContext;
var index = Element.TemplatedItems.GetGlobalIndexOfItem(obj);
Log.Debug("TEST", $"Item index: {index}");
Element.NotifyHighlightedItem(obj, index);
}
}
protected override void Dispose(bool disposing)
{
if (disposing && Control != null)
{
Control.ScrollAnimationStopped -= OnScrollAnimationStopped;
}
base.Dispose(disposing);
}
}
}
We does not provide API to get current focused item, but as workaround commented on above, you can get it
@myroot understanding this is a workaround, but couldn't this issue be kept open as enhancement? i think this workaround is a bit much for rapid application development, and get focus item is worthy addition for CircularUI API.
@axa88 Thank you for your suggestion. This is the same one I suggested to Xamarin.Forms two years ago. https://github.com/xamarin/Xamarin.Forms/issues/2181
We'll discuss internally whether to add this to CircularUI by itself. Thanks!
Is there any progress on this?
Hi @Machinero. Thanks for the workaround provided, however I cannot get the following line from the custom renderer to compile:
if (item.Data is NListView.ItemContext itemContext && pos == 0)
"NListView" is not being recognized, is that correct?
Thank you for waiting so long. 🙏 I've just published a new version (1.5.3) to nuget that support this.. (See also release note )
Plus, thanks to @Machinero for providing great idea. ❤️
Describe the bug
It doesn't appear possible to get the currently focused item in a
CircleListView
. When rotating the bezel, or scrolling the list, i would like to know which item has been scrolled to.Example here I would like to obtain the index of this list item that comes into focus:
Item is not selected or tapped so
ItemTapped
orItemSelected
events are irrelevant.Focused
event only is relevant to the EntireListView
not individual items.Scrolled
,ItemAppearing
,ItemDisappearing
event args do not provide information of the focused item.To Reproduce Steps to reproduce the behavior:
CircleListView
Expected behavior Be able to obtain the index of the focused item of a
CircleListView
Perhaps a property FocusedItem could be added.Environment (please complete the following information):
Target Product: Tizen Platform Version [e.g. Tizen 5.5] Tizen.CircularUI Version [1.4.0 > 1.5.0]
Additional context Perhaps im ignorant, but i do not see a way to do this.