-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
android: style exit node picker per Material UI and add disable button
Updates #ENG-2911 Signed-off-by: Percy Wegmann <[email protected]>
- Loading branch information
Showing
12 changed files
with
377 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
android/src/main/java/com/tailscale/ipn/ui/util/ClickableOrGrayedOut.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) Tailscale Inc & AUTHORS | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
package com.tailscale.ipn.ui.util | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.alpha | ||
import androidx.compose.ui.semantics.Role | ||
|
||
/** | ||
* Similar to Modifier.clickable, but if enabled == false, this adds a 75% alpha to make disabled | ||
* items appear grayed out. | ||
*/ | ||
@Composable | ||
fun Modifier.clickableOrGrayedOut( | ||
enabled: Boolean = true, | ||
onClickLabel: String? = null, | ||
role: Role? = null, | ||
onClick: () -> Unit | ||
) = | ||
if (enabled) { | ||
clickable(onClickLabel = onClickLabel, role = role, onClick = onClick) | ||
} else { | ||
alpha(0.75f) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) Tailscale Inc & AUTHORS | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
package com.tailscale.ipn.ui.util | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.lazy.LazyItemScope | ||
import androidx.compose.foundation.lazy.LazyListScope | ||
import androidx.compose.material3.HorizontalDivider | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
|
||
object Lists { | ||
@Composable | ||
fun SectionDivider() { | ||
Box(Modifier.size(0.dp, 24.dp)) | ||
} | ||
|
||
@Composable | ||
fun ItemDivider() { | ||
HorizontalDivider(color = MaterialTheme.colorScheme.secondaryContainer) | ||
} | ||
} | ||
|
||
/** Similar to items() but includes a horizontal divider between items. */ | ||
inline fun <T> LazyListScope.itemsWithDividers( | ||
items: List<T>, | ||
noinline key: ((item: T) -> Any)? = null, | ||
crossinline contentType: (item: T) -> Any? = { _ -> null }, | ||
crossinline itemContent: @Composable LazyItemScope.(item: T) -> Unit | ||
) = | ||
items( | ||
count = items.size, | ||
key = if (key != null) { index: Int -> key(items[index]) } else null, | ||
contentType = { index -> contentType(items[index]) }) { | ||
if (it > 0 && it < items.size) { | ||
Lists.ItemDivider() | ||
} | ||
itemContent(items[it]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.