Instantly share code, notes, and snippets.
Created
November 4, 2025 06:31
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
-
Save dev778g-me/34dea604486ca64c96e8f5ffb54d42d4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package com.example.chromeui | |
| import androidx.compose.animation.core.Animatable | |
| import androidx.compose.animation.core.spring | |
| import androidx.compose.foundation.background | |
| import androidx.compose.foundation.border | |
| import androidx.compose.foundation.clickable | |
| import androidx.compose.foundation.gestures.awaitEachGesture | |
| import androidx.compose.foundation.gestures.awaitFirstDown | |
| import androidx.compose.foundation.gestures.waitForUpOrCancellation | |
| import androidx.compose.foundation.interaction.MutableInteractionSource | |
| import androidx.compose.foundation.layout.Box | |
| import androidx.compose.foundation.layout.fillMaxSize | |
| import androidx.compose.foundation.layout.fillMaxWidth | |
| import androidx.compose.foundation.layout.padding | |
| import androidx.compose.foundation.shape.RoundedCornerShape | |
| import androidx.compose.material3.MaterialTheme | |
| import androidx.compose.material3.Text | |
| import androidx.compose.runtime.Composable | |
| import androidx.compose.runtime.remember | |
| import androidx.compose.runtime.rememberCoroutineScope | |
| import androidx.compose.ui.Alignment | |
| import androidx.compose.ui.Modifier | |
| import androidx.compose.ui.draw.clip | |
| import androidx.compose.ui.draw.shadow | |
| import androidx.compose.ui.graphics.Brush | |
| import androidx.compose.ui.graphics.Color | |
| import androidx.compose.ui.graphics.graphicsLayer | |
| import androidx.compose.ui.input.pointer.pointerInput | |
| import androidx.compose.ui.text.style.LineHeightStyle | |
| import androidx.compose.ui.unit.dp | |
| import androidx.compose.ui.unit.lerp | |
| import kotlinx.coroutines.launch | |
| @Composable | |
| fun ChromeButton(modifier: Modifier = Modifier,text: String) { | |
| val scope = rememberCoroutineScope() | |
| val progress = remember { Animatable(0f) } | |
| val primary = MaterialTheme.colorScheme.primary | |
| val onPrimary = MaterialTheme.colorScheme.onPrimary | |
| val secondary = MaterialTheme.colorScheme.secondary | |
| Box( | |
| modifier = modifier | |
| .graphicsLayer { | |
| val pr = progress.value | |
| val maxScale = (size.width + 16f.dp.toPx()) / size.width | |
| val scale = androidx.compose.ui.util.lerp(1f, maxScale, pr) | |
| scaleY = scale | |
| scaleX = scale | |
| } | |
| .fillMaxWidth() | |
| .padding( | |
| horizontal = 34.dp | |
| ) | |
| .shadow( | |
| elevation = 20.dp, | |
| shape = RoundedCornerShape(34.dp) | |
| ) | |
| .border( | |
| brush = Brush.verticalGradient( | |
| colors = listOf( | |
| onPrimary, | |
| primary, | |
| secondary | |
| ) | |
| ), | |
| width = 4.dp, | |
| shape = RoundedCornerShape(34.dp) | |
| ) | |
| .background( | |
| brush = Brush.verticalGradient( | |
| colors = listOf( | |
| onPrimary, | |
| primary | |
| ), | |
| ), shape = RoundedCornerShape(34.dp) | |
| ) | |
| .clip(RoundedCornerShape(34.dp)) | |
| .clickable( | |
| onClick = {}, | |
| indication = null, | |
| interactionSource = remember { MutableInteractionSource() }) | |
| .pointerInput(scope) { | |
| val animation = spring(0.5f, 300f, 0.002f) | |
| awaitEachGesture { | |
| awaitFirstDown() | |
| scope.launch { | |
| progress.animateTo(1f, animation) | |
| } | |
| waitForUpOrCancellation() | |
| scope.launch { | |
| progress.animateTo(0f, animation) | |
| } | |
| } | |
| } | |
| , | |
| contentAlignment = Alignment.Center | |
| ) { | |
| Text( | |
| modifier = modifier.padding( | |
| vertical = 16.dp | |
| ), | |
| text = text, | |
| style = MaterialTheme.typography.titleMedium.copy( | |
| brush = Brush.verticalGradient( | |
| colors = listOf( | |
| Color(0xFF252424), | |
| Color(0xFF3C3C3C) | |
| ) | |
| ) | |
| ) | |
| ) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment