Skip to content

feat(components): add SegmentWidthMode (Fill / Fit) to SegmentedContent#27

Merged
maniramezan merged 2 commits into
mainfrom
feat/segment-width-mode
Jun 6, 2026
Merged

feat(components): add SegmentWidthMode (Fill / Fit) to SegmentedContent#27
maniramezan merged 2 commits into
mainfrom
feat/segment-width-mode

Conversation

@maniramezan
Copy link
Copy Markdown
Owner

Summary

  • Adds a SegmentWidthMode enum (Fill / Fit) and a widthMode parameter to both SegmentedContent overloads (default: Fill, preserving existing behaviour)
  • Fill — bar expands to fill available width (current default)
  • Fit — bar wraps to the natural width of its segments; scrolls only when they overflow
  • Introduces IntrinsicSegmentRow for the Fit + non-overflow path (plain Row, no weight(1f) / fillMaxWidth)
  • SegmentBar's SubcomposeLayout now reports totalIntrinsic as its layout width in Fit mode and guards even-distribution behind Fill mode
  • fillMaxWidth on Column and AnimatedContent is applied conditionally

Test plan

  • Existing unit tests pass (SegmentedContentTest, SegmentedContentInteractionTest)
  • New segmentWidthModeValues test verifies enum stability
  • SegmentedContentFitWidthPreview renders the bar at intrinsic width in Android Studio Preview
  • With widthMode = Fit and few short segments: bar is narrower than the screen
  • With widthMode = Fit and many long segments (overflow): bar scrolls horizontally at full width
  • Default (widthMode = Fill) behaviour is unchanged across all existing previews

Introduces a `widthMode` parameter so callers can choose between:
- `Fill` (default) — bar expands to fill available width, existing behaviour
- `Fit` — bar wraps to the natural width of its segments; only scrolls when they overflow

Adds `IntrinsicSegmentRow` for the Fit+non-overflow path, updates
`SegmentBar`'s SubcomposeLayout to report intrinsic width in Fit mode,
conditionally applies `fillMaxWidth` on the Column and AnimatedContent,
and guards even-distribution behind Fill mode. Preview, Showkase, and
unit-test coverage included.
@maniramezan maniramezan merged commit c30950b into main Jun 6, 2026
2 checks passed
@maniramezan maniramezan deleted the feat/segment-width-mode branch June 6, 2026 16:54
This was referenced Jun 6, 2026
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