Skip to content

Instantly share code, notes, and snippets.

View carterhudson's full-sized avatar

Carter Hudson carterhudson

  • Denver, CO
View GitHub Profile
class PhoneNumberVisualTransformation(locale: Locale = Locale.getDefault()) : VisualTransformation {
private val phoneNumberFormatter =
PhoneNumberUtil.getInstance().getAsYouTypeFormatter(locale.country)
override fun filter(text: AnnotatedString): TransformedText {
phoneNumberFormatter.clear()
var formatted = ""
@Composable
private fun BottomNavigationBar(
modifier: Modifier = Modifier,
currentDestination: Screen,
onClick: (id: Screen) -> Unit
) {
val bottomBarVisible = bottomBarNavDestinations.contains(currentDestination)
AnimatedVisibility(
data class NutritionDateWithFoodItemsEntity(
@Embedded val nutritionDate: NutritionDateEntity,
@Relation(
parentColumn = "epochDay",
entityColumn = "createdAt",
associateBy = Junction(NutritionDateAndFoodItemCrossRefEntity::class)
)
val foodItems: List<FoodItemEntity>
)
fun Modifier.repeatingClickable(
interactionSource: MutableInteractionSource,
enabled: Boolean,
maxDelayMillis: Long = 1000,
minDelayMillis: Long = 5,
delayDecayFactor: Float = .20f,
onClick: () -> Unit
): Modifier = composed {
val currentClickListener by rememberUpdatedState(onClick)
@Preview
@Composable
fun CustomRepeatingButton() {
Box(modifier = Modifier.fillMaxSize()) {
var repeatCount by remember { mutableStateOf(0) }
val interactionSource = remember { MutableInteractionSource() }
Surface(
modifier = Modifier
.repeatingClickable(
fun Modifier.repeatingClickable(
interactionSource: InteractionSource,
enabled: Boolean,
maxDelayMillis: Long = 1000,
minDelayMillis: Long = 5,
delayDecayFactor: Float = .20f,
onClick: () -> Unit
): Modifier = composed {
val currentClickListener by rememberUpdatedState(onClick)
@Composable
fun RepeatingButton(
modifier: Modifier = Modifier,
onClick: () -> Unit,
enabled: Boolean = true,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
elevation: ButtonElevation? = ButtonDefaults.elevation(),
shape: Shape = MaterialTheme.shapes.small,
border: BorderStroke? = null,
colors: ButtonColors = ButtonDefaults.buttonColors(),
@Composable
fun RepeatingButton(
modifier: Modifier = Modifier,
onClick: () -> Unit,
enabled: Boolean = true,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
elevation: ButtonElevation? = ButtonDefaults.elevation(),
shape: Shape = MaterialTheme.shapes.small,
border: BorderStroke? = null,
colors: ButtonColors = ButtonDefaults.buttonColors(),
@Composable
fun RepeatingButton(
modifier: Modifier = Modifier,
onClick: () -> Unit,
enabled: Boolean = true,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
elevation: ButtonElevation? = ButtonDefaults.elevation(),
shape: Shape = MaterialTheme.shapes.small,
border: BorderStroke? = null,
colors: ButtonColors = ButtonDefaults.buttonColors(),
@Composable
fun RepeatingButton(
modifier: Modifier = Modifier,
onClick: () -> Unit,
enabled: Boolean = true,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
elevation: ButtonElevation? = ButtonDefaults.elevation(),
shape: Shape = MaterialTheme.shapes.small,
border: BorderStroke? = null,
colors: ButtonColors = ButtonDefaults.buttonColors(),