From 9f16ccde403adbbc81096fd572b4c4ece5edc8fd Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Mon, 21 Sep 2026 11:17:06 -0700 Subject: [PATCH] Remove init-variables clang-tidy workarounds Summary: Restore idiomatic Objective-C fast enumeration now that React Native no longer enables the incompatible `cppcoreguidelines-init-variables` check. Changelog: [Internal] Differential Revision: D121040575 --- .../React/DevSupport/RCTFrameTimingsObserver.mm | 2 +- .../react-native/React/Fabric/AppleEventBeat.mm | 5 +---- .../ScrollView/RCTVirtualViewContainerState.mm | 2 +- .../ComponentViews/View/RCTViewComponentView.mm | 14 +++++++------- .../textlayoutmanager/RCTTextLayoutManager.mm | 1 - 5 files changed, 10 insertions(+), 14 deletions(-) diff --git a/packages/react-native/React/DevSupport/RCTFrameTimingsObserver.mm b/packages/react-native/React/DevSupport/RCTFrameTimingsObserver.mm index 51087cfd5d52..aa3c57043d0d 100644 --- a/packages/react-native/React/DevSupport/RCTFrameTimingsObserver.mm +++ b/packages/react-native/React/DevSupport/RCTFrameTimingsObserver.mm @@ -294,7 +294,7 @@ - (UIWindow *)_getKeyWindow if (scene.activationState == UISceneActivationStateForegroundActive && [scene isKindOfClass:[UIWindowScene class]]) { auto windowScene = (UIWindowScene *)scene; - for (UIWindow *window = nullptr in windowScene.windows) { + for (UIWindow *window in windowScene.windows) { if (window.isKeyWindow) { return window; } diff --git a/packages/react-native/React/Fabric/AppleEventBeat.mm b/packages/react-native/React/Fabric/AppleEventBeat.mm index 66f93729aee8..aac259b214d8 100644 --- a/packages/react-native/React/Fabric/AppleEventBeat.mm +++ b/packages/react-native/React/Fabric/AppleEventBeat.mm @@ -84,11 +84,8 @@ - (void)display // before it executes is made safe by the owner check above. NSMapTable *layers = layers_; RCTExecuteOnMainQueue(^{ - NSEnumerator *enumerator = layers.objectEnumerator; - RCTEventBeatFlusherLayer *layer = enumerator.nextObject; - while (layer != nil) { + for (RCTEventBeatFlusherLayer *layer in layers.objectEnumerator) { [layer removeFromSuperlayer]; - layer = enumerator.nextObject; } }); } diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTVirtualViewContainerState.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTVirtualViewContainerState.mm index 8cbc43f8cb70..c24314e0552a 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTVirtualViewContainerState.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTVirtualViewContainerState.mm @@ -143,7 +143,7 @@ - (void)_updateModes:(id)virtualView NSArray> *virtualViewsIt = (virtualView != nullptr) ? @[ virtualView ] : [_virtualViews allObjects]; - for (id vv = nullptr in virtualViewsIt) { + for (id vv in virtualViewsIt) { CGRect rect = [vv containerRelativeRect:scrollView]; RCTVirtualViewMode mode = RCTVirtualViewModeHidden; diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm index 37db047e8b25..61ef98f921cd 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm @@ -757,7 +757,7 @@ - (void)prepareForRecycle // Clean up box shadow layers to prevent cross-component contamination if (_boxShadowLayers != nullptr) { - for (CALayer *boxShadowLayer = nullptr in _boxShadowLayers) { + for (CALayer *boxShadowLayer in _boxShadowLayers) { [boxShadowLayer removeFromSuperlayer]; } [_boxShadowLayers removeAllObjects]; @@ -817,7 +817,7 @@ - (UIView *)betterHitTest:(CGPoint)point withEvent:(UIEvent *)event return nil; } - for (UIView *subview = nullptr in [currentContainerView.subviews reverseObjectEnumerator]) { + for (UIView *subview in [currentContainerView.subviews reverseObjectEnumerator]) { UIView *hitView = [subview hitTest:[subview convertPoint:point fromView:currentContainerView] withEvent:event]; if (hitView) { return hitView; @@ -975,7 +975,7 @@ - (UIView *)effectiveContentView if (_swiftUIWrapper == nullptr) { _swiftUIWrapper = [RCTSwiftUIContainerViewWrapper new]; UIView *swiftUIContentView = [[UIView alloc] init]; - for (UIView *subview = nullptr in self.subviews) { + for (UIView *subview in self.subviews) { [swiftUIContentView addSubview:subview]; } swiftUIContentView.clipsToBounds = self.clipsToBounds; @@ -993,7 +993,7 @@ - (UIView *)effectiveContentView } else { if (_swiftUIWrapper != nullptr) { UIView *swiftUIContentView = _swiftUIWrapper.contentView; - for (UIView *subview = nullptr in swiftUIContentView.subviews) { + for (UIView *subview in swiftUIContentView.subviews) { [self addSubview:subview]; } self.clipsToBounds = swiftUIContentView.clipsToBounds; @@ -1019,7 +1019,7 @@ - (UIView *)currentContainerView if (_useCustomContainerView) { if (!_containerView) { _containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)]; - for (UIView *subview = nullptr in effectiveContentView.subviews) { + for (UIView *subview in effectiveContentView.subviews) { [_containerView addSubview:subview]; } _containerView.clipsToBounds = effectiveContentView.clipsToBounds; @@ -1805,10 +1805,10 @@ - (void)transferVisualPropertiesFromView:(UIView *)sourceView toView:(UIView *)d if (_filterLayer != nullptr) { [destinationView.layer addSublayer:_filterLayer]; } - for (CALayer *layer = nullptr in _backgroundImageLayers) { + for (CALayer *layer in _backgroundImageLayers) { [destinationView.layer addSublayer:layer]; } - for (CALayer *layer = nullptr in _boxShadowLayers) { + for (CALayer *layer in _boxShadowLayers) { [destinationView.layer addSublayer:layer]; } } diff --git a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm index 58a9879af9d5..af5b225e8e7e 100644 --- a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm +++ b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm @@ -234,7 +234,6 @@ - (void)drawAttributedString:(AttributedString)attributedString CGFloat baseline = lineRect.origin.y + font.ascender + frame.origin.y; - // NOLINTNEXTLINE(cppcoreguidelines-init-variables) for (NSString *line in lines) { CGFloat y = 0.0f; if ([line isEqualToString:@"underline"]) {