Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The following code may encounter issues when using AnimatedVisibility, as the animation is very uneven #224

Open
Kuki93 opened this issue Feb 22, 2024 · 0 comments
Assignees

Comments

@Kuki93
Copy link

Kuki93 commented Feb 22, 2024



@Preview
@Composable
fun AnimatedVisibilityCookbook() {
    var visible1 by remember {
        mutableStateOf(true)
    }

    var visible2 by remember {
        mutableStateOf(true)
    }
    Row(
        modifier = Modifier.padding(top = 20.dp).fillMaxWidth(),
        horizontalArrangement = Arrangement.spacedBy(6.dp)
    ) {
        Button(
            modifier = Modifier,
            onClick = {
                visible1 = !visible1
            },
            shape = RoundedCornerShape(6.dp),
            colors = ButtonDefaults.buttonColors(containerColor = Color.White),
            contentPadding = PaddingValues(horizontal = 8.dp)
        ) {
            Text(
                text = "text",
                color = Color.Black,
                textAlign = TextAlign.Center
            )
        }
        AnimatedVisibility(
            modifier =  Modifier.weight(1f),
            visible = visible1
        ) {
            Button(
                modifier = Modifier,
                onClick = {  },
                shape = RoundedCornerShape(6.dp),
                colors =  ButtonDefaults.buttonColors(containerColor = Color.White),
                contentPadding = PaddingValues(horizontal = 8.dp)
            ) {
                Text(
                    text = "text1",
                    color = Color.Black,
                    textAlign = TextAlign.Center
                )
            }
        }
        AnimatedVisibility(
            modifier = Modifier.weight(1f),
            visible = visible2
        ) {
            Button(
                modifier = Modifier,
                onClick = {  },
                shape = RoundedCornerShape(6.dp),
                colors =  ButtonDefaults.buttonColors(containerColor = Color.White),
                contentPadding = PaddingValues(horizontal = 8.dp)
            ) {
                Text(
                    text = "text2",
                    color = Color.Black,
                    textAlign = TextAlign.Center
                )
            }
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants