Repository navigation
feat: add CarouselView control - #38
Merged
Merged
Conversation
Render Ruby carousel_view with Flutter's M3 CarouselView (or CarouselView.weighted) on Material and a hand-built Cupertino carousel on Apple platforms: a fixed-extent bouncing ListView with optional per-item snapping, rounded PhysicalShape items with press dimming, and a PageView approximation for flex_weights. item_click reports the tapped index and animate_to_item scrolls to an item.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the
CarouselViewcontrol (Work Package F, item F2, P2).Ruby counterpart: AdamMusa/ruflet#51
Rendering
It follows the three-file adaptive pattern, plus one design-neutral model file:
adaptive_carousel_view.dartdispatches throughPlatformControlRendererinsideLayoutControl. It renders anErrorControlwhen:item_extentnorflex_weightsis set (the message suggests both);flex_weightscontains a non-positive weight;carousel_view_model.dartis design-neutral. It holds the shared keyword parsing,initial_itemand index clamping, theitem_clickcallback, and the parser for theanimate_to_iteminvoke arguments. It accepts camelCase or snake_case curve names.material_carousel_view.dart) usesCarouselView, orCarouselView.weightedwhenflex_weightsis given (flex_weightswins overitem_extent). It is driven by aCarouselController(initialItem:), andanimate_to_itemcallsCarouselController.animateToItem.cupertino_carousel_view.dart) is hand-built from widgets-layer and Cupertino pieces only, with no Material, per D-7.item_extent, it is a fixed-extentListView.builderwithBouncingScrollPhysics. Withitem_snapping, a small per-item snapping physics settles flings on whole items, likePageScrollPhysicswith a page size of one item.Padding(padding, default 4)around aPhysicalShape:shape, or a 20 px rounded rectangle by default;bgcolor, orsecondarySystemBackgroundby default;elevationanditem_clip_behavior.CupertinoButton. Ifoverlay_coloris given, itspressedcolour is painted over the item instead.enable_splash: falseturns this feedback off.GestureDetector, attached only whenon_item_clickis set.flex_weightsis approximated by aPageView. ItsviewportFractionis the first weight divided by the sum, withpadEnds: falseandpageSnappingset fromitem_snapping. This approximation is documented in the SPEC.Wire keys and events
controlschildrenitem_extentitemExtentListView.itemExtent(clamped to viewport)flex_weightsCarouselView.weighted(flexWeights:)PageView(viewportFraction: first/sum)consume_max_weightconsumeMaxWeightshrink_extentshrinkExtentitem_snappingitemSnappingpageSnappinghorizontal,reversescrollDirection,reversepaddingpadding(default 4)bgcolor,elevation,shape,item_clip_behaviorPhysicalShapeoverlay_color,enable_splashinitial_itemCarouselController(initialItem:)on_item_clickfiresitem_clickwith the tapped index (int). The tap handler is only set when the Ruby handler exists.animate_to_item(index, duration: 300, curve: "ease")sends theanimate_to_iteminvoke. Each renderer registers its ownaddInvokeMethodListenerand returnsnullfor other names. Out-of-range indexes clamp.CarouselView.onIndexChanged, so per the SPEC there is noon_changeevent for the visible item.Tests
test/widgets/ruby_carousel_view_test.dart, 22 tests on iOS and Android. They check:item_extentwide, at full height, and laid out in order;item_click1, and nothing fires without a handler;animate_to_item(2)moves item 2 to the leading edge, and index 99 clamps to the last item;initial_itemstarts on that item;item_snappingsettles on a whole item after a drag;flex_weights [2,1,1]makes the leading item half the viewport;bgcolor,elevation,shape,item_clip_behaviorandreversereach the renderer;CarouselView(item_extent: 200), covered on all 5 platforms.verify_pr.shwith Flutter 3.41.2: +722: All tests passed! (baseline 695).flutter analyze lib testreports No issues found!. The wire-key audit shows 0 new findings: every CarouselView key is read anditem_clickis fired.