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

Compose views + back stack don't work together as expected #289

Closed
arthur-ghazaryan opened this issue Apr 25, 2021 · 4 comments · Fixed by #299
Closed

Compose views + back stack don't work together as expected #289

arthur-ghazaryan opened this issue Apr 25, 2021 · 4 comments · Fixed by #299
Labels
bug Something isn't working compose

Comments

@arthur-ghazaryan
Copy link

Hello there! 👋

I'm trying to use jetpack compose with ComposeRibView like this

class HomeViewImpl private constructor(context: Context) : ComposeRibView(context), HomeView {

  private var bottomBar = mutableStateOf<ComposeView?>(null)
  private var content = mutableStateOf<ComposeView?>(null)

  override val composable: @Composable () -> Unit = {
          Column(
              modifier =
                  Modifier.fillMaxSize().background(MaterialTheme.colors.surface)
          ) {
            Box(modifier = Modifier.fillMaxWidth().weight(1f)) {
              content.value?.invoke()
            }
            bottomBar.value?.invoke()
          }
      }

  override fun getParentViewForSubtree(subtreeOf: Node<*>): MutableState<ComposeView?> {
    return when (subtreeOf) {
      is BottomBar -> bottomBar
      else -> content
    }
  }

  class Factory : HomeView.Factory {
    override fun invoke(p1: Nothing?): (RibView) -> HomeView = { HomeViewImpl(it.context) }
  }
}

Backstack uses content to show backstack content.
The problem is that when I'm pushing something in the backstack attachChild is called before detachChild, so my content value becomes null after attaching the child. Are there any other ways to use compose with backstack ?

@zsoltk
Copy link
Contributor

zsoltk commented Apr 26, 2021

Hi @arthur-ghazaryan! That's weird. I'll try to reproduce it.

@arthur-ghazaryan
Copy link
Author

Hey @zsoltk 👋 , thanks for your fast response. If it's can help I've created a reproducible sample https://github.com/arthur-ghazaryan/rib-compose-sample

@zsoltk
Copy link
Contributor

zsoltk commented Apr 29, 2021

Thanks for the sample, it's really helpful. I checked it and I can confirm there's an issue. I couldn't dig deeper yet, but will do soon.

@zsoltk zsoltk added the bug Something isn't working label Apr 29, 2021
@zsoltk zsoltk changed the title [Question] Compose and backstack. Compose views + back stack don't work together as expected Apr 29, 2021
@arthur-ghazaryan
Copy link
Author

Thank you! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compose
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants