https://kotlinlang.org logo
Title
d

dimsuz

04/25/2022, 3:33 PM
Is there a way to simulate Multiple Context receivers without this feature enabled? 🙂 I want to write a modifier working with align from ColumnScope...
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:
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
:
fun Modifier.bottomOverlayPadding(): ColumnScope.() -> Modifier = { align(Alignment.End) }
But usage will be a “little” strange with double parentheses 😅
.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...
👍 1