What you think, compose is good or not?
# android
s
What you think, compose is good or not?
🧵 1
🧵 3
j
It’s the best thing ever !
s
Yeah its is. But have you realised code is going unstructured. Composable functions can access anyone from anywhere. Like static.
c
Actually, Compose is much more structured than normal Android Views, by nature of making everything in your UI explicit and/or locally-scoped. Any “global properties” it needs are set as
CompositionLocals
(locally-scoped) rather than accessing anything globally, and everything else is passed explicitly through function parameters. There’s nothing in the Compose APIs that breaks this rule. If you are letting your Composable functions access top-level or global properties, that’s a problem with how you’re using it, not a problem with Compose itself. The docs make it very clear that Composable functions should never access global variables
❤️ 3
s
Yes I know Composable function is not using global variables but if I create composable function in one file, i.e Activity. All other Activities or file can also accessing.
c
Make the Composable function
private
and only the file you declared it can access it. 🤷🏼‍♂️
c
Again, that’s not a concern of Compose itself, it’s entirely within your control to scope your composable functions as you need. You can put them inside a class or top-level
object
, mark them internal/private, do whatever you need to make sure functions are only used on the screen they’re intended for. This is no different from how you’d scope your ViewModels or utility functions that are only used on one screen
s
Oh.. Ok....
I got the point....