From c9c6582ee593595d1c153443494457c14e1a60b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Ma=C5=82ecki?= Date: Wed, 16 Sep 2026 09:17:38 -0700 Subject: [PATCH] Make View conversion headers Apple warning-clean (#58542) Summary: Make public View and CSS conversion headers compile under Apple's -Wswitch-enum and -Wswitch-default policies. Add explicit safe defaults for exhaustive enum conversions and narrowly suppress -Wswitch-enum for the intentionally partial CSSLength token parser. Changelog: [Internal]. Reviewed By: cipolleschi Differential Revision: D120154654 --- .../view/accessibilityPropsConversions.h | 32 +++++++++++++------ .../renderer/components/view/conversions.h | 24 ++++++++++++++ .../react/renderer/css/CSSLength.h | 7 ++++ .../react/renderer/css/CSSTransformOrigin.h | 4 +-- 4 files changed, 55 insertions(+), 12 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h b/packages/react-native/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h index 7c96b9a608f2..bcb3d915c098 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h @@ -182,6 +182,10 @@ inline std::string toString(const ImportantForAccessibility &importantForAccessi return "no"; case ImportantForAccessibility::NoHideDescendants: return "no-hide-descendants"; + default: + LOG(ERROR) << "Unsupported ImportantForAccessibility value: " << static_cast(importantForAccessibility); + react_native_expect(false); + return "auto"; } } @@ -372,12 +376,12 @@ inline std::string toString(const AccessibilityRole &accessibilityRole) return "slidingdrawer"; case AccessibilityRole::Iconmenu: return "iconmenu"; + default: + LOG(ERROR) << "Unsupported AccessibilityRole value: " << static_cast(accessibilityRole); + react_native_expect(false); + // sane default for prod + return "none"; } - - LOG(ERROR) << "Unsupported AccessibilityRole value"; - react_native_expect(false); - // sane default for prod - return "none"; } inline void fromRawValue(const PropsParserContext &context, const RawValue &value, AccessibilityRole &result) @@ -613,12 +617,12 @@ inline std::string toString(const Role &role) return "treegrid"; case Role::Treeitem: return "treeitem"; + default: + LOG(ERROR) << "Unsupported Role value: " << static_cast(role); + react_native_expect(false); + // sane default for prod + return "none"; } - - LOG(ERROR) << "Unsupported Role value"; - react_native_expect(false); - // sane default for prod - return "none"; } inline void fromRawValue(const PropsParserContext &context, const RawValue &value, Role &result) @@ -780,6 +784,10 @@ inline std::string toString(AccessibilityLiveRegion accessibilityLiveRegion) return "polite"; case AccessibilityLiveRegion::Assertive: return "assertive"; + default: + LOG(ERROR) << "Unsupported AccessibilityLiveRegion value: " << static_cast(accessibilityLiveRegion); + react_native_expect(false); + return "none"; } } @@ -795,6 +803,10 @@ inline std::string toString(AccessibilityState::CheckedState state) return "Mixed"; case AccessibilityState::None: return "None"; + default: + LOG(ERROR) << "Unsupported AccessibilityState::CheckedState value: " << static_cast(state); + react_native_expect(false); + return "None"; } } diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/conversions.h b/packages/react-native/ReactCommon/react/renderer/components/view/conversions.h index 743b0e7a57d3..8ef320cf8c84 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/conversions.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/conversions.h @@ -124,6 +124,10 @@ static inline PositionType positionTypeFromYogaPositionType(yoga::PositionType p return PositionType::Relative; case yoga::PositionType::Absolute: return PositionType::Absolute; + default: + LOG(ERROR) << "Unexpected yoga::PositionType value: " << static_cast(positionType); + react_native_expect(false); + return PositionType::Relative; } } @@ -138,6 +142,10 @@ inline DisplayType displayTypeFromYGDisplay(YGDisplay display) return DisplayType::Flex; case YGDisplayGrid: return DisplayType::Grid; + default: + LOG(ERROR) << "Unexpected YGDisplay value: " << static_cast(display); + react_native_expect(false); + return DisplayType::Flex; } } @@ -185,6 +193,10 @@ inline YGDirection yogaDirectionFromLayoutDirection(LayoutDirection direction) return YGDirectionLTR; case LayoutDirection::RightToLeft: return YGDirectionRTL; + default: + LOG(ERROR) << "Unexpected LayoutDirection value: " << static_cast(direction); + react_native_expect(false); + return YGDirectionInherit; } } @@ -1113,6 +1125,10 @@ inline std::string toString(PointerEventsMode value) return "box-none"; case PointerEventsMode::BoxOnly: return "box-only"; + default: + LOG(ERROR) << "Unsupported PointerEventsMode value: " << static_cast(value); + react_native_expect(false); + return "auto"; } } @@ -1695,6 +1711,10 @@ inline std::string toString(const LayoutConformance &value) return "strict"; case LayoutConformance::Compatibility: return "compatibility"; + default: + LOG(ERROR) << "Unsupported LayoutConformance value: " << static_cast(value); + react_native_expect(false); + return "strict"; } } @@ -1774,6 +1794,10 @@ inline std::string toString(const Transform &transform) result += "{\"identity\": true}"; break; } + default: + LOG(ERROR) << "Unsupported TransformOperationType value: " << static_cast(operation.type); + react_native_expect(false); + break; } } diff --git a/packages/react-native/ReactCommon/react/renderer/css/CSSLength.h b/packages/react-native/ReactCommon/react/renderer/css/CSSLength.h index fa3e811cf771..18b3b0a48cc5 100644 --- a/packages/react-native/ReactCommon/react/renderer/css/CSSLength.h +++ b/packages/react-native/ReactCommon/react/renderer/css/CSSLength.h @@ -31,7 +31,14 @@ template <> struct CSSDataTypeParser { static constexpr auto consumePreservedToken(const CSSPreservedToken &token) -> std::optional { +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wswitch-enum" +#endif switch (token.type()) { +#ifdef __clang__ +#pragma clang diagnostic pop +#endif case CSSTokenType::Dimension: if (auto unit = parseCSSLengthUnit(token.unit())) { return CSSLength{.value = token.numericValue(), .unit = *unit}; diff --git a/packages/react-native/ReactCommon/react/renderer/css/CSSTransformOrigin.h b/packages/react-native/ReactCommon/react/renderer/css/CSSTransformOrigin.h index 0a4309a10e79..be1818efaae3 100644 --- a/packages/react-native/ReactCommon/react/renderer/css/CSSTransformOrigin.h +++ b/packages/react-native/ReactCommon/react/renderer/css/CSSTransformOrigin.h @@ -195,9 +195,9 @@ struct CSSDataTypeParser { return CSSPercentage{100.0f}; case CSSTransformOriginKeyword::Bottom: return CSSPercentage{100.0f}; + default: + return {}; } - - return {}; } };