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

Add ItemFocused event to CircleListView #362

Merged
merged 1 commit into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.ScrollAnimationStopped -= 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; }
}
}