-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- do not allow avatar click when user is already on settings
- visually show click is not avail by reducing oppacity - added avatar shining animation gradient [Ticket: X]
- Loading branch information
Showing
2 changed files
with
93 additions
and
5 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
...in/kotlin/network/bisq/mobile/presentation/ui/components/atoms/animations/ShineOverlay.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,76 @@ | ||
package network.bisq.mobile.presentation.ui.components.atoms.animations | ||
|
||
import androidx.compose.animation.core.* | ||
import androidx.compose.foundation.Canvas | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.shape.CircleShape | ||
import androidx.compose.foundation.layout.BoxScope | ||
import androidx.compose.runtime.* | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.geometry.Offset | ||
import androidx.compose.ui.graphics.* | ||
import kotlin.random.Random | ||
|
||
const val INITIAL_SHINE = -1.0f | ||
const val TARGET_SHINE = 3f | ||
const val ANIMATION_INTERVAL = 5000 | ||
const val ANIMATION_MAX_INTERVAL = 10001 | ||
const val GRADIENT_OFFSET_FACTOR = 300f | ||
|
||
fun nextDuration(): Int = Random.nextInt(ANIMATION_INTERVAL, ANIMATION_MAX_INTERVAL) | ||
|
||
@Composable | ||
fun ShineOverlay( | ||
modifier: Modifier = Modifier, | ||
content: @Composable BoxScope.() -> Unit | ||
) { | ||
|
||
val randomDuration = remember { mutableStateOf(nextDuration()) } | ||
|
||
val infiniteTransition = rememberInfiniteTransition() | ||
val gradientOffset by infiniteTransition.animateFloat( | ||
initialValue = INITIAL_SHINE, | ||
targetValue = TARGET_SHINE, | ||
animationSpec = infiniteRepeatable( | ||
animation = tween(durationMillis = randomDuration.value, easing = LinearEasing), | ||
repeatMode = RepeatMode.Restart | ||
) | ||
) | ||
|
||
LaunchedEffect(gradientOffset) { | ||
if (gradientOffset == TARGET_SHINE) { | ||
randomDuration.value = nextDuration() | ||
} | ||
} | ||
|
||
// Gradient brush that moves across the composable | ||
val gradientBrush = Brush.linearGradient( | ||
colors = listOf( | ||
Color.Transparent, | ||
Color.White.copy(alpha = 0.3f), // Shine effect | ||
Color.Transparent | ||
), | ||
start = Offset(gradientOffset * GRADIENT_OFFSET_FACTOR, gradientOffset * GRADIENT_OFFSET_FACTOR), | ||
end = Offset((gradientOffset + 1) * GRADIENT_OFFSET_FACTOR, (gradientOffset + 1) * GRADIENT_OFFSET_FACTOR) | ||
) | ||
|
||
// Layer composable with shine overlay | ||
Box( | ||
modifier = modifier | ||
.clip(CircleShape), | ||
contentAlignment = Alignment.Center | ||
) { | ||
// UserIcon composable | ||
content() | ||
|
||
// Canvas for the moving shine gradient | ||
Canvas( | ||
modifier = Modifier | ||
.matchParentSize() | ||
.clip(CircleShape)) { | ||
drawRect(brush = gradientBrush) | ||
} | ||
} | ||
} |
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