Commit 3fdaa51c authored by Ronan Abhamon's avatar Ronan Abhamon

feat(Animations/CaterpillarAnimation): better animation

parent 681b3512
...@@ -3,46 +3,93 @@ import QtQuick 2.7 ...@@ -3,46 +3,93 @@ import QtQuick 2.7
Row { Row {
id: container id: container
property int sphereSize: 10 property int duration: 200
property int nSpheres: 3 property int nSpheres: 3
property color sphereColor: '#8F8F8F'
property int sphereSize: 10
property int sphereSpaceSize: 10
spacing: 6 spacing: 6
Repeater { Repeater {
id: repeater
model: nSpheres model: nSpheres
Rectangle { Rectangle {
id: ymovingBox id: sphere
property bool forceRunning: false
property int previousY: 0
color: '#8F8F8F' function startAnimation () {
height: container.sphereSize if (!animator.running) {
radius: container.sphereSize / 2 animator.running = true
} else {
forceRunning = true
}
}
color: sphereColor
height: width
radius: width / 2
width: container.sphereSize width: container.sphereSize
onYChanged: console.log('y changed', y) onYChanged: {
// No call executed by last sphere.
if (index === nSpheres - 1) {
return
}
if (y === (sphereSpaceSize / 2) && previousY === 0) {
repeater.itemAt(index + 1).startAnimation()
}
previousY = y
}
Component.onCompleted: {
// Only start first sphere.
if (index === 0) {
animator.running = true
}
}
YAnimator on y { YAnimator on y {
duration: container.duration
from: 0
id: animator id: animator
running: false
duration: 500 to: sphereSpaceSize / 2
from: 10
running: true
to: 0
onRunningChanged: { onRunningChanged: {
if (!running) { if (running) {
if (to === 0) { return
to = 10 }
var mid = sphereSpaceSize / 2
if (from === sphereSpaceSize && to === mid) {
from = mid
to = 0
} else if (from === mid && to === 0) {
from = 0 from = 0
to = mid
if (index !== 0 && !forceRunning) {
return
}
} else if (from === 0 && to === mid) {
from = mid
to = sphereSpaceSize
} else { } else {
to = 0 from = sphereSpaceSize
from = 10 to = mid
} }
forceRunning = false
animator.running = true animator.running = true
} }
} }
} }
} }
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment