Mehdi Haghgoo
03/22/2021, 7:29 PMMehdi Haghgoo
03/22/2021, 7:44 PMMehdi Haghgoo
03/22/2021, 7:45 PM@Composable
fun BottomBar(navController: NavHostController) {
var selectedItem by mutableStateOf("home")
BottomAppBar(Modifier.fillMaxWidth()) {
Icon(Icons.Outlined.Home, contentDescription = "Home",
Modifier
.clickable { navController.navigate("home"); selectedItem = "home" }
.weight(1f)
.size(if(selectedItem == "home") 32.dp else 24.dp)
.animateContentSize()
)
Icon(Icons.Outlined.Person, contentDescription = "Profile",
Modifier
.clickable { navController.navigate("profile"); selectedItem = "profile" }
.weight(1f)
.size(if(selectedItem == "profile") 32.dp else 24.dp)
.animateContentSize()
)
Icon(painterResource(id = R.drawable.balance), contentDescription = "Balance",
Modifier
.clickable { navController.navigate("balance"); selectedItem = "balance" }
.weight(1f)
.size(if(selectedItem == "balance") 32.dp else 24.dp)
.animateContentSize()
)
Icon(Icons.Outlined.Settings, contentDescription = "Settings",
Modifier
.clickable { navController.navigate("settings"); selectedItem = "settings" }
.weight(1f)
.size(if(selectedItem == "settings") 32.dp else 24.dp)
.animateContentSize()
)
}
}
Doris Liu
03/22/2021, 8:39 PManimateDpAsState
. animateContentSize changes the content instantly while only animating the container sizeMehdi Haghgoo
03/23/2021, 4:16 AMMehdi Haghgoo
03/23/2021, 6:57 AM@Composable
fun BottomBar(navController: NavHostController) {
var selectedItem by mutableStateOf("home")
val smSize by animateDpAsState(targetValue = 24.dp)
val bgSize by animateDpAsState(targetValue = 32.dp)
BottomAppBar(Modifier.fillMaxWidth()) {
Icon(Icons.Outlined.Home, contentDescription = "Home",
Modifier
.clickable { navController.navigate("home"); selectedItem = "home" }
.weight(1f)
.size(if (selectedItem == "home") bgSize else smSize)
// .animateContentSize()
)
Icon(Icons.Outlined.Person, contentDescription = "Profile",
Modifier
.clickable { navController.navigate("profile"); selectedItem = "profile" }
.weight(1f)
.size(if (selectedItem == "profile") bgSize else smSize)
// .animateContentSize()
)
Icon(painterResource(id = R.drawable.balance), contentDescription = "Balance",
Modifier
.clickable { navController.navigate("balance"); selectedItem = "balance" }
.weight(1f)
.size(if (selectedItem == "balance") bgSize else smSize)
// .animateContentSize()
)
Icon(Icons.Outlined.Settings, contentDescription = "Settings",
Modifier
.clickable { navController.navigate("settings"); selectedItem = "settings" }
.weight(1f)
.size(if (selectedItem == "settings") bgSize else smSize)
// .animateContentSize()
)
}
}
Mehdi Haghgoo
03/23/2021, 7:16 AM