Radu - Ionut Kurta
07/26/2021, 8:33 AMnitrog42
07/26/2021, 12:17 PMnitrog42
07/26/2021, 12:22 PMRadu - Ionut Kurta
07/26/2021, 12:44 PMclass MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
ComposeApplicationTheme {
val scope = rememberCoroutineScope()
var route by remember { mutableStateOf("home") }
Scaffold(topBar = {
TopAppBar(title = { Text("Simple TopAppBar") },navigationIcon = {
if(route == "home") {
IconButton(onClick = {
route = "profile"
// scope.launch { afterAnimation { route = "profile" } }
}) {
Icon(Icons.Filled.Person, contentDescription = null)
}
} else {
IconButton(onClick = {
route = "home"
// scope.launch { afterAnimation { route = "home" } }
}) {
Icon(Icons.Filled.ArrowBack, contentDescription = null)
}
}
})
}) {
Text("Content")
}
}
}
}
}
suspend fun afterAnimation(run: () -> Unit) {
delay(150).also { run() }
}
a simple way to reproduce try running the code once with just route = "something" part and then swap with the commented scope.launch part in the first case the ripple wont play for the icon button and the re-composition makes for a hard visual transition while the second one looks better, it feels like a weird way to handle a click just to get the default animation to finishRadu - Ionut Kurta
07/26/2021, 12:49 PMRadu - Ionut Kurta
07/26/2021, 12:49 PMclass MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
ComposeApplicationTheme {
var route by remember { mutableStateOf("home") }
Scaffold(topBar = {
TopAppBar(title = { Text("Simple TopAppBar") },navigationIcon = {
IconButton(onClick = {
route = if(route == "home") {
"profile"
} else {
"home"
}
}) {
if(route == "home") {
Icon(Icons.Filled.Person, contentDescription = null)
} else {
Icon(Icons.Filled.ArrowBack, contentDescription = null)
}
}
})
}) {
Text("Content")
}
}
}
}
}
Radu - Ionut Kurta
07/26/2021, 12:50 PM