$ show Lavmee/constraintlayout-compose-multiplatform
This repository provides a full port of AndroidX ConstraintLayout and MotionLayout for Compose Multiplatform, enabling declarative, constraint-based layouts and keyframe animations across Android, iOS, Desktop, macOS, and Web (Wasm). The library is published as `tech.annexflow.compose:constraintlayout-compose-multiplatform` and includes a complete Kotlin Multiplatform implementation of the core constraint solver, motion engine, JSON5 parser, and Compose DSL. It supports both inline DSL and JSON-based constraint definitions, with experimental MotionLayout for animated transitions between constraint sets, including swipe gestures, keyframes, and custom easing curves. Architecturally, the project is split into a `compose` module containing the Compose-specific composables (`ConstraintLayout`, `MotionLayout`, `ConstraintSet`, `Transition`) and a `core` module that houses the platform-agnostic constraint solving engine (`LinearSystem`, `SolverVariable`, `ConstraintWidget`), motion interpolation (`CurveFit`, `Easing`, `StopLogicEngine`), and a custom JSON5 parser (`CLParser`). The sample app demonstrates various use cases such as collapsible toolbars, carousels, puzzle layouts, and swipe-driven transitions. The codebase is well-tested with extensive unit tests for both the core engine and Compose integration, and includes CI pipelines for building and validation. The library is actively maintained with recent commits and responsive issue triage. While it is a port of an AndroidX library, it has been adapted for multiplatform use with platform-specific expect/actual declarations for logging, weak references, and debug rendering. The code exhibits high craftsmanship in areas like the custom linear solver, motion interpolation algorithms, and the JSON parser, making it a valuable resource for developers needing advanced layout and animation capabilities in Compose Multiplatform projects.
The LLM identified 5 files worth highlighting for reuse:
Core composable implementing ConstraintLayout for Compose Multiplatform. Provides both inline DSL (using `ConstraintLayoutScope` and `Modifier.constrainAs`) and `ConstraintSet`-based API. Supports animated constraint changes via `animateChangesSpec` using `Animatable` and `Channel`. Handles measurement delegation to the core solver and integrates with design-time tooling. Demonstrates a clean separation between declarative layout definition and runtime measurement.
Custom JSON5 parser for constraint and motion scene definitions. Implements a tokenizer and recursive descent parser producing `CLObject`, `CLArray`, `CLKey`, `CLNumber`, `CLString`, and `CLToken` nodes. Supports comments, trailing commas, and unquoted keys. Reusable for any JSON5 parsing need, not tied to layout logic. Demonstrates non-obvious skill in building a lightweight, platform-independent parser.
Implements a multi-stage deceleration engine for velocity-based animations. Supports cruise, accelerate, and brake phases with configurable acceleration, velocity, and distance limits. Used by `OnSwipe` to compute spring-like motion. Self-contained and reusable for any animation system requiring realistic deceleration profiles. Demonstrates sophisticated physics-based interpolation.
Provides a `Modifier.carouselSwipeable()` extension and `CarouselSwipeableState` for building swipeable carousels with anchor snapping, resistance, and velocity-based target computation. Implements sinusoidal resistance and threshold-based snapping. Uses Compose's `Animatable` and `NestedScrollConnection`. Reusable as a standalone swipeable component for any horizontal paging UI. Demonstrates advanced gesture handling and physics simulation.
Implements monotonic cubic Hermite spline interpolation for smooth motion paths. Computes tangents using finite differences and ensures monotonicity. Used by the motion engine for keyframe interpolation. Self-contained and reusable for any curve fitting or animation interpolation need. Demonstrates solid numerical methods implementation.