Skip to content

A powerful animation library for React-Lua interfaces with spring physics, tweens, and composable animations.

License

Notifications You must be signed in to change notification settings

OutOfBears/react-flow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Slither Icon

React-Flow

⚑ A blazing fast animation library for React-Lua interfaces, providing stateful animations with unrestricted flexibility and performance. 🀌

Version License Stars Forks Watchers Issues Pull Requests Last Commit

πŸ“‹ Table of Contents

✨ Features

  • πŸ”„ Stateful Animations - Animations that automatically respond to your component's state changes, ensuring UI and state stay perfectly synchronized
  • ⛓️ Chainable Animations - Effortlessly build complex animation sequences that flow naturally from one to another
  • πŸ”€ Interruptible Flows - Gracefully handle user interactions by modifying animations mid-flight without jarring visual transitions
  • 🧩 Composable System - Create reusable animation components that can be combined in endless ways for consistent motion design
  • πŸ›‘οΈ Memory-Safe Design - Built with React's lifecycle in mind to prevent memory leaks and ensure proper cleanup

πŸ“¦ Installation

Using Wally (Recommended)

Add React-Flow to your wally.toml file:

[dependencies]
ReactFlow = "outofbears/react-flow@0.2.0"

Then install with:

wally install

Manual Installation

Simply clone the repository and include it in your project structure.

Requiring the Module

Once installed, require React-Flow in your code:

-- For common Roblox setups:
local ReactFlow = require(ReplicatedStorage.Packages.ReactFlow)

πŸ”§ Hooks

useSpring

Creates spring-based physics animations with React bindings. Springs provide natural, bouncy motion that reacts to changes dynamically.

Arguments:

  • config: A configuration table with the following properties:
    • start: Initial value of the animation (required)
    • target: Target value to animate toward (optional)
    • speed: Spring stiffness - higher values create faster motion (default: 10)
    • damper: Damping ratio - higher values reduce bouncing (default: 1)

Returns:
A binding that updates as the animation progresses, and an update function to modify the animation.

Example:

local useSpring = ReactFlow.useSpring

-- Inside your component:
local position, updatePosition = useSpring({
    start = UDim2.fromScale(0, 0),           -- Initial Value (required)
    target = UDim2.fromScale(0.5, 0.5),      -- Target value (optional)

    speed = 20,
    damper = 0.8,
})

-- Later, update the spring with new parameters:
updatePosition({
    target = UDim2.fromScale(0.5, 0.5),

    speed = 15,
    damper = 0.7,
})

-- Use in your component:
return createElement("Frame", {
    Position = position, -- Use binding directly in property
})

useTween

Creates tween-based animations that follow a specific timing curve. Ideal for animations that need precise timing or easing effects.

Arguments:

  • config: A configuration table with the following properties:
    • start: Initial value of the animation (required)
    • target: Target value to animate toward (optional)
    • info: TweenInfo instance (required)

Returns:
A binding that updates as the animation progresses, and an update function to modify the animation.

Example:

local useTween = ReactFlow.useTween

-- Inside your component:
local transparency, updateTransparency = useTween({
    start = 1,      -- Initial value (required)
    target = 0,     -- Target value (optional)

    -- TweenInfo - controls duration, easing style, and behavior
    info = TweenInfo.new(
        0.5,
        Enum.EasingStyle.Quad,
        Enum.EasingDirection.Out, 
    )
})

-- Later, update the tween:
updateTransparency({
    target = 0,     -- New target value

    -- Optional: update tween configuration
    info = TweenInfo.new(0.3, Enum.EasingStyle.Quart, Enum.EasingDirection.InOut),
})

-- Use in your component:
return createElement("Frame", {
    BackgroundTransparency = transparency,
})

useGroupAnimation

Creates a group of animations that are managed together as a single entity. With useGroupAnimation, you can define multiple animation states by combining the following animation primitives: useAnimation, useSpringAnimation, useSequenceAnimation, and useTweenAnimation. This allows you to define complex animation states and switch between them seamlessly at runtime, providing an elegant way to handle UI state transitions.

Arguments:

  • animations: A table mapping state names (e.g., "active", "inactive") to their animation definitions. Each definition can mix multiple animation types.
  • defaults: A table providing the default initial values for each animation property.

Returns:
A table of bindings for each animation property, and a function (commonly named playAnimation) that accepts a state name to switch between the defined animation groups.

Example:

local useGroupAnimation = ReactFlow.useGroupAnimation
local useSequenceAnimation = ReactFlow.useSequenceAnimation
local useAnimation = ReactFlow.useAnimation

local Spring = ReactFlow.Spring
local Tween = ReactFlow.Tween

-- Inside your component:
local animations, playAnimation = useGroupAnimation({
    enable = useSequenceAnimation({
        {
            timestamp = 0,
            transparency = Tween({target = 0, info = TweenInfo.new(0.2)}),
        },
        {
            timestamp = 0.2,
            position = Spring({target = UDim2.fromScale(0.5, 0.5), speed = 20}),
        },
    }),
    disable = useAnimation({
        transparency = Tween({target = 1, info = TweenInfo.new(0.1)}),
        position = Spring({target = UDim2.fromScale(0.5, 1), speed = 25}),
    }),
}, {
    transparency = 1
    position = UDim2.fromScale(0.5, 1),
})

-- Play the animation with the specificed name:
if enabled then
    playAnimation("enable")
else
    playAnimation(
        "disable",
        true -- Optional second argument to play animation immediately
    )
end

-- Use the animation bindings in your component:
return createElement("Frame", {
    Size = UDim2.new(0, 100, 0, 100),
    BackgroundTransparency = animations.transparency,
    Position = animations.position,
})

TransitionFragment

TransitionFragment is a component that allows elements to be animated on transition in and out by preserving their presence in a cached fragment during enter and leave operations. When children are added or removed, the component maintains them in the DOM while injecting transition state props, enabling easy enter and exit animations.

The component automatically injects the following props into child elements:

  • entering: boolean - True when the element is being added
  • exiting: boolean - True when the element is being removed
  • onEnterComplete: () -> () - Callback when enter animation completes
  • onExitComplete: () -> () - Callback when exit animation completes

This allows child components to respond to transition states and perform appropriate animations while TransitionFragment handles the lifecycle management.

Arguments:

  • children: A table containing the elements to be managed with transitions. Elements are automatically cached and transitioned when added or removed.

Returns:

A TransitionFragment component that handles the transition lifecycle and injects transition props into its children.

Example:

local function Entry(props: {
    entering: boolean,
    exiting: boolean,
    onEnterComplete: () -> (),
    onExitComplete: () -> ()
})
    useEffect(function()
        if props.entering then
            -- Play enter animation and wait for animation to complete
            props.onEnterComplete()
        end
    end, {props.entering})

    useEffect(function()
        if props.exiting then
            -- Play enter animation and wait for animation to complete
            props.onExitComplete()
        end
    end, {props.exiting})

    return ...
end

return createElement(ExampleContainer, {}, {
    entries = createElement(TransitionFragment, {}, {
        -- list of Entries
    })
})

πŸ“Š Supported Value Types

React-Flow supports animating the following userdata and native types:

Basic Types

  • number - Numeric values
  • UDim2 - 2D positioning (scale and offset)
  • UDim - 1D positioning (scale and offset)
  • Vector2 - 2D vectors
  • Vector3 - 3D vectors
  • Color3 - RGB color values

Advanced Types

  • CFrame - Position and orientation
  • ColorSequenceKeypoint - Color gradient keypoints
  • NumberSequenceKeypoint - Number gradient keypoints
  • BrickColor - Legacy colors
  • NumberRange - Min/max ranges
  • PhysicalProperties - Physics simulation properties
  • Ray - Line segments
  • Region3 - 3D spatial regions
  • Region3int16 - Integer-based 3D regions

🎬 Showcase

RoundControl

Round Control Interface

TowerUpgrade

Tower Upgrade Interface

NPCDialogue

NPC Dialogue

πŸ’– Contribution

React-Flow was developed by @Nexure with the assistance of @GreenDeno

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A powerful animation library for React-Lua interfaces with spring physics, tweens, and composable animations.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •