1 /*
2  * Copyright 2022 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.ui.inspection.testdata
18 
19 import android.os.Bundle
20 import androidx.activity.ComponentActivity
21 import androidx.activity.compose.setContent
22 import androidx.compose.foundation.layout.Column
23 import androidx.compose.foundation.layout.Row
24 import androidx.compose.foundation.layout.padding
25 import androidx.compose.material.Button
26 import androidx.compose.material.Text
27 import androidx.compose.runtime.mutableStateOf
28 import androidx.compose.runtime.remember
29 import androidx.compose.ui.Alignment
30 import androidx.compose.ui.Modifier
31 import androidx.compose.ui.unit.dp
32 
33 class RecompositionTestActivity : ComponentActivity() {
onCreatenull34     override fun onCreate(savedInstanceState: Bundle?) {
35         super.onCreate(savedInstanceState)
36         setContent {
37             Column {
38                 Row {
39                     val clickCount1 = remember { mutableStateOf(0) }
40                     Column {
41                         Button(
42                             onClick = { clickCount1.value = clickCount1.value + 1 },
43                             modifier = Modifier.padding(16.dp, 4.dp)
44                         ) {
45                             Text("Click row 1")
46                         }
47                     }
48                     Column(modifier = Modifier.align(Alignment.CenterVertically)) {
49                         Text("Row 1 click count: ${clickCount1.value}")
50                     }
51                 }
52                 Row {
53                     val clickCount2 = remember { mutableStateOf(0) }
54                     Column {
55                         Button(
56                             onClick = { clickCount2.value = clickCount2.value + 1 },
57                             modifier = Modifier.padding(16.dp, 4.dp)
58                         ) {
59                             Text("Click row 2")
60                         }
61                     }
62                     Column(modifier = Modifier.align(Alignment.CenterVertically)) {
63                         Text("Row 2 click count: ${clickCount2.value}")
64                     }
65                 }
66             }
67         }
68     }
69 }
70