MainActivity.kt
package com.cfsuman.jetpackcompose
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.compose.animation.core.*
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MainContent()
}
}
@Composable
fun MainContent(){
val isEnabled = remember { mutableStateOf(true) }
val isCollapsed = remember { mutableStateOf(true) }
val size: Dp by animateDpAsState(
targetValue = if (isCollapsed.value) 100.dp else 300.dp,
animationSpec = tween(
durationMillis = 3000, // duration
delayMillis = 2000, // delay before start animation
easing = FastOutSlowInEasing
),
finishedListener = {
// disable the button
isEnabled.value = true
}
)
Column(
modifier = Modifier
.fillMaxSize()
.background(Color(0xFFFFDDF4))
.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Button(
onClick = {
isCollapsed.value = !isCollapsed.value
isEnabled.value = false
},
colors = ButtonDefaults.buttonColors(
Color(0xFF2A2F23), Color(0xCCFFFFFF)
),
enabled = isEnabled.value
) {
Text(
text = "Animate Size Change",
modifier = Modifier.padding(12.dp)
)
}
Icon(
Icons.Filled.Favorite,
contentDescription = "Localized description",
Modifier.size(size),
tint = Color(0xFFFF355E)
)
}
}
@Preview
@Composable
fun ComposablePreview(){
//MainContent()
}
}
- jetpack compose - Image shape
- jetpack compose - Image tint
- jetpack compose - Image from assets folder
- jetpack compose - How to use LazyColumn
- jetpack compose - Accessing string resources
- jetpack compose - String resource positional formatting
- jetpack compose - Text custom font
- jetpack compose - Accessing font resource
- jetpack compose - LazyColumn scroll to top bottom
- jetpack compose - LazyColumn smooth scrolling
- jetpack compose - Animate content size
- jetpack compose - Infinite float animation
- jetpack compose - Rotate animation
- jetpack compose - Make Text clickable
- jetpack compose - Draw line on Canvas