5

I am passing a modifier instance to a function like this

@Composable
fun SomeComposable(modifier : Modifier) {
    
}

I want to know the current padding applied to the passed modifier inside the function. How to do this?

@Composable
   fun SomeComposable(modifier : Modifier) {
       // val currentTopPadding = modifier.getTopPadding()
  }

I know there is nothing like getTopPadding() but I want a similar or any other function if there is any which gives me padding

AgentP
  • 6,261
  • 2
  • 31
  • 52

1 Answers1

3

Answer from Adam Powell in Kotlin Slack Channel:

No, you're not meant to be able to ask this. If you were able to and this practice were encouraged it would be prohibitively difficult to write UI code that composes with UI code written by others, or to combine libraries that are unaware of one another

This is why Android View padding is frighteningly complex - it permits querying padding and the set of things considered "padding" is unexpectedly large, and has to be for correctness

Padding is an instruction to compose's layout system to subtract available space from an element during measurement and to position the final measured element within a larger space. It is far from the only such instruction available, and app or library code can create their own as well.

Here's the link to his answer.

nglauber
  • 18,674
  • 6
  • 70
  • 75