[go: nahoru, domu]

blob: 259973fa1d484ac17ac8d579e84a81a16608dc5f [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 Shapard78f42892020-05-20 16:02:06 -070023import androidx.ui.core.clipToBounds
Shep Shapard70a8cfe2020-03-30 16:17:26 -070024import androidx.ui.core.gesture.tapGestureFilter
Louis Pullen-Freilichddda7be2020-07-17 18:28:12 +010025import androidx.compose.foundation.Border
26import androidx.compose.foundation.Box
27import androidx.compose.foundation.Text
Louis Pullen-Freilich623e4052020-07-19 20:24:03 +010028import androidx.compose.foundation.layout.Column
29import androidx.compose.foundation.layout.fillMaxSize
30import androidx.compose.foundation.layout.preferredSize
31import androidx.compose.foundation.layout.wrapContentSize
Nader Jawad6df06122020-06-03 15:27:08 -070032import androidx.ui.geometry.Offset
George Mount842c8c12020-01-08 16:03:42 -080033import androidx.ui.unit.dp
shepshapard0cc02c42019-06-28 15:51:14 -070034
35/**
Shep Shapard07c9e2c2020-05-21 16:44:25 -070036 * Simple [tapGestureFilter] demo.
shepshapard0cc02c42019-06-28 15:51:14 -070037 */
Louis Pullen-Freilicha228adf2020-03-11 18:42:11 +000038@Composable
Shep Shapard07c9e2c2020-05-21 16:44:25 -070039fun TapGestureFilterDemo() {
Louis Pullen-Freilicha228adf2020-03-11 18:42:11 +000040 val color = state { Colors.random() }
shepshapard0cc02c42019-06-28 15:51:14 -070041
Nader Jawad6df06122020-06-03 15:27:08 -070042 val onTap: (Offset) -> Unit = {
Louis Pullen-Freilicha228adf2020-03-11 18:42:11 +000043 color.value = color.value.anotherRandomColor()
44 }
shepshapard0cc02c42019-06-28 15:51:14 -070045
Shep Shapard07c9e2c2020-05-21 16:44:25 -070046 Column {
47 Text("The box changes color when you tap it.")
48 Box(
49 Modifier.fillMaxSize()
50 .wrapContentSize(Alignment.Center)
Shep Shapard78f42892020-05-20 16:02:06 -070051 .preferredSize(192.dp)
Shep Shapard07c9e2c2020-05-21 16:44:25 -070052 .tapGestureFilter(onTap)
Shep Shapard78f42892020-05-20 16:02:06 -070053 .clipToBounds(),
Shep Shapard07c9e2c2020-05-21 16:44:25 -070054 backgroundColor = color.value,
55 border = Border(2.dp, BorderColor)
56 )
57 }
Shep Shapard89316462020-03-03 17:00:52 -080058}