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

Commit

Permalink
Add ItemFocused event to CircleListView
Browse files Browse the repository at this point in the history
  • Loading branch information
rookiejava committed Apr 8, 2021
1 parent 65b344b commit e630090
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

using System;
using ElmSharp;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Tizen;
Expand All @@ -39,6 +40,7 @@ protected override Xamarin.Forms.Platform.Tizen.Native.ListView CreateNativeCont
{
_listView = new WatchListView(XForms.NativeParent, this.GetSurface());
_listView.ItemLongPressed += OnItemLongPressed;
_listView.ScrollAnimationStopped += OnScrollAnimationStopped;
return _listView;
}

Expand All @@ -49,6 +51,7 @@ protected override void Dispose(bool disposing)
if (_listView != null)
{
_listView.ItemLongPressed -= OnItemLongPressed;
_listView.ItemFocused -= OnScrollAnimationStopped;
}
}
base.Dispose(disposing);
Expand All @@ -64,6 +67,17 @@ void OnItemLongPressed(object sender, GenListItemEventArgs args)
}
}

void OnScrollAnimationStopped(object sender, EventArgs args)
{
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);
Element.NotifyIteFocused(obj, index);
}
}

void UpdateBarColor()
{
if (!Element.BarColor.IsDefault)
Expand Down
11 changes: 11 additions & 0 deletions src/Tizen.Wearable.CircularUI.Forms/CircleListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,21 @@ public Color BarColor
/// </summary>
public event EventHandler<ItemLongPressedEventArgs> ItemLongPressed;

/// <summary>
/// Event that is raised when a new item is long pressed.
/// </summary>
public event EventHandler<ItemFocusedEventArgs> ItemFocused;

[EditorBrowsable(EditorBrowsableState.Never)]
public void NotifyItemLongPressed(object item, int index)
{
ItemLongPressed?.Invoke(this, new ItemLongPressedEventArgs(item, index));
}

[EditorBrowsable(EditorBrowsableState.Never)]
public void NotifyIteFocused(object item, int index)
{
ItemFocused?.Invoke(this, new ItemFocusedEventArgs(item, index));
}
}
}
47 changes: 47 additions & 0 deletions src/Tizen.Wearable.CircularUI.Forms/ItemFocusedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Flora License, Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://floralicense.org/license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;

namespace Tizen.Wearable.CircularUI.Forms
{
/// <summary>
/// Event arguments for the ItemFocused event of CircleListView.
/// </summary>
public class ItemFocusedEventArgs : EventArgs
{
/// <summary>
/// Creates a new ItemFocusedEventArgs object.
/// </summary>
/// <param name="item">An item data of new focused item.</param>
/// <param name="itemIndex">An index of new focused item.</param>
public ItemFocusedEventArgs(object item, int itemIndex)
{
Item = item;
ItemIndex = itemIndex;
}

/// <summary>
/// Gets the data of new focused item
/// </summary>
public object Item { get; private set; }

/// <summary>
/// Gets the index of new focused item
/// </summary>
public int ItemIndex { get; private set; }
}
}

0 comments on commit e630090

Please sign in to comment.