Skip to main content

Reanimated

Animate layouts built with Vortex Native using Reanimated. Wrap Vortex components in Animated.View and time the animation with the theme's duration and easing tokens.

bun add react-native-reanimated react-native-worklets

Add the Worklets Babel plugin last in your plugin list, then reinstall pods and rebuild the app. Expo apps include the plugin; install the packages with bunx expo install instead.

babel.config.js
module.exports = {
  presets: ["module:@react-native/babel-preset"],
  plugins: ["react-native-worklets/plugin"],
};

Match Vortex motion

theme.duration holds milliseconds, and theme.easing holds cubic Bézier control points. Spread them into Easing.bezier so custom animations move like Vortex components:

src/Details.tsx
import { Stack, Text, useSwitch, useTheme } from "@vortexlabs/vortex-native";
import { useEffect } from "react";
import { Pressable } from "react-native";
import Animated, {
  Easing,
  useAnimatedStyle,
  useSharedValue,
  withTiming,
} from "react-native-reanimated";

const Details = () => {
  const { theme } = useTheme();
  const { isOn, flipSwitch } = useSwitch();
  const progress = useSharedValue(0);

  useEffect(() => {
    progress.value = withTiming(isOn ? 1 : 0, {
      duration: theme.duration[200],
      easing: Easing.bezier(...theme.easing.easeOut),
    });
  }, [isOn, progress, theme]);

  const detailsStyle = useAnimatedStyle(() => ({
    opacity: progress.value,
    transform: [{ translateY: (1 - progress.value) * -8 }],
  }));

  return (
    <Stack gap={2}>
      <Pressable role="button" onPress={flipSwitch}>
        <Text weight="medium">{isOn ? "Hide details" : "Show details"}</Text>
      </Pressable>
      <Animated.View style={detailsStyle}>
        <Text color="subtle">Shipped to 3 devices.</Text>
      </Animated.View>
    </Stack>
  );
};

export default Details;

Animate the Animated.View wrapper rather than the Vortex component, so Vortex keeps control of its own styles.

Reduced motion

withTiming follows the device's reduced motion setting by default and jumps straight to the final value. To decide per animation, pass reduceMotion:

import { ReduceMotion, withTiming } from "react-native-reanimated";

withTiming(1, {
  duration: theme.duration[200],
  reduceMotion: ReduceMotion.Never,
});

Keep ReduceMotion.Never for motion that carries meaning, such as a progress indicator.