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 /// <since_tizen> 8 </since_tizen>
37 /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
38 [EditorBrowsable(EditorBrowsableState.Never)]
39 public WearableList() : base(new RecycleAdapter(), new FishEyeLayoutManager())
41 ScrollingDirection = ScrollableBase.Direction.Vertical;
43 ScrollDragStarted += OnScrollDragStarted;
44 ScrollAnimationEnded += OnAnimationEnded;
46 ContentContainer.PositionUsesPivotPoint = true;
47 ContentContainer.ParentOrigin = Tizen.NUI.ParentOrigin.Center;
48 ContentContainer.PivotPoint = Tizen.NUI.PivotPoint.TopCenter;
49 NoticeAnimationEndBeforePosition = 50;
51 ScrollAvailableArea = new Vector2(0, ContentContainer.SizeHeight);
55 Scrollbar = new CircularScrollbar();
56 DecelerationThreshold = 60.0f;
57 DecelerationRate = 0.991f;
60 protected override void SetScrollbar()
62 if(LayoutManager != null)
64 Scrollbar.Initialize(ContentContainer.Size.Height, LayoutManager.StepSize, ContentContainer.CurrentPosition.Y, false);
68 public new RecycleAdapter Adapter
79 foreach (View child in Children)
81 child.PositionUsesPivotPoint = true;
82 child.ParentOrigin = Tizen.NUI.ParentOrigin.TopCenter;
85 ScrollAvailableArea = new Vector2( 0, ContentContainer.SizeHeight );
90 /// Set focus to item which has specific data index.
92 /// <param name="dataIndex">Data index of item.</param>
93 /// <param name="animated">If set true, scroll to item using animation.</param>
94 /// <since_tizen> 8 </since_tizen>
95 /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
96 public void SetFocus(int dataIndex, bool animated)
98 if (LayoutManager == null)
103 foreach (RecycleItem item in Children)
105 if (item.DataIndex == dataIndex)
107 RecycleItem prevFocusedItem = FocusedItem;
108 prevFocusedItem?.OnFocusLost();
110 FocusedItem.OnFocusGained();
112 ScrollTo(item.DataIndex * LayoutManager.StepSize, animated);
117 private void OnAnimationEnded(object source, ScrollEventArgs args)
122 /// This helps developer who wants to know before scroll is reaching target position.
124 /// <param name="targetPosition">Index of item.</param>
125 /// <since_tizen> 8 </since_tizen>
126 /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
127 protected override void OnPreReachedTargetPosition(float targetPosition)
129 if (LayoutManager == null)
133 int targetDataIndex = (int)Math.Round(Math.Abs(targetPosition) / LayoutManager.StepSize);
135 for (int i = 0; i < Children.Count; i++)
137 RecycleItem item = Children[i] as RecycleItem;
143 if (targetDataIndex == item.DataIndex)
146 item.OnFocusGained();
152 private void OnScrollDragStarted(object source, ScrollEventArgs args)
154 RecycleItem prevFocusedItem = FocusedItem;
155 prevFocusedItem?.OnFocusLost();