I know its not kosher Compose, but I need a childs...
# compose
g
I know its not kosher Compose, but I need a childs modifier, to change a parents background all the way to the top of the tree without making any changes to the parents via code. is that possible? I’ve been looking at the Modifier node stuff and it seems like the answer is in there somewhere
👀 3
Theres the TraversalNode that ive been eyeing up using. Google has a great example here https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]droidx/compose/ui/samples/TraverseModifierDemo.kt;bpv=0;bpt=1 But unfortunately you have to tag every node thats traversable. I don’t think its possible without that though
s
Rather than letting a child modify its parents state, can you hoist the background as a state into the lowest-shared component? This would let you keep state flowing down the Compose hierarchy, and you'd use events to propagate changes in the background up the chain
g
Unfortunately it goes against the requirements so I can’t filter anything down. I could maybe use LocalComposition to provide the colour to places which would avoid that direct tying but ive a feeling its not whats expected
s
Where do these requirements come from? Is someone standing over your shoulder and directing your implementation details? Hoisting state is a very common practice. https://developer.android.com/develop/ui/compose/state#state-hoisting
😅 1
g
some company tech test
t
By tech test you mean for some interview? I wonder what kinda of position requires this haha
g
yeah yeah interview, senior android dev it seems. i mean it fits their use case so it makes sense but its completely anti compose but there we are
🤞🏽 1
🤞 1