Add InputFilter to TextField, TextEditor
[platform/core/csapi/tizenfx.git] / test / NUITizenGallery / Examples / CollectionViewTest / CollectionViewTest7.xaml.cs
1 /*
2  * Copyright(c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 using System;
18 using System.Collections.ObjectModel;
19 using System.ComponentModel;
20 using Tizen.NUI;
21 using Tizen.NUI.Binding;
22 using Tizen.NUI.BaseComponents;
23 using Tizen.NUI.Components;
24 using Tizen.NUI.Components.Extension;
25
26 namespace NUITizenGallery
27 {
28     public partial class CollectionViewTest7 : ContentPage
29     {
30         void OnScrolling(object sender, ScrollEventArgs e)
31         {
32             ObservableCollection<TestItem> source = ColView.ItemsSource as ObservableCollection<TestItem>;
33             if (source == null) return;
34             //Reached Bound of Scroll
35             if (e.ScrollPosition.Y == (ColView.ContentContainer.SizeHeight - ColView.SizeHeight))
36             {
37                 int count = source.Count;
38                 var Rand = new Random();
39                 for (int i = count; i < count + 20; i++)
40                 {
41                     source.Add(new TestItem(i,
42                                             "Test Item",
43                                             new Color(((float)(Rand.Next(255))/255),
44                                                       ((float)(Rand.Next(255))/255),
45                                                       ((float)(Rand.Next(255))/255), 1)));
46                 }
47             }
48         }
49
50         public CollectionViewTest7()
51         {
52             InitializeComponent();
53             BindingContext = new TestSourceModel(40);
54
55             ColView.ItemTemplate = new DataTemplate(() =>
56             {
57                 var item = new RecyclerViewItem()
58                 {
59                     WidthSpecification = LayoutParamPolicies.MatchParent,
60                     HeightSpecification = 100,
61                 };
62                 item.SetBinding(View.BackgroundColorProperty, "BgColor");
63                 var label = new TextLabel()
64                 {
65                     ParentOrigin = Tizen.NUI.ParentOrigin.Center,
66                     PivotPoint = Tizen.NUI.PivotPoint.Center,
67                     PositionUsesPivotPoint = true,
68                 };
69                 label.PixelSize = 30;
70                 label.SetBinding(TextLabel.TextProperty, "Index");
71                 item.Add(label);
72
73                 return item;
74             });
75             // Currently ScrollableBase only support Scrolling and ScrollOutOfBound event.
76             ColView.Scrolling += OnScrolling;
77         }
78
79         protected override void Dispose(DisposeTypes type)
80         {
81             if (Disposed)
82             {
83                 return;
84             }
85
86             if (type == DisposeTypes.Explicit)
87             {
88                 RemoveAllChildren(true);
89             }
90
91             base.Dispose(type);
92         }
93
94         private void RemoveAllChildren(bool dispose = false)
95         {
96             RecursiveRemoveChildren(this, dispose);
97         }
98
99         private void RecursiveRemoveChildren(View parent, bool dispose)
100         {
101             if (parent == null)
102             {
103                 return;
104             }
105
106             int maxChild = (int)parent.ChildCount;
107             for (int i = maxChild - 1; i >= 0; --i)
108             {
109                 View child = parent.GetChildAt((uint)i);
110                 if (child == null)
111                 {
112                     continue;
113                 }
114
115                 RecursiveRemoveChildren(child, dispose);
116                 parent.Remove(child);
117                 if (dispose)
118                 {
119                     child.Dispose();
120                 }
121             }
122         }
123     }
124 }