Hi everyone, does anyone know how to show a Compos...
# compose-android
l
Hi everyone, does anyone know how to show a Compose popup in anywhere in the Android app? Ex: A global counter to count from X down to 0, when it reach 0, we show the popup no matter where we're in the app
k
CompositionLocal could help, you would however need to create a composable that reacts to displaying the dialog in every screen. Or have it defined once in a top level Scaffold
s
Copy code
MainActivity {
 override onCreate() {
  setContent {
   var showPopup by remember { mutableStateOf(false) }
   YourNormalApp(showPopup = { showPopup = true })
   if (showPopup) {
    ThisPopup(dismissPopup = { showPopup = false })
   }
  }
 }
}
Something like that should suffice. The way/time that
showPopup
is set to true or false can be determined from your needs.
l
There is one pain point that I forgot to mention, my app is not a fully compose app, it uses Activities and Fragments a lot inside. So what I’m doing is putting my Compose popup inside a transparent dialog fragment or fragment to show it globally. But using a dialog fragment to show a Compose popup looks tricky laugh cry face palm
s
Perhaps best to cut your losses and just use a non compose popup in the first place, and just use compose code for its UI if possible 😄
l
I wish i can laugh cry face palm but the purpose is to migrate the app to use Compose, so new popup show be the Compose popup
s
You absolutely can. In a mixed app, sometimes you have to make such compromises. In androidx.navigation documentation even they explicitly say that the path to migrate to compose is specifically to not do it until all your fragments are using compose internally, and then you can do the switch for all of them at the same time. https://developer.android.com/develop/ui/compose/migrate/strategy#removing-fragments https://developer.android.com/develop/ui/compose/migrate/migration-scenarios/navigation
☝️ 1
☝🏿 1