Skip to content

Instantly share code, notes, and snippets.

@CostaFot
Created March 13, 2024 01:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CostaFot/1f3f6c1e8c74909c2a29bc56fda85deb to your computer and use it in GitHub Desktop.
Save CostaFot/1f3f6c1e8c74909c2a29bc56fda85deb to your computer and use it in GitHub Desktop.
@Composable
private fun MainContent(
changeSystemBarStyle: (SystemBarStyle) -> Unit
) {
Scaffold(
modifier = Modifier.fillMaxSize(),
containerColor = Color.Black
) { paddingValues ->
LaunchedEffect(Unit) {
changeSystemBarStyle(SystemBarStyle.dark(android.graphics.Color.TRANSPARENT))
}
val layoutDirection = LocalLayoutDirection.current
Box(
modifier = Modifier
.fillMaxSize()
.padding(
start = paddingValues.calculateStartPadding(layoutDirection),
end = paddingValues.calculateEndPadding(layoutDirection),
bottom = paddingValues.calculateBottomPadding(),
)
) {
Column(
modifier = Modifier.fillMaxSize()
) {
var alpha by remember {
mutableFloatStateOf(0f)
}
val color by remember(alpha) {
logDebug { alpha.toString() }
mutableStateOf(Color.Red.copy(alpha = alpha))
}
val animatedColor by animateColorAsState(targetValue = color, label = "")
Spacer(
modifier = Modifier
.windowInsetsTopHeight(WindowInsets.statusBars)
.fillMaxWidth()
.background(animatedColor)
)
BoxWithConstraints(
modifier = Modifier.fillMaxSize()
) {
val minimumBoxHeight = 200.dp
val maximumBoxHeight = maxHeight // stop before covering the status bar
var boxHeight by remember {
mutableStateOf(minimumBoxHeight)
}
LaunchedEffect(boxHeight) {
alpha = (boxHeight / maximumBoxHeight).coerceIn(0f, 1f)
}
Box(
modifier = Modifier
.fillMaxWidth()
.height(boxHeight)
.background(Color.White)
.align(Alignment.BottomCenter)
.pointerInput(Unit) {
detectVerticalDragGestures { change, dragAmount ->
if (dragAmount < 0f) { // dragging up
if (boxHeight >= maximumBoxHeight) {
boxHeight = maximumBoxHeight
} else {
if (boxHeight <= maxHeight) {
boxHeight += 6.dp
}
}
} else if (dragAmount > 0f) { // dragging down
if (boxHeight <= minimumBoxHeight) {
boxHeight = minimumBoxHeight
} else {
boxHeight -= 6.dp
}
}
}
}
) {
Image(
painter = painterResource(id = R.drawable.cheems),
contentDescription = null,
modifier = Modifier
.size(boxHeight)
.align(Alignment.Center)
)
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment