Skip to content

feat: add CarouselView control - #51

Merged
AdamMusa merged 2 commits into
mainfrom
feat/carousel-view
Oct 29, 2026
Merged

AdamMusa merged 2 commits into
mainfrom
feat/carousel-view

Conversation

@AdamMusa

Copy link
Copy Markdown
Owner

Adds the Ruby side of CarouselView (Work Package F, item F2, P2).

Engine counterpart (renderer): AdamMusa/ruflet-engine#38

Usage

banners_view = carousel_view(
  height: 200, item_extent: 320, item_snapping: true,
  controls: banners.map { |b| image(src: b.url, fit: "cover") },
  on_item_click: ->(e) { open_banner(e.value) })

banners_view.animate_to_item(2)                                   # 300 ms, "ease"
banners_view.animate_to_item(0, duration: 500, curve: "easeInOut")

# Material 3 "hero" layout (approximated on iOS)
carousel_view(height: 180, flex_weights: [3, 2, 1]) do
  container(bgcolor: "primary")
  container(bgcolor: "secondary")
end

API

  • controls/materials/carouselview_control.rb: CarouselViewControl, TYPE carouselview, WIRE CarouselView.
    • KEYWORDS: bgcolor consume_max_weight controls elevation enable_splash flex_weights horizontal initial_item item_clip_behavior item_extent item_snapping overlay_color padding reverse shape shrink_extent plus the common layout keywords.
    • Events: on_item_click, which fires item_click with the tapped index, plus on_animation_end and on_size_change.
    • Default horizontal = true.
    • Method animate_to_item(index, duration: 300, curve: "ease", timeout: 10, on_result: nil) invokes animate_to_item with {"index", "duration", "curve"}. It is a no-op before the control is on a page.
  • CLASS_MAP has carousel_view and carouselview in the materials and top-level registries.
  • DSL helpers carousel_view(children = nil, **props, &block) and carouselview are in material_control_methods.rb, shared_control_forwarders.rb and dsl.rb.
  • Either item_extent or flex_weights is required. The renderer shows an ErrorControl when both are missing, so a carousel built before its data arrives does not raise in Ruby.

Tests

  • New test/carousel_view_compatibility_test.rb (7 runs). It covers:
    • _c, positional, controls: and block children, and every keyword serialized (colours normalized, state maps kept);
    • the weighted variant and its defaults;
    • Ruflet.control(:carousel_view) and the Ruflet::DSL helpers;
    • page.dispatch_event for item_click reaches the handler with e.value;
    • animate_to_item sends the invoke payload with defaults and with explicit duration and curve;
    • animate_to_item without a page returns nil;
    • unknown keywords and events raise.
  • verify_pr.sh: with RUBY_PKGS="ruflet_core ruflet_rails": ruflet_core 146/146 files, 625 runs; ruflet_rails 15/15 files, 278 runs. The engine pair passes too (+722 tests, analyze clean). The wire-key audit shows 0 new findings.

Add carousel_view/carouselview helpers and the CarouselView wire type with item_extent/flex_weights layouts, surface keywords, on_item_click and an animate_to_item method. horizontal defaults to true.
@AdamMusa
AdamMusa merged commit 5657a38 into main Oct 29, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant