Cocoa Beans 0.0.54-beta0 Help

๐Ÿ“น Animation Observables

Available Since 0.0.39

Table of content:

Introduction

This page describes a set of animation-based observable implementations based on the Observable and Observer interfaces. These are useful for reactive and animated UI elements, such as fading or blinking text, typewriter-style effects, and interpolated values.

All classes implement the standard Observable<T> interface and update automatically using an Observable<Instant> time source.

Overview

Each animation implementation provides a different visual behavior:

Class Name

Description

FadingColorBlinkObservable

Fades text in and out with a blinking effect at the end.

FadingColorInOutObservable

Fades text in and out symmetrically, with hold times at the start and end.

TypingObservable

Animates text like a typewriter.

FixedDoubleLerpObservable

Smoothly interpolates numeric values over a fixed duration.

Usage & Showcase

public void onJoin(CocoaBoard board) { board.title(new FadingColorInOutObservable( Observable.immutable("ProjectZero"), boardManager.getNow(), Duration.ofSeconds(3), Duration.ofMillis(750), Duration.ofMillis(2 * 50L), Style.style(NamedTextColor.GREEN, TextDecoration.BOLD), Style.style(NamedTextColor.DARK_GREEN, TextDecoration.BOLD), Style.style(NamedTextColor.DARK_GREEN, TextDecoration.BOLD) )); board.add(Component.text("Simple scoreboard animations")); board.add(new FixedDoubleLerpObservable( boardManager.getMoney().map(i -> i + 0.0), boardManager.getNow(), Duration.ofMillis(750) ).map(money -> Component.text("Money ") .color(NamedTextColor.GRAY) .append(Component.text( String.format("%.1f", money), NamedTextColor.RED )) )); board.add(new TypingObservable( Observable.immutable("Hello, World!"), boardManager.getNow(), Duration.ofMillis(50 * 50L), Duration.ofMillis(50 * 50L), Duration.ofMillis(2 * 50L), "ยงk" ).map(Component::text)); board.add(new FadingColorInOutObservable( Observable.immutable("example.com"), boardManager.getNow(), Duration.ofSeconds(3), Duration.ofMillis(750), Duration.ofMillis(2 * 50L), Style.style(NamedTextColor.YELLOW, TextDecoration.BOLD), Style.style(NamedTextColor.GOLD, TextDecoration.BOLD), Style.style(NamedTextColor.WHITE, TextDecoration.BOLD) )); }
scoreboard_animations.gif

Advantages

Animation observables provide a declarative and reactive approach to building time-based UI transitions. Below are some of the key advantages:

๐Ÿ” Continuous Reactivity

All animations automatically update based on their dependencies (Observable<String>, Observable<Instant>, etc.), without manual ticking or recomputation. This ensures a clean separation between logic and time-based rendering.

๐Ÿงฉ Composable Animations

Each animation is implemented as a self-contained observable that can be easily composed with others, enabling layered effects like fading + blinking or typing + styling.

โš™๏ธ Configurable Behavior

Animations like FadingColorBlinkObservable, FadingColorInOutObservable, and TypingObservable expose parameters such as characterDelay, blinkTimes, and writingSpeedPerCharacter, allowing fine-grained control over timing and styling.

๐ŸŽจ Style Interpolation

Visual transitions are achieved using styled Components and helper functions like AnimationHelpers.fading, enabling smooth color blending and appearance effects.

๐Ÿ”„ State API Integration

Because all animation classes implement Observable<T> and Observer, they seamlessly plug into the state-based update mechanism, propagating changes downstream efficiently.

๐Ÿงช Predictable & Testable

Deterministic behavior based on time and text input makes these animations easy to simulate, debug, and verify in tests.

โฑ๏ธ Time-Based Synchronization

By using Observable<Instant> for time tracking, all animations can remain in sync with a global clock or custom scheduler, supporting coordinated animations across components.

What next

Last modified: 07 July 2025