Skip to content

Animations

AnimatedContainer

A container that gradually changes its values over a period of time.

AnimatedContainer
Tap me!
AnimatedOpacity
Fade
Tap to fade
vue
<template>
  <Column :mainAxisAlignment="'center'" :crossAxisAlignment="'center'">
    <SizedBox :height="20" />
    <Text :style="TextStyle({ fontSize: 18, fontWeight: 'bold' })">AnimatedContainer</Text>
    <SizedBox :height="20" />

    <GestureDetector @tap="toggleContainer">
      <AnimatedContainer
        :width="selected ? 200 : 100"
        :height="selected ? 100 : 200"
        :alignment="selected ? 'center' : 'topCenter'"
        :duration="1000"
        curve="ease-in-out"
        :decoration="
          BoxDecoration({
            borderRadius: BorderRadius.all(selected ? 20 : 0),
            color: selected ? 'red' : 'blue',
            boxShadow: selected
              ? BoxShadow({
                  color: 'rgba(0,0,0,0.5)',
                  blurRadius: 10,
                  spreadRadius: 2,
                  offset: { x: 0, y: 4 },
                })
              : undefined,
          })
        "
      >
        <Text :style="TextStyle({ color: 'white' })">Tap me!</Text>
      </AnimatedContainer>
    </GestureDetector>

    <SizedBox :height="40" />
    <div style="height: 1px; width: 100%; background: #eee" />
    <SizedBox :height="40" />

    <Text :style="TextStyle({ fontSize: 18, fontWeight: 'bold' })">AnimatedOpacity</Text>
    <SizedBox :height="20" />

    <Column>
      <AnimatedOpacity :opacity="opacityLevel" :duration="500">
        <Container :width="100" :height="100" color="green" alignment="center">
          <Text :style="TextStyle({ color: 'white' })">Fade</Text>
        </Container>
      </AnimatedOpacity>
      <SizedBox :height="20" />
      <GestureDetector @tap="toggleOpacity">
        <Container
          :padding="EdgeInsets.all(10)"
          :decoration="BoxDecoration({ borderRadius: BorderRadius.all(4), color: '#EEE' })"
        >
          <Text>Tap to fade</Text>
        </Container>
      </GestureDetector>
    </Column>
  </Column>
</template>

<script setup lang="ts">
import { ref } from "vue";
import {
  AnimatedContainer,
  AnimatedOpacity,
  Column,
  Text,
  SizedBox,
  GestureDetector,
  Container,
  BoxDecoration,
  BorderRadius,
  BoxShadow,
  TextStyle,
  EdgeInsets,
} from "fluekit";

const selected = ref(false);
const toggleContainer = () => {
  selected.value = !selected.value;
};

const opacityLevel = ref(1.0);
const toggleOpacity = () => {
  console.log(opacityLevel.value);

  opacityLevel.value = opacityLevel.value === 1.0 ? 0.0 : 1.0;
};
</script>

AnimatedOpacity

Animated version of Opacity which automatically transitions the child's opacity over a given duration.

Fade
Toggle Opacity
vue
<template>
  <div class="demo-box">
    <Column :gap="20" alignment="center">
      <AnimatedOpacity :opacity="opacity" :duration="500">
        <Container :width="100" :height="100" color="blue" alignment="center">
          <Text data="Fade" :style="TextStyle({ color: 'white' })" />
        </Container>
      </AnimatedOpacity>

      <GestureDetector @tap="toggleOpacity">
        <Container
          color="#eee"
          :padding="EdgeInsets.all(10)"
          :border="Border.all({ width: 1, color: '#ccc' })"
          :borderRadius="4"
        >
          <Text data="Toggle Opacity" />
        </Container>
      </GestureDetector>
    </Column>
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import {
  AnimatedOpacity,
  Container,
  Column,
  Text,
  GestureDetector,
  TextStyle,
  EdgeInsets,
  Border,
} from "fluekit";

const opacity = ref(1);

const toggleOpacity = () => {
  opacity.value = opacity.value === 1 ? 0.2 : 1;
};
</script>

API

AnimatedContainer

Props

NameTypeDefaultDescription
widthnumber | string-The width of the container.
heightnumber | string-The height of the container.
paddingEdgeInsets-The padding of the container.
marginEdgeInsets-The margin of the container.
decorationBoxDecoration-The decoration to paint behind the child.
foregroundDecorationBoxDecoration-The decoration to paint in front of the child.
colorstring-The color to paint behind the child.
alignmentAlignment-The alignment of the child within the container.
clipBehavior'none' | 'hardEdge' | 'antiAlias''none'The content will be clipped (or not) according to this option.
transformstring-The transformation matrix to apply to the container.
transformAlignmentAlignment-The alignment of the origin of the coordinate system in which the transform takes place.
constraintsBoxConstraints-Additional constraints to apply to the child.
durationnumber300The duration over which to animate the parameters.
curvestring'linear'The curve to apply when animating the parameters.

Slots

NameDescription
defaultThe child contained by the container.

AnimatedOpacity

Props

NameTypeDefaultDescription
opacitynumber-The fraction to scale the child's alpha value.
durationnumber300The duration over which to animate the opacity.
curvestring'linear'The curve to apply when animating the opacity.

Slots

NameDescription
defaultThe widget below this widget in the tree.