Skip to content

Commit 4239f64

Browse files
coadofacebook-github-bot
authored andcommitted
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
1 parent 7e02fc7 commit 4239f64

4 files changed

Lines changed: 55 additions & 12 deletions

File tree

packages/react-native/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ inline std::string toString(const ImportantForAccessibility &importantForAccessi
182182
return "no";
183183
case ImportantForAccessibility::NoHideDescendants:
184184
return "no-hide-descendants";
185+
default:
186+
LOG(ERROR) << "Unsupported ImportantForAccessibility value: " << static_cast<int>(importantForAccessibility);
187+
react_native_expect(false);
188+
return "auto";
185189
}
186190
}
187191

@@ -372,12 +376,12 @@ inline std::string toString(const AccessibilityRole &accessibilityRole)
372376
return "slidingdrawer";
373377
case AccessibilityRole::Iconmenu:
374378
return "iconmenu";
379+
default:
380+
LOG(ERROR) << "Unsupported AccessibilityRole value: " << static_cast<int>(accessibilityRole);
381+
react_native_expect(false);
382+
// sane default for prod
383+
return "none";
375384
}
376-
377-
LOG(ERROR) << "Unsupported AccessibilityRole value";
378-
react_native_expect(false);
379-
// sane default for prod
380-
return "none";
381385
}
382386

383387
inline void fromRawValue(const PropsParserContext &context, const RawValue &value, AccessibilityRole &result)
@@ -613,12 +617,12 @@ inline std::string toString(const Role &role)
613617
return "treegrid";
614618
case Role::Treeitem:
615619
return "treeitem";
620+
default:
621+
LOG(ERROR) << "Unsupported Role value: " << static_cast<int>(role);
622+
react_native_expect(false);
623+
// sane default for prod
624+
return "none";
616625
}
617-
618-
LOG(ERROR) << "Unsupported Role value";
619-
react_native_expect(false);
620-
// sane default for prod
621-
return "none";
622626
}
623627

624628
inline void fromRawValue(const PropsParserContext &context, const RawValue &value, Role &result)
@@ -780,6 +784,10 @@ inline std::string toString(AccessibilityLiveRegion accessibilityLiveRegion)
780784
return "polite";
781785
case AccessibilityLiveRegion::Assertive:
782786
return "assertive";
787+
default:
788+
LOG(ERROR) << "Unsupported AccessibilityLiveRegion value: " << static_cast<int>(accessibilityLiveRegion);
789+
react_native_expect(false);
790+
return "none";
783791
}
784792
}
785793

@@ -795,6 +803,10 @@ inline std::string toString(AccessibilityState::CheckedState state)
795803
return "Mixed";
796804
case AccessibilityState::None:
797805
return "None";
806+
default:
807+
LOG(ERROR) << "Unsupported AccessibilityState::CheckedState value: " << static_cast<int>(state);
808+
react_native_expect(false);
809+
return "None";
798810
}
799811
}
800812

packages/react-native/ReactCommon/react/renderer/components/view/conversions.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ static inline PositionType positionTypeFromYogaPositionType(yoga::PositionType p
124124
return PositionType::Relative;
125125
case yoga::PositionType::Absolute:
126126
return PositionType::Absolute;
127+
default:
128+
LOG(ERROR) << "Unexpected yoga::PositionType value: " << static_cast<int>(positionType);
129+
react_native_expect(false);
130+
return PositionType::Relative;
127131
}
128132
}
129133

@@ -138,6 +142,10 @@ inline DisplayType displayTypeFromYGDisplay(YGDisplay display)
138142
return DisplayType::Flex;
139143
case YGDisplayGrid:
140144
return DisplayType::Grid;
145+
default:
146+
LOG(ERROR) << "Unexpected YGDisplay value: " << static_cast<int>(display);
147+
react_native_expect(false);
148+
return DisplayType::Flex;
141149
}
142150
}
143151

@@ -185,6 +193,10 @@ inline YGDirection yogaDirectionFromLayoutDirection(LayoutDirection direction)
185193
return YGDirectionLTR;
186194
case LayoutDirection::RightToLeft:
187195
return YGDirectionRTL;
196+
default:
197+
LOG(ERROR) << "Unexpected LayoutDirection value: " << static_cast<int>(direction);
198+
react_native_expect(false);
199+
return YGDirectionInherit;
188200
}
189201
}
190202

@@ -1113,6 +1125,10 @@ inline std::string toString(PointerEventsMode value)
11131125
return "box-none";
11141126
case PointerEventsMode::BoxOnly:
11151127
return "box-only";
1128+
default:
1129+
LOG(ERROR) << "Unsupported PointerEventsMode value: " << static_cast<int>(value);
1130+
react_native_expect(false);
1131+
return "auto";
11161132
}
11171133
}
11181134

@@ -1695,6 +1711,10 @@ inline std::string toString(const LayoutConformance &value)
16951711
return "strict";
16961712
case LayoutConformance::Compatibility:
16971713
return "compatibility";
1714+
default:
1715+
LOG(ERROR) << "Unsupported LayoutConformance value: " << static_cast<int>(value);
1716+
react_native_expect(false);
1717+
return "strict";
16981718
}
16991719
}
17001720

@@ -1774,6 +1794,10 @@ inline std::string toString(const Transform &transform)
17741794
result += "{\"identity\": true}";
17751795
break;
17761796
}
1797+
default:
1798+
LOG(ERROR) << "Unsupported TransformOperationType value: " << static_cast<int>(operation.type);
1799+
react_native_expect(false);
1800+
break;
17771801
}
17781802
}
17791803

packages/react-native/ReactCommon/react/renderer/css/CSSLength.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@ template <>
3131
struct CSSDataTypeParser<CSSLength> {
3232
static constexpr auto consumePreservedToken(const CSSPreservedToken &token) -> std::optional<CSSLength>
3333
{
34+
#ifdef __clang__
35+
#pragma clang diagnostic push
36+
#pragma clang diagnostic ignored "-Wswitch-enum"
37+
#endif
3438
switch (token.type()) {
39+
#ifdef __clang__
40+
#pragma clang diagnostic pop
41+
#endif
3542
case CSSTokenType::Dimension:
3643
if (auto unit = parseCSSLengthUnit(token.unit())) {
3744
return CSSLength{.value = token.numericValue(), .unit = *unit};

packages/react-native/ReactCommon/react/renderer/css/CSSTransformOrigin.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ struct CSSDataTypeParser<CSSTransformOrigin> {
195195
return CSSPercentage{100.0f};
196196
case CSSTransformOriginKeyword::Bottom:
197197
return CSSPercentage{100.0f};
198+
default:
199+
return {};
198200
}
199-
200-
return {};
201201
}
202202
};
203203

0 commit comments

Comments
 (0)