Bryan Lee

    Bryan Lee

    2 years ago
    Is there a "composable" way of sharing data between screens like how you could use a shared view model for sharing data between fragments?
    Adam Powell

    Adam Powell

    2 years ago
    Sure:
    val sharedState = memo { createStateObject() }
    
    when (screen) {
      Screen.First -> FirstScreen(sharedState)
      Screen.Second -> SecondScreen(sharedState)
    }
    Bryan Lee

    Bryan Lee

    2 years ago
    awesome, thanks! (:
    Adam Powell

    Adam Powell

    2 years ago
    Note that the above won't persist across config changes (yet) - stay tuned on that front. 🙂 what API you'll need to use in place of
    memo
    there may change but the idea will remain