lotus-ios / lotus

A Swift animation DSL for animating layers with help of CoreAnimation
MIT License
15 stars 2 forks source link

Proposal: Change animatable target on go #47

Open vkondrashkov opened 4 years ago

vkondrashkov commented 4 years ago

Feature proposal

Add API to make it possible to change current animatable target on go

Alternatives

It's possible to achieve same behavior with nesting .runAnimation calls inside .then blocks, but it can lead to enormous amount of indentations, example:

layer.lotus.runAnimation {
    $0.make.motion(.vertical).to(200)
}.then {
    /* ... */
}.then { _ in
    anotherLayer.lotus.runAnimation {
        $0.make.scaling.to(2)
    }.then {
        /* ... */
    }.then { _ in
        yetAnotherLayer.lotus.runAnimation {
            $0.make.rotation.to(.pi)
        }.then {
            /* ... */
        }
    }
}

Motivation

It would make it easier to change target on go for complex animations where chaining is very important and at the same time make code cleaner.

Additional

I would like to use block that will return a new target some sort of this:

layer.lotus.runAnimation {
    $0.motion(.vertical).to(200)
}.then {
    /* ... */
}.changeTarget {
    return anotherLayer
}.then {
    $0.opacity.to(1)
}

This block makes it possible to even create layer on go not just change target