1 /*
2  * Copyright 2019 The Android Open Source Project
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 package androidx.compose.runtime.mock
18 
19 import androidx.compose.runtime.AbstractApplier
20 
21 @Suppress("EXTENSION_SHADOWED_BY_MEMBER")
22 class ViewApplier(root: View) : AbstractApplier<View>(root) {
23     var called = false
24 
25     var onBeginChangesCalled = 0
26         private set
27 
28     var onEndChangesCalled = 0
29         private set
30 
insertTopDownnull31     override fun insertTopDown(index: Int, instance: View) {
32         // Ignored as the tree is built bottom-up.
33         called = true
34     }
35 
insertBottomUpnull36     override fun insertBottomUp(index: Int, instance: View) {
37         current.addAt(index, instance)
38         called = true
39     }
40 
removenull41     override fun remove(index: Int, count: Int) {
42         current.removeAt(index, count)
43         called = true
44     }
45 
movenull46     override fun move(from: Int, to: Int, count: Int) {
47         current.moveAt(from, to, count)
48         called = true
49     }
50 
onClearnull51     override fun onClear() {
52         root.removeAllChildren()
53         called = true
54     }
55 
onBeginChangesnull56     override fun onBeginChanges() {
57         onBeginChangesCalled++
58         called = true
59     }
60 
onEndChangesnull61     override fun onEndChanges() {
62         onEndChangesCalled++
63         called = true
64     }
65 
66     override var current: View
<lambda>null67         get() = super.current.also { if (it != root) called = true }
68         set(value) {
69             super.current = value
70             called = true
71         }
72 
downnull73     override fun down(node: View) {
74         super.down(node)
75         called = true
76     }
77 
upnull78     override fun up() {
79         super.up()
80         called = true
81     }
82 }
83