Repository navigation
Description
Overview
The iOS implementation (ios/RNCSegmentedControl.{h,m} + RNCSegmentedControlManager.m) is a legacy-architecture view manager. On the New Architecture it currently works through React Native's interop layer for legacy components. I verified this on React Native 0.88, which is New-Architecture-only, in the example app's iOS simulator build: values, images, selection, enabled, colours and the new disabledIndices all render correctly.
So nothing is broken today. But the interop layer is a migration bridge, and React Native recommends that libraries ship native Fabric components. A codegen-based component would also give type-checked native props and avoid interop overhead.
#761 implemented a Fabric component in 2023. It's useful prior art, but it can't be merged as-is:
- Missing features: it predates
testIDS(Added testIDS prop which can be used to pass testID to individual segment buttons #894),disabledIndices(feat: add disabledIndices prop to disable individual segments #936) and the tint-colour text fix (fix:Fix text color reverting to default after changing tintColor #803). Its Fabric view doesn't implement them, and it restructures theios/sources. - Old build setup: the podspec uses the React Native 0.72-era setup (hand-written Folly flags and dependencies behind
RCT_NEW_ARCH_ENABLED) rather thaninstall_modules_dependencies. - Possible JS/native mismatch: the JS side picks the codegen component whenever Fabric is active, but the native Fabric view is only compiled when
RCT_NEW_ARCH_ENABLEDis set. If those disagree, JS sends{type, stringValue}values to a native view that expects strings. - Deprecated imports: the codegen spec uses React Native deep imports and a non-existent
'ViewPropTypes'import path.
Proposal
Re-implement the iOS view as a Fabric native component on current React Native (0.88), using #761 as a reference:
- A codegen spec (
codegenNativeComponent) covering all current iOS props:values(strings and image sources),selectedIndex,tintColor,backgroundColor,momentary,enabled,appearance,fontStyle/activeFontStyle(colour, size, family, weight),testIDS,disabledIndices, and theonChangeevent. - A Fabric component view that shares the existing
UISegmentedControllogic, so the two architectures can't drift apart again. - A podspec using
install_modules_dependencies, pluscodegenConfiginpackage.json.
Decision needed: old architecture support
peerDependencies says react-native >= 0.62, and many apps are still on the old architecture (React Native ≤ 0.81 with the New Architecture disabled). Options:
- Support both architectures, with the legacy view manager kept for the old architecture. This is more code, but the change isn't breaking.
- New Architecture only, in a major release that raises the
react-nativepeer range. This is simpler, but it's a breaking change.
Acceptance criteria
- The iOS example app (React Native 0.88) renders through the Fabric component, not the interop layer, and every example section behaves as it does today.
- Every prop listed above works on iOS, including
testIDS(accessibility identifiers) anddisabledIndices. - The old-architecture behaviour matches whichever option above is chosen.
- CI's iOS job builds the component.
Supersedes #761.
Activity