-
-
Notifications
You must be signed in to change notification settings - Fork 251
[feature/kotlin] Kotlin code in animator module #55
Conversation
override fun evaluate(fraction: Float, startPathDataNodes: Array<PathDataNode>?, endPathDataNodes: Array<PathDataNode>?): Array<PathDataNode> { | ||
if (evaluatedNodes == null) { | ||
evaluatedNodes = PathParserCompat.deepCopyNodes(startPathDataNodes) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can do like so:
val evaluatedNodes = this.evaluatedNodes?.let { it } ?: PathParserCompat.deepCopyNodes(startPathDataNodes)
this.evaluatedNodes = evaluatedNodes
then we can remove !!
from evaluatedNodes!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree with that. You can see in 7bb9d6a.
} | ||
} | ||
applyAnimatorProperties(valueAnimator, path) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can move applyAnimatorProperties(valueAnimator, path)
inside apply{}
block then can remove val valueAnimator
like below:
ValueAnimator.ofFloat(*values).apply {
addUpdateListener { animation ->
listener?.update(path, animation.animatedValue as Float)
path.onRichPathUpdatedListener?.onPathUpdated()
}
applyAnimatorProperties(this, path)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. You can see in b9ce4a1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all, This is a great PR and thank you for your efforts!
I agree with the three points you mentioned in the PR description, especially the second and the third points, I always prefer to have backward compatibility as you did and also I would like to see that Kotlin style you suggested :)
Thanks!
@tarek360 Hi, Thank you for saying so. First, If we are going to support backward compatibility and add new Kotlin style, then I think we should modify like below in AnimationBuilder. [ AnimationBuilder.kt ] var trimPathEnd = floatArrayOf(0f)
set(value) {
property("trimPathEnd", *value)
field = value
}
fun trimPathEnd(vararg values: Float) = apply {
trimPathEnd = values
} Second, If we add animate method in RichPathAnimator, then we can keep similar with Java. companion object {
private val animationBuilders = arrayListOf<AnimationBuilder>()
@JvmStatic fun animate(vararg paths: RichPath): AnimationBuilder {
val viewAnimator = RichPathAnimator()
return viewAnimator.addAnimationBuilder(*paths)
}
fun animate(vararg paths: RichPath, block:AnimationBuilder.()->Unit){
AnimationBuilder(RichPathAnimator(), *paths).apply(block).run {
animationBuilders.add(this)
start()
}
}
} Last, we create animation in Kotlin like this : RichPathAnimator.animate(*allPaths) {
trimPathEnd = floatArrayOf(0f, 1f)
// ..
} What about that? |
Hi, for the 1st and 2nd points, if we keep it, for now, I see it still works with Java correctly and but not Kotlin style, so I think later after we merge this PR, we can have another version of the builder with Kotlin DSL. The 3rd point, I'd get rid of the asterisk! What do you think? |
@tarek360 And, I also think we can develop Kotlin DSL after merging this :) |
@tarek360 |
I think the code like
|
@tarek360 Then you means that we are going to replace |
@step4me this PR is getting old :) |
* [feature/kotlin] Kotlin code in animator module (#55) * add buildSrc/build to gitignore * add kotlin source directory and configuration for animator module * add RichPathAnimator kotlin class * add kotlin classes to animator module * change to kotlin richpathanimator reference in app module MainActivity * remove non-null assertion operator in PathEvaluator * remove local variable using apply block in AnimationBuilder * modify vararg parameter [paths] to Array type in AnimationBuilder Co-authored-by: Ahmed Tarek <a.tarek360@gmail.com> * fix java/kotlin compatability * fix repeatMode repeatCount * add kotlin source directory and configuration for richpath module * convert java to kotlin on RichPath, View, Drawable and Util classes * move model and util directories to below richpath directory * add Group Kotlin class * modify RichPathView's parent to AppCompatImageView * convert java to kotlin related on PathParser classes * convert java to kotlin on PathUtils class * convert java to kotlin on OnRichPathUpdatedListener interface * modify PathEvaluator's generic type to nullable and deepCopyNodes' return type to non-null * modify Boolean type variable `pivotToCenter` to `isPivotToCenter` * delete `originalPath` variable and use constructor parameter `src` * modify pathDataNodes getter and setter * modify package references of richpath module * modify {@link class} in JavaDoc to [class] in KDoc * delete java source set and rename kotlin package in richpath module * rename test package source set to kotlin and convert java to kotlin on UtilsTest * delete sourceSets configuration on animator and richpath modules * modify showToast msg parameter type to non-null * modify sourceSet name kotlin to java Co-authored-by: Injin Bae <eyegochild@gmail.com>
Hi, @tarek360 :)
As you see in this PR, I added kotlin source set in animator module.
I think we can remove java source set after we discuss about changes.
RepeatMode
I changed RepeatMode type to sealed class.
@JvmStatic fun animate
I think animator module can be called from Java.
And, I tested in app module MainActivity.
apply
I used many
apply inline function
in AnimationBuilder class.So, I want to change more like :
RichPathAnimator.create { paths = allPaths; duration = 800; .... }
I need your advice.
Thanks!