[go: nahoru, domu]

blob: 508a5cbf662872727797bb8bb573f65308f4e82c [file] [log] [blame]
shepshapard0cc02c42019-06-28 15:51:14 -07001/*
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
George Mount54370f12020-05-06 16:03:20 -070017package androidx.ui.core.demos.gestures
shepshapard0cc02c42019-06-28 15:51:14 -070018
Louis Pullen-Freilicha228adf2020-03-11 18:42:11 +000019import androidx.compose.Composable
shepshapard0cc02c42019-06-28 15:51:14 -070020import androidx.compose.state
Adam Powell999a89b2020-03-11 09:08:07 -070021import androidx.ui.core.Alignment
22import androidx.ui.core.Modifier
Shep Shapard70a8cfe2020-03-30 16:17:26 -070023import androidx.ui.core.gesture.tapGestureFilter
Matvei Malkov0e4dc6d2020-02-19 15:11:59 +000024import androidx.ui.foundation.Border
25import androidx.ui.foundation.Box
Shep Shapard07c9e2c2020-05-21 16:44:25 -070026import androidx.ui.foundation.Text
27import androidx.ui.layout.Column
Adam Powell999a89b2020-03-11 09:08:07 -070028import androidx.ui.layout.fillMaxSize
29import androidx.ui.layout.preferredSize
30import androidx.ui.layout.wrapContentSize
Shep Shaparde7d051f2020-05-13 15:19:16 -070031import androidx.ui.unit.PxPosition
George Mount842c8c12020-01-08 16:03:42 -080032import androidx.ui.unit.dp
shepshapard0cc02c42019-06-28 15:51:14 -070033
34/**
Shep Shapard07c9e2c2020-05-21 16:44:25 -070035 * Simple [tapGestureFilter] demo.
shepshapard0cc02c42019-06-28 15:51:14 -070036 */
Louis Pullen-Freilicha228adf2020-03-11 18:42:11 +000037@Composable
Shep Shapard07c9e2c2020-05-21 16:44:25 -070038fun TapGestureFilterDemo() {
Louis Pullen-Freilicha228adf2020-03-11 18:42:11 +000039 val color = state { Colors.random() }
shepshapard0cc02c42019-06-28 15:51:14 -070040
Shep Shaparde7d051f2020-05-13 15:19:16 -070041 val onTap: (PxPosition) -> Unit = {
Louis Pullen-Freilicha228adf2020-03-11 18:42:11 +000042 color.value = color.value.anotherRandomColor()
43 }
shepshapard0cc02c42019-06-28 15:51:14 -070044
Shep Shapard07c9e2c2020-05-21 16:44:25 -070045 Column {
46 Text("The box changes color when you tap it.")
47 Box(
48 Modifier.fillMaxSize()
49 .wrapContentSize(Alignment.Center)
50 .tapGestureFilter(onTap)
51 .preferredSize(192.dp),
52 backgroundColor = color.value,
53 border = Border(2.dp, BorderColor)
54 )
55 }
Shep Shapard89316462020-03-03 17:00:52 -080056}