1 /* Copyright (c) 2020 Samsung Electronics Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
17 using Tizen.NUI.BaseComponents;
18 using Tizen.NUI.Components;
19 using System.ComponentModel;
21 namespace Tizen.NUI.Wearable
24 /// [Draft] This class provides a list view styled by wearable ux.
25 /// List will lay out all items with Fish-Eye layout manager.
27 /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
28 [EditorBrowsable(EditorBrowsableState.Never)]
29 public class WearableList : RecyclerView
31 private RecycleItem FocusedItem = null;
34 /// Default constructor.
36 /// <param name="adapter">Recycle adapter of List.</param>
37 /// <since_tizen> 8 </since_tizen>
38 /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
39 [EditorBrowsable(EditorBrowsableState.Never)]
40 public WearableList() : base(new RecycleAdapter(), new FishEyeLayoutManager())
42 ScrollingDirection = ScrollableBase.Direction.Vertical;
44 ScrollDragStartEvent += OnScrollDragStart;
45 ScrollAnimationEndEvent += OnAnimationEnd;
47 mContainer.PositionUsesPivotPoint = true;
48 mContainer.ParentOrigin = Tizen.NUI.ParentOrigin.Center;
49 mContainer.PivotPoint = Tizen.NUI.PivotPoint.TopCenter;
50 NoticeAnimationEndBeforePosition = 50;
52 ScrollAvailableArea = new Vector2( 0, mContainer.SizeHeight);
57 public new RecycleAdapter Adapter
68 foreach (View child in mContainer.Children)
70 child.PositionUsesPivotPoint = true;
71 child.ParentOrigin = Tizen.NUI.ParentOrigin.TopCenter;
74 ScrollAvailableArea = new Vector2( 0, mContainer.SizeHeight );
79 /// Set focus to item which has specific data index.
81 /// <param name="dataIndex">Data index of item.</param>
82 /// <param name="animated">If set true, scroll to item using animation.</param>
83 /// <since_tizen> 8 </since_tizen>
84 /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
85 public void SetFocus(int dataIndex, bool animated)
87 foreach (RecycleItem item in mContainer.Children)
89 if (item.DataIndex == dataIndex)
91 RecycleItem prevFocusedItem = FocusedItem;
92 prevFocusedItem?.OnFocusLost();
94 FocusedItem.OnFocusGained();
96 ScrollTo(item.DataIndex * mLayoutManager.StepSize, animated);
101 private void OnAnimationEnd(object source, ScrollableBase.ScrollEventArgs args)
106 /// This helps developer who wants to know before scroll is reaching target position.
108 /// <param name="targetPosition">Index of item.</param>
109 /// <since_tizen> 8 </since_tizen>
110 /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
111 protected override void OnPreReachedTargetPosition(float targetPosition)
113 int targetDataIndex = (int)Math.Round(Math.Abs(targetPosition) / mLayoutManager.StepSize);
115 for (int i = 0; i < mContainer.Children.Count; i++)
117 RecycleItem item = mContainer.Children[i] as RecycleItem;
119 if (targetDataIndex == item.DataIndex)
122 item.OnFocusGained();
128 private void OnScrollDragStart(object source, ScrollableBase.ScrollEventArgs args)
130 RecycleItem prevFocusedItem = FocusedItem;
131 prevFocusedItem?.OnFocusLost();