0

I have a composable in my app that can render the contents of a directory:

    EntriesListing(
        directoryListing,
        renderUpButton = uiState.value.directory != Path.Empty,
        navigateUp = {
            uiState.value = UiState(
                lastDirectory = uiState.value.directory,
                directory = uiState.value.directory.parent(),
            )
        },
        navigateDown = {
            uiState.value = UiState(
                uiState.value.dirStack + listOf(uiState.value.directory.join(it.name)!!),
                lastDirectory = uiState.value.directory,
                directory = uiState.value.directory.join(it.name),
            )
        },
        selectNote = {

        },
    )

This view works as expected. Now I want to animate this view when the user selects a directory or goes to the parent directory. I tried a Box with two AnimatedContents:

    Box {
        key(uiState.value.lastDirectory) {
            AnimatedVisibility(visible = false) {
                DirView(uiState, uiState.value.lastDirectory)
            }
        }
        key(uiState.value.directory) {
            AnimatedVisibility(visible = true) {
                DirView(uiState, uiState.value.directory)
            }
        }
    }

But it's not working. Only the current directory content is displayed without any transitions. How do I implement that?

thewolf
  • 417
  • 1
  • 5
  • 10
  • check out [this answer](https://stackoverflow.com/a/71206842/3585796) – Phil Dukhov Apr 22 '22 at 08:03
  • I was aware of this. That's why I added the key composable. When the use clicks on a directory, the current `directory` becomes `lastDirectory` and the value of visible parameter for it changes from true to false. Unless keys in compose work very differently from react and flutter, I believe this should work. – thewolf Apr 22 '22 at 21:29
  • "`AnimatedVisibility` works when visible is different between previous and current recompositions. In your code it's always `true`, so no animation should happen." `key` doesn't change this fact. – Phil Dukhov Apr 23 '22 at 03:02

0 Answers0