-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
137 additions
and
6 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
88 changes: 88 additions & 0 deletions
88
shared/src/commonMain/kotlin/com/bumble/livemosaic/participant/MagicButton.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,88 @@ | ||
@file:Suppress("MagicNumber") | ||
package com.bumble.livemosaic.participant | ||
|
||
import androidx.compose.animation.animateColorAsState | ||
import androidx.compose.animation.core.tween | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.alpha | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.platform.LocalUriHandler | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import kotlinx.coroutines.delay | ||
import kotlin.random.Random | ||
|
||
@Composable | ||
fun MagicButton(modifier: Modifier = Modifier) { | ||
// Generate random colors | ||
fun randomColor(): Color = Color( | ||
red = Random.nextInt(256), | ||
green = Random.nextInt(256), | ||
blue = Random.nextInt(256) | ||
) | ||
|
||
var bgColor by remember { mutableStateOf(randomColor()) } | ||
var textColor by remember { mutableStateOf(randomColor()) } | ||
// Animate color transition | ||
val animatedBgColor by animateColorAsState(targetValue = bgColor, animationSpec = tween(1000)) | ||
val animatedTextColor by animateColorAsState( | ||
targetValue = textColor, | ||
animationSpec = tween(1000) | ||
) | ||
LaunchedEffect(Unit) { | ||
// Change color every 1 second | ||
while (true) { | ||
delay(1000) // wait for 1 second | ||
bgColor = randomColor() | ||
textColor = randomColor() | ||
} | ||
} | ||
val uriHandler = LocalUriHandler.current | ||
Column( | ||
modifier = modifier.fillMaxSize().background(Color.White), | ||
verticalArrangement = Arrangement.Center, | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
Box( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(32.dp) | ||
.clip(shape = RoundedCornerShape(8.dp, 8.dp, 8.dp, 8.dp)) | ||
.background(animatedBgColor) | ||
.clickable { | ||
// Redirect to the website | ||
uriHandler.openUri("https://bumble-tech.github.io/appyx/") | ||
}, | ||
contentAlignment = Alignment.Center | ||
) { | ||
Text( | ||
text = "Click me!", | ||
color = animatedTextColor, | ||
fontSize = 22.sp, | ||
fontWeight = FontWeight.Bold, | ||
textAlign = TextAlign.Center, | ||
modifier = Modifier.padding(16.dp).alpha(1f).align(Alignment.Center) | ||
) | ||
} | ||
|
||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.