shepshapard | 0cc02c4 | 2019-06-28 15:51:14 -0700 | [diff] [blame] | 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 | |
George Mount | 54370f1 | 2020-05-06 16:03:20 -0700 | [diff] [blame] | 17 | package androidx.ui.core.demos.gestures |
shepshapard | 0cc02c4 | 2019-06-28 15:51:14 -0700 | [diff] [blame] | 18 | |
Louis Pullen-Freilich | a228adf | 2020-03-11 18:42:11 +0000 | [diff] [blame] | 19 | import androidx.compose.Composable |
shepshapard | 0cc02c4 | 2019-06-28 15:51:14 -0700 | [diff] [blame] | 20 | import androidx.compose.state |
Adam Powell | 999a89b | 2020-03-11 09:08:07 -0700 | [diff] [blame] | 21 | import androidx.ui.core.Alignment |
| 22 | import androidx.ui.core.Modifier |
Shep Shapard | 78f4289 | 2020-05-20 16:02:06 -0700 | [diff] [blame] | 23 | import androidx.ui.core.clipToBounds |
Shep Shapard | 70a8cfe | 2020-03-30 16:17:26 -0700 | [diff] [blame] | 24 | import androidx.ui.core.gesture.tapGestureFilter |
Louis Pullen-Freilich | ddda7be | 2020-07-17 18:28:12 +0100 | [diff] [blame] | 25 | import androidx.compose.foundation.Border |
| 26 | import androidx.compose.foundation.Box |
| 27 | import androidx.compose.foundation.Text |
Louis Pullen-Freilich | 623e405 | 2020-07-19 20:24:03 +0100 | [diff] [blame] | 28 | import androidx.compose.foundation.layout.Column |
| 29 | import androidx.compose.foundation.layout.fillMaxSize |
| 30 | import androidx.compose.foundation.layout.preferredSize |
| 31 | import androidx.compose.foundation.layout.wrapContentSize |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 32 | import androidx.ui.geometry.Offset |
George Mount | 842c8c1 | 2020-01-08 16:03:42 -0800 | [diff] [blame] | 33 | import androidx.ui.unit.dp |
shepshapard | 0cc02c4 | 2019-06-28 15:51:14 -0700 | [diff] [blame] | 34 | |
| 35 | /** |
Shep Shapard | 07c9e2c | 2020-05-21 16:44:25 -0700 | [diff] [blame] | 36 | * Simple [tapGestureFilter] demo. |
shepshapard | 0cc02c4 | 2019-06-28 15:51:14 -0700 | [diff] [blame] | 37 | */ |
Louis Pullen-Freilich | a228adf | 2020-03-11 18:42:11 +0000 | [diff] [blame] | 38 | @Composable |
Shep Shapard | 07c9e2c | 2020-05-21 16:44:25 -0700 | [diff] [blame] | 39 | fun TapGestureFilterDemo() { |
Louis Pullen-Freilich | a228adf | 2020-03-11 18:42:11 +0000 | [diff] [blame] | 40 | val color = state { Colors.random() } |
shepshapard | 0cc02c4 | 2019-06-28 15:51:14 -0700 | [diff] [blame] | 41 | |
Nader Jawad | 6df0612 | 2020-06-03 15:27:08 -0700 | [diff] [blame] | 42 | val onTap: (Offset) -> Unit = { |
Louis Pullen-Freilich | a228adf | 2020-03-11 18:42:11 +0000 | [diff] [blame] | 43 | color.value = color.value.anotherRandomColor() |
| 44 | } |
shepshapard | 0cc02c4 | 2019-06-28 15:51:14 -0700 | [diff] [blame] | 45 | |
Shep Shapard | 07c9e2c | 2020-05-21 16:44:25 -0700 | [diff] [blame] | 46 | Column { |
| 47 | Text("The box changes color when you tap it.") |
| 48 | Box( |
| 49 | Modifier.fillMaxSize() |
| 50 | .wrapContentSize(Alignment.Center) |
Shep Shapard | 78f4289 | 2020-05-20 16:02:06 -0700 | [diff] [blame] | 51 | .preferredSize(192.dp) |
Shep Shapard | 07c9e2c | 2020-05-21 16:44:25 -0700 | [diff] [blame] | 52 | .tapGestureFilter(onTap) |
Shep Shapard | 78f4289 | 2020-05-20 16:02:06 -0700 | [diff] [blame] | 53 | .clipToBounds(), |
Shep Shapard | 07c9e2c | 2020-05-21 16:44:25 -0700 | [diff] [blame] | 54 | backgroundColor = color.value, |
| 55 | border = Border(2.dp, BorderColor) |
| 56 | ) |
| 57 | } |
Shep Shapard | 8931646 | 2020-03-03 17:00:52 -0800 | [diff] [blame] | 58 | } |