Mihai Burlaciuc | 478fae6 | 2019-08-08 10:00:06 +0100 | [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 | |
Siyamed Sinir | fc05929 | 2019-11-21 13:39:17 -0800 | [diff] [blame] | 17 | package androidx.ui.framework.samples |
Mihai Burlaciuc | 478fae6 | 2019-08-08 10:00:06 +0100 | [diff] [blame] | 18 | |
| 19 | import androidx.annotation.Sampled |
| 20 | import androidx.compose.Composable |
Qingqing Deng | 8c5d038 | 2019-09-16 11:59:16 -0700 | [diff] [blame] | 21 | import androidx.ui.core.Alignment |
Siyamed Sinir | fc05929 | 2019-11-21 13:39:17 -0800 | [diff] [blame] | 22 | import androidx.ui.core.DropDownAlignment |
| 23 | import androidx.ui.core.DropdownPopup |
| 24 | import androidx.ui.core.Popup |
Matvei Malkov | 59bac36 | 2020-02-13 20:23:13 +0000 | [diff] [blame] | 25 | import androidx.ui.foundation.Box |
Mihai Burlaciuc | 478fae6 | 2019-08-08 10:00:06 +0100 | [diff] [blame] | 26 | import androidx.ui.foundation.shape.corner.RoundedCornerShape |
| 27 | import androidx.ui.graphics.Color |
Matvei Malkov | 59bac36 | 2020-02-13 20:23:13 +0000 | [diff] [blame] | 28 | import androidx.ui.layout.LayoutSize |
George Mount | 842c8c1 | 2020-01-08 16:03:42 -0800 | [diff] [blame] | 29 | import androidx.ui.unit.dp |
Mihai Burlaciuc | 478fae6 | 2019-08-08 10:00:06 +0100 | [diff] [blame] | 30 | |
| 31 | @Sampled |
| 32 | @Composable |
| 33 | fun PopupSample() { |
Matvei Malkov | 59bac36 | 2020-02-13 20:23:13 +0000 | [diff] [blame] | 34 | Box { |
Mihai Burlaciuc | 478fae6 | 2019-08-08 10:00:06 +0100 | [diff] [blame] | 35 | val popupWidth = 200.dp |
| 36 | val popupHeight = 50.dp |
| 37 | val cornerSize = 16.dp |
| 38 | |
| 39 | Popup(alignment = Alignment.Center) { |
| 40 | // Draw a rectangle shape with rounded corners inside the popup |
Matvei Malkov | 59bac36 | 2020-02-13 20:23:13 +0000 | [diff] [blame] | 41 | Box( |
| 42 | LayoutSize(popupWidth, popupHeight), |
| 43 | shape = RoundedCornerShape(cornerSize), |
| 44 | backgroundColor = Color.White |
| 45 | ) |
Mihai Burlaciuc | 478fae6 | 2019-08-08 10:00:06 +0100 | [diff] [blame] | 46 | } |
| 47 | } |
Mihai Burlaciuc | 49000c6 | 2019-09-17 11:15:47 +0100 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | @Sampled |
| 51 | @Composable |
| 52 | fun DropdownPopupSample() { |
Matvei Malkov | 59bac36 | 2020-02-13 20:23:13 +0000 | [diff] [blame] | 53 | Box(LayoutSize(400.dp, 200.dp)) { |
Mihai Burlaciuc | 49000c6 | 2019-09-17 11:15:47 +0100 | [diff] [blame] | 54 | val popupWidth = 200.dp |
| 55 | val popupHeight = 50.dp |
| 56 | val cornerSize = 16.dp |
| 57 | |
| 58 | // The popup will appear below the parent |
| 59 | DropdownPopup(dropDownAlignment = DropDownAlignment.Left) { |
| 60 | // Draw a rectangle shape with rounded corners inside the popup |
Matvei Malkov | 59bac36 | 2020-02-13 20:23:13 +0000 | [diff] [blame] | 61 | Box( |
| 62 | LayoutSize(popupWidth, popupHeight), |
| 63 | shape = RoundedCornerShape(cornerSize), |
| 64 | backgroundColor = Color.White |
| 65 | ) |
Mihai Burlaciuc | 49000c6 | 2019-09-17 11:15:47 +0100 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | } |