Skip to content

Commit

Permalink
Added documentation on transitions.
Browse files Browse the repository at this point in the history
  • Loading branch information
michielvandergeest committed Mar 13, 2024
1 parent 50ce597 commit faf99ee
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
- [Hooking into lifecycle events](/components/lifecycle_events.md)
- [Handling User input](/components/user_input.md)
- [Methods](/components/methods.md)
- Transitions and Animations
- [Transitions](/transitions_animations/transitions.md)
9 changes: 9 additions & 0 deletions docs/sidebar.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,14 @@
"link": "/components/methods"
}
]
},
{
"text": "Transitions and Animations",
"items": [
{
"text": "Transitions",
"link": "/transitions_animations/transitions"
}
]
}
]
132 changes: 132 additions & 0 deletions docs/transitions_animations/transitions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Blits - Lightning 3 App Development Framework

## Transitions

So far we have explored how to create components and draw elements on the screen. But everything has
been rather static so far.

We did learn how to _reactively_ changes values and trigger rerenders based on that. So if you try the example below, you'll see that indeed our golden element changes position. But it just jumps from one place to another:

```js
export default Blits('Gold', {
template: `
<Element color="gold" w="100" h="100" :x="$x" :y=:"$y" />
`,
state() {
return {
x: 0,
y: 0,
}
},
input: {
enter() {
this.x = this.x + 100
this.y = this.y + 50
}
},
```
Using _transitions_ we really make our App come alive.
### Applying a transition
Blits offers an easy and intuitive way to apply transitions. All you need to do is add the `.transition` modifier to a reactive attribute, and now whenever you change the value referenced in the attribute, it will automatically _smooth_ into the new value.
```js
export default Blits('Gold', {
template: `
<Element color="gold" w="100" h="100" :x.transiton="$x" :y.transition=:"$y" />
`,
state() {
return {
x: 0,
y: 0,
}
},
input: {
enter() {
this.x = this.x + 100
this.y = this.y + 50
}
},
```
If we try out the modified example above, you'll notice how difference adding a simple transition makes.
When the `.transition`-modifier is added to a reactive attribute, a default `ease-in` transition with a duration of `300ms` is applied
### Customizing transitions
While the default transition will look pretty good out of the box and is great for quickly improving the look of your App, you may want to customize specific transitions.
Blits gives you full control over your transitions, with a simple to use format, right inside your template.
Instead of referencing your component's state variable directly, you can also supply an inlien `object literal` in the attribute with a `.transition`-modifier. This will allow you to pass a number of options to change the way the transition will work.
The transition object must have a `value` key, which references the state variable (or prop or computed property) that triggers the transition.
Further more you can specify:
- `duration` - the duration of the transition in `ms`
- `delay` - the time in `ms` after which the transition should initiate
- `easing` - the easing function of the transition. Can be one of the defaults easing options listed below, or a custom `cubic-bezier` definitions (i.e. `cubic-bezier(0,1.35,.99,-0.07)`).
```xml
<Element color="gold" w="100" h="100"
:x.transiton="{value: $x, duration: 300, easing: 'ease-in-back', delay: 400}"
:y.transition=:"{value: $x, duration: 300, easing: 'cubic-bezier(1,-0.64,0.39,1.44)'}">
</Element>
```
Besides a reference to the `value`, you can also use dynamic values for the other keys in the transition object. This way you'll be able to dynamically control the delay, duration or easing function.
```xml
<Element color="gold" w="100" h="100"
:x.transiton="{value: $x, duration: $dynamicDuration, delay: $dynamicDelay}">
</Element>
```
#### Available easing functions
- `ease-in`
- `ease-out`
- `ease-in-out`
- `ease-in-sine`
- `ease-out-sine`
- `ease-in-out-sine`
- `ease-in-cubic`
- `ease-out-cubic`
- `ease-in-out-cubic`
- `ease-in-circ`
- `ease-out-circ`
- `ease-in-out-circ`
- `ease-in-back`
- `ease-out-back`
- `ease-in-out-back`
### Listening to transition events
Sometimes you may want to perform an action when a transition ends or when it starts.
You can easily hook into these transiti)on events by adding a `start` and `end` key to the transition object. Both value should be a function (or a reference to a `method` on your component).
The `start` function will be called when the transition actually starts (after a possible specified delay) and the `end` function is called as soon as the transitions is finished.
```js
export default Blits('Gold', {
template: `
<Element color="gold" w="100" h="100"
:x.transiton="{value: $x, start: $transitionBegin, end: $transitionEnd}"
/>
`,
///
methods: {
transitionBegin() {
//
},
transitionEnd() {
//
},
}
```

0 comments on commit faf99ee

Please sign in to comment.