Is there a way to simulate Multiple Context receivers without this feature enabled? 🙂
I want to write a modifier working with align from ColumnScope...
Copy code
internal fun Modifier.bottomOverlayPadding(): Modifier {
return Modifier
.align(Alignment.End) // can't use, need ColumnScope
}
o
Oleksandr Balan
04/25/2022, 4:01 PM
I would simply pass a
scope
as first param to your custom modifier and then use
with
in modifier body:
Copy code
fun Modifier.bottomOverlayPadding(scope: ColumnScope) = with(scope) {
align(Alignment.End)
}
… or if you prefer some “hacky” way you may return a lambda with your needed
scope
:
Copy code
fun Modifier.bottomOverlayPadding(): ColumnScope.() -> Modifier = { align(Alignment.End) }
But usage will be a “little” strange with double parentheses 😅
Copy code
.bottomOverlayPadding()()
d
dimsuz
04/25/2022, 4:20 PM
nice hacks! 😁
The first one I thought of, the second one is "nice" too)) thanks, will consider if I want to go either route...