Skip to content

feat: add apportionsSegmentWidthsByContent prop for iOS - #964

Merged
Naturalclar merged 1 commit into
react-native-segmented-control:masterfrom
officialasishkumar:feat/apportions-segment-widths-by-content
Nov 29, 2026
Merged

Naturalclar merged 1 commit into
react-native-segmented-control:masterfrom
officialasishkumar:feat/apportions-segment-widths-by-content

Conversation

@officialasishkumar

Copy link
Copy Markdown
Contributor

Overview

Adds an apportionsSegmentWidthsByContent prop that exposes UISegmentedControl's apportionsSegmentWidthsByContent. With it, each segment's width follows its content instead of every segment getting the same width. This helps when horizontal space is limited and some labels are much shorter than others. Fixes #883.

<SegmentedControl
  values={['S', 'Medium', 'Extra Large']}
  apportionsSegmentWidthsByContent
/>
  • iOS: the view manager exports the prop. It maps directly onto the UISegmentedControl property, so no other native code is needed.
  • Flow and TypeScript typings, README docs (marked iOS-only) and an example in the example app.
  • Android and web ignore the prop, like the other iOS-only props.

Test Plan

  • Added a case to types-test/typecheck.tsx. pnpm tsc fails without the index.d.ts change and passes with it.
  • pnpm exec jest --runInBand, pnpm lint and pnpm flow check pass locally.
  • I haven't run the native change in a simulator here, so the iOS build relies on CI. It is a single RCT_EXPORT_VIEW_PROPERTY line that follows the existing props.

Expose UISegmentedControl's `apportionsSegmentWidthsByContent` so the
width of each segment can follow the width of its content instead of
every segment getting the same width. This keeps short labels compact
and gives long labels room when horizontal space is limited.

- iOS: export the prop from the view manager; it maps directly onto the
  UISegmentedControl property, so no extra native code is needed.
- Add the prop to the Flow and TypeScript typings, with a type-level test.
- Document it in the README as iOS-only and add it to the example app.

Fixes react-native-segmented-control#883

@Naturalclar Naturalclar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you! I built it and checked the rendering in the iOS simulator, since CI doesn't compile the native code.

@Naturalclar
Naturalclar merged commit c3e8e90 into react-native-segmented-control:master Nov 29, 2026
6 checks passed
@Naturalclar Naturalclar mentioned this pull request Nov 29, 2026
3 tasks
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.

apportionsSegmentWidthsByContent

2 participants