Is there a Modifier that lets me wrap the content ...
# compose
j
Is there a Modifier that lets me wrap the content that is about to be created in a CompositionLocalProvider. I.E. If i apply a modifier to a composable, I’d like the child content to be able to access that set CompositionLocal.
a
Nope. Modifiers are part of the conceptual nesting structure of layout nodes but not of the composition that builds them. What are you trying to do? There might be another mechanism to achieve the same API result. ModifierLocals were recently added to support some of these use cases, but they're specifically available to the later layout/draw phases after composition.
j
Thanks Adam. So what I’m trying to do is implement an analytics modifier that will receive and event object. Then, when a view is on the screen it would perform an action with that event object. Where the local comes in is that I’d like to be able to have a stack of any tracked view above the currently tracked view so i have context where it is. I was looking at ModifierLocals but I was having trouble understanding exactly how I would use them in my case. I can have each modifier provide the current stack, but the consumer felt funny to me since it operates with a callback mechanism and I’d have to link that into some other modifier (when detecting the shown state)
a
yes, it's quite low level and intended for building other abstractions on top of (e.g. compose's focus handling) but it sounds like you have the basic data flow right. Since you'll be dealing with layout visibility you shouldn't have any data dependency loops.
j
So your opinion is to give ModifierLocals a go? I’ll have to play with them and see how it works. It sounds like I have to chain the modifier local consumer into a layout listener modifier?