From afd5e723dedf57ae95e5c692358aa025987a6f28 Mon Sep 17 00:00:00 2001 From: Kacper Kafara Date: Tue, 10 Dec 2024 08:10:37 +0100 Subject: [PATCH] refactor(iOS): simplify UINavigationControllerDelegate methods implementation (#2562) ## Description Noticed a low-hanging opportunity to simplify this method while doing something different. We already had this loop implemented in helper function so we could use it. ## Test code and steps to reproduce CI should be enough ## Checklist - [ ] Ensured that CI passes --- ios/RNSScreenStack.mm | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/ios/RNSScreenStack.mm b/ios/RNSScreenStack.mm index a405231717..87cf04e5a4 100644 --- a/ios/RNSScreenStack.mm +++ b/ios/RNSScreenStack.mm @@ -244,21 +244,16 @@ - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { - UIView *view = viewController.view; #ifdef RCT_NEW_ARCH_ENABLED - if (![view isKindOfClass:[RNSScreenView class]]) { + if (![viewController.view isKindOfClass:[RNSScreenView class]]) { // if the current view is a snapshot, config was already removed so we don't trigger the method return; } #endif - RNSScreenStackHeaderConfig *config = nil; - for (UIView *subview in view.reactSubviews) { - if ([subview isKindOfClass:[RNSScreenStackHeaderConfig class]]) { - config = (RNSScreenStackHeaderConfig *)subview; - break; - } - } - [RNSScreenStackHeaderConfig willShowViewController:viewController animated:animated withConfig:config]; + auto *screenView = static_cast(viewController.view); + [RNSScreenStackHeaderConfig willShowViewController:viewController + animated:animated + withConfig:screenView.findHeaderConfig]; } - (void)presentationControllerDidDismiss:(UIPresentationController *)presentationController