1

I want to use verticalArrangement = Arrangement.SpaceBetween in Column to align view top and bottom. I did this before without any problem. Now I added AnimatedVisibility to look good animation when my condition true. But It overlapping the view. I can't understand that things.

PairContentStateLess

@Composable
fun PairContentStateLess(
    viewModel: XyzPairViewModel,
    scanning: State<Boolean>,
    onResume: () -> Unit,
    onPause: () -> Unit,
    tryAgainAction: () -> Unit,
    openSettingAction: () -> Unit,
    onResumeScan: () -> Unit,
    onPauseScan: () -> Unit,
) {
    AnimatedVisibility(visible = true) {
        AppBarScaffold() {
            Column(
                modifier = Modifier
                    .padding(10.dp)
                    .fillMaxSize()
                    .verticalScroll(rememberScrollState()),
                horizontalAlignment = Alignment.CenterHorizontally,
                verticalArrangement = if (viewModel.isBluetoothEnabled && scanning.value) {
                    Arrangement.Top
                } else {
                    Arrangement.SpaceBetween
                }
            ) {
                PairScreenImage()
                PairDeviceDescription()
                if (viewModel.isBluetoothEnabled) {
                    PressAndHoldDescription()
                    WaitingToPair(scanning.value)
                    UnableToPair(scanning.value)
                } else {
                    BluetoothTurnOnWarning()
                    Spacer(modifier = Modifier.weight(1f))
                    TryAgainButtonView { tryAgainAction() }
                    OpenDeviceSettingsButtonView { openSettingAction() }
                }
            }
        }
    }
}

I am only adding UnableToPair code now. If I am using it working fine without any problem.

UnableToPair

fun ColumnScope.UnableToPair(scanning: Boolean) {
    if (!scanning) {
        WarningBoxView()
        Spacer(modifier = Modifier.weight(1f))
        TryAgainButtonView {

        }
    }
}

UI look like this

enter image description here

Now main problems come

when I tried to use AnimatedVisibility. I don't know what happened in the WarningBoxView and TryAgainButtonView.

@Composable
fun ColumnScope.UnableToPair(scanning: Boolean) {
   AnimatedVisibility (!scanning) {
        WarningBoxView()
        Spacer(modifier = Modifier.weight(1f))
        TryAgainButtonView {

        }
    }
}

UI look like this and I hide sensitive data from black box in image. Please notice only button and warning box.

enter image description here

Thanks

Kotlin Learner
  • 3,995
  • 6
  • 47
  • 127
  • Does this answer your question? [Spacer not working correctly in nested function in jetpack compose](https://stackoverflow.com/questions/74020353/spacer-not-working-correctly-in-nested-function-in-jetpack-compose) – z.g.y Oct 11 '22 at 10:10
  • no this is wrong. I deleted that question as well. – Kotlin Learner Oct 11 '22 at 10:14

0 Answers0