is there anyone who can explain to me what the c function is used for?
Signature
public inline fun <T, R> with(receiver: T, f: T.() -> R): R = receiver.f()
Doc
Calls the specified function f with the given receiver as the receiver and returns its result.
And I found its use in this project by Antonio Leiva . It was used to move:
fun View.animateTranslationY(translationY: Int, interpolator: Interpolator) { with(ObjectAnimator.ofFloat(this, "translationY", translationY.toFloat())) { setDuration(context.resources.getInteger(R.integer.config_mediumAnimTime).toLong()) setInterpolator(interpolator) start() } }
I thought I knew the point of passing it on
fun View.animateTranslationX(translationX: Int, interpolator: Interpolator) { with(ObjectAnimator()) { ofFloat(this, "translationX", translationX.toFloat()) setDuration(context.resources.getInteger(R.integer.config_mediumAnimTime).toLong()) setInterpolator(interpolator) start() } }
but it does not compile ... But I think that ObjectAnimaton is the receiver, and it gets everything that I will name in the bracket {} . Can someone explain the real meaning and provide a basic example - at least simpler than this ?: D
source share