Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

Obtain current focused item of CircleListView when scrolling list #339

Closed
axa88 opened this issue Jun 26, 2020 · 7 comments · Fixed by #362
Closed

Obtain current focused item of CircleListView when scrolling list #339

axa88 opened this issue Jun 26, 2020 · 7 comments · Fixed by #362
Labels
enhancement New feature or request

Comments

@axa88
Copy link

axa88 commented Jun 26, 2020

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:
image

Item is not selected or tapped so ItemTapped or ItemSelected events are irrelevant.
Focused event only is relevant to the Entire ListView not individual items.
Scrolled, ItemAppearing, ItemDisappearing event args do not provide information of the focused item.

To Reproduce
Steps to reproduce the behavior:

  1. Populate a CircleListView
  2. scroll the list by any means
  3. try to obtain the index when the focused list item changes

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:
image
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.

@axa88 axa88 added the bug Something isn't working label Jun 26, 2020
@myroot myroot added enhancement New feature or request and removed bug Something isn't working labels Jun 28, 2020
@Machinero
Copy link

Machinero commented Jul 2, 2020

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);
        }
    }
}

@myroot
Copy link
Collaborator

myroot commented Sep 21, 2020

We does not provide API to get current focused item, but as workaround commented on above, you can get it

@myroot myroot closed this as completed Sep 21, 2020
@axa88
Copy link
Author

axa88 commented Sep 21, 2020

@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.

@rookiejava
Copy link
Contributor

@axa88 Thank you for your suggestion. This is the same one I suggested to Xamarin.Forms two years ago. xamarin/Xamarin.Forms#2181

We'll discuss internally whether to add this to CircularUI by itself.
Thanks!

@AliArdaOrhan
Copy link

Is there any progress on this?

@hacqua
Copy link

hacqua commented Feb 26, 2021

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?

@rookiejava
Copy link
Contributor

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. ❤️

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants