[NUI][NUITizenGallery] add Animal ListView and GridView examples
[platform/core/csapi/tizenfx.git] / test / NUITizenGallery / Examples / CollectionViewTest / AnimalGridPage.cs
1 /*
2  * Copyright(c) 2022 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.ComponentModel;
19 using Tizen.NUI;
20 using Tizen.NUI.Binding;
21 using Tizen.NUI.BaseComponents;
22 using Tizen.NUI.Components;
23 using Tizen.NUI.Components.Extension;
24
25 namespace NUITizenGallery
26 {
27     public partial class AnimalGridPage : ContentPage
28     {
29         public AnimalGridPage()
30         {
31             InitializeComponent();
32             BindingContext = new Animals();
33         }
34
35         protected override void Dispose(DisposeTypes type)
36         {
37             if (Disposed)
38             {
39                 return;
40             }
41
42             if (type == DisposeTypes.Explicit)
43             {
44                 RemoveAllChildren(true);
45             }
46
47             base.Dispose(type);
48         }
49
50         private void RemoveAllChildren(bool dispose = false)
51         {
52             RecursiveRemoveChildren(this, dispose);
53         }
54
55         private void RecursiveRemoveChildren(View parent, bool dispose)
56         {
57             if (parent == null)
58             {
59                 return;
60             }
61
62             int maxChild = (int)parent.ChildCount;
63             for (int i = maxChild - 1; i >= 0; --i)
64             {
65                 View child = parent.GetChildAt((uint)i);
66                 if (child == null)
67                 {
68                     continue;
69                 }
70
71                 RecursiveRemoveChildren(child, dispose);
72                 parent.Remove(child);
73                 if (dispose)
74                 {
75                     child.Dispose();
76                 }
77             }
78         }
79     }
80 }