badoo / RIBs

Badoo's take on RIBs
Apache License 2.0
162 stars 50 forks source link

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

Closed arthur-ghazaryan closed 3 years ago

arthur-ghazaryan commented 3 years ago

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 commented 3 years ago

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

arthur-ghazaryan commented 3 years ago

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 commented 3 years ago

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.

arthur-ghazaryan commented 3 years ago

Thank you! 👍