From ba3ee1621c88463af363810c138d33c78dc48c08 Mon Sep 17 00:00:00 2001 From: Yogev Ben David Date: Sun, 7 Nov 2021 16:59:59 +0200 Subject: [PATCH] Remove manually dismissing all modals on setRoot (#7340) Currently we manually dismiss all modals on `setRoot`, we should instead clear it from the modal manager so that those controllers will be automatically released by the reference count system. --- lib/ios/RNNAssert.h | 4 ++-- lib/ios/RNNBottomTabOptions.m | 3 ++- lib/ios/RNNButtonBuilder.m | 6 +++--- lib/ios/RNNButtonOptions.m | 8 ++++---- lib/ios/RNNCommandsHandler.m | 5 +---- lib/ios/RNNDotIndicatorPresenter.m | 3 ++- lib/ios/RNNModalManager.h | 2 ++ lib/ios/RNNModalManager.m | 5 +++++ lib/ios/RNNSegmentedControl.h | 2 +- lib/ios/RNNTabBarItemCreator.m | 5 +++-- lib/ios/RNNUIBarButtonItem.h | 2 +- lib/ios/RNNUIBarButtonItem.m | 6 +++--- lib/ios/TopBarPresenter.m | 12 ++++++++---- 13 files changed, 37 insertions(+), 26 deletions(-) diff --git a/lib/ios/RNNAssert.h b/lib/ios/RNNAssert.h index 1cc79aa8d51..9d4db01738c 100644 --- a/lib/ios/RNNAssert.h +++ b/lib/ios/RNNAssert.h @@ -12,8 +12,8 @@ extern BOOL RNNIsMainQueue(void); if ((condition) == 0) { \ if (RNN_NSASSERT) { \ [[NSAssertionHandler currentHandler] \ - handleFailureInFunction:(NSString * _Nonnull) @(__func__) \ - file:(NSString * _Nonnull) @(__FILE__) \ + handleFailureInFunction:(NSString *_Nonnull)@(__func__) \ + file:(NSString *_Nonnull)@(__FILE__) \ lineNumber:__LINE__ \ description:__VA_ARGS__]; \ } \ diff --git a/lib/ios/RNNBottomTabOptions.m b/lib/ios/RNNBottomTabOptions.m index 0f24da1d61a..a164e64aae4 100644 --- a/lib/ios/RNNBottomTabOptions.m +++ b/lib/ios/RNNBottomTabOptions.m @@ -84,7 +84,8 @@ - (BOOL)hasValue { self.testID.hasValue || self.icon.hasValue || self.selectedIcon.hasValue || self.iconColor.hasValue || self.selectedIconColor.hasValue || self.selectedTextColor.hasValue || self.iconInsets.hasValue || self.textColor.hasValue || - self.visible.hasValue || self.selectTabOnPress.hasValue || self.sfSymbol.hasValue || self.sfSelectedSymbol.hasValue; + self.visible.hasValue || self.selectTabOnPress.hasValue || self.sfSymbol.hasValue || + self.sfSelectedSymbol.hasValue; } @end diff --git a/lib/ios/RNNButtonBuilder.m b/lib/ios/RNNButtonBuilder.m index ff2cad4fed8..24e3cb3589b 100644 --- a/lib/ios/RNNButtonBuilder.m +++ b/lib/ios/RNNButtonBuilder.m @@ -31,9 +31,9 @@ - (RNNUIBarButtonItem *)build:(RNNButtonOptions *)button return [[RNNUIBarButtonItem alloc] initCustomIcon:button iconCreator:_iconCreator onPress:onPress]; - } else if (button.sfSymbol.hasValue) { - return [[RNNUIBarButtonItem alloc] initWithSFSymbol:button onPress:onPress]; - } else if (button.icon.hasValue) { + } else if (button.sfSymbol.hasValue) { + return [[RNNUIBarButtonItem alloc] initWithSFSymbol:button onPress:onPress]; + } else if (button.icon.hasValue) { return [[RNNUIBarButtonItem alloc] initWithIcon:button onPress:onPress]; } else if (button.text.hasValue) { return [[RNNUIBarButtonItem alloc] initWithTitle:button onPress:onPress]; diff --git a/lib/ios/RNNButtonOptions.m b/lib/ios/RNNButtonOptions.m index 8f4d4ab69fa..a3119131d8d 100644 --- a/lib/ios/RNNButtonOptions.m +++ b/lib/ios/RNNButtonOptions.m @@ -11,7 +11,7 @@ - (instancetype)initWithDict:(NSDictionary *)dict { self.fontWeight = [TextParser parse:dict key:@"fontWeight"]; self.fontSize = [NumberParser parse:dict key:@"fontSize"]; self.text = [TextParser parse:dict key:@"text"]; - self.sfSymbol = [TextParser parse:dict key:@"sfSymbol"]; + self.sfSymbol = [TextParser parse:dict key:@"sfSymbol"]; self.testID = [TextParser parse:dict key:@"testID"]; self.accessibilityLabel = [TextParser parse:dict key:@"accessibilityLabel"]; self.color = [ColorParser parse:dict key:@"color"]; @@ -40,7 +40,7 @@ - (RNNButtonOptions *)copy { newOptions.color = self.color.copy; newOptions.disabledColor = self.disabledColor.copy; newOptions.icon = self.icon.copy; - newOptions.sfSymbol = self.sfSymbol.copy; + newOptions.sfSymbol = self.sfSymbol.copy; newOptions.iconInsets = self.iconInsets.copy; newOptions.enabled = self.enabled.copy; newOptions.selectTabOnPress = self.selectTabOnPress.copy; @@ -73,8 +73,8 @@ - (void)mergeOptions:(RNNButtonOptions *)options { self.disabledColor = options.disabledColor; if (options.icon.hasValue) self.icon = options.icon; - if (options.sfSymbol.hasValue) - self.sfSymbol = options.sfSymbol; + if (options.sfSymbol.hasValue) + self.sfSymbol = options.sfSymbol; if (options.enabled.hasValue) { self.enabled = options.enabled; [self.iconBackground setEnabled:self.enabled]; diff --git a/lib/ios/RNNCommandsHandler.m b/lib/ios/RNNCommandsHandler.m index 5eb5078892d..3c6c67fab21 100644 --- a/lib/ios/RNNCommandsHandler.m +++ b/lib/ios/RNNCommandsHandler.m @@ -82,10 +82,7 @@ - (void)setRoot:(NSDictionary *)layout } } - [_modalManager dismissAllModalsAnimated:NO - completion:^{ - - }]; + [_modalManager reset]; UIViewController *vc = [_controllerFactory createLayout:layout[@"root"]]; [_layoutManager addPendingViewController:vc]; diff --git a/lib/ios/RNNDotIndicatorPresenter.m b/lib/ios/RNNDotIndicatorPresenter.m index 6869d071e20..635c1151f2a 100644 --- a/lib/ios/RNNDotIndicatorPresenter.m +++ b/lib/ios/RNNDotIndicatorPresenter.m @@ -92,7 +92,8 @@ - (BOOL)currentIndicatorEquals:(UIViewController *)child options:(DotIndicatorOp return NO; UIView *currentIndicator = [self getCurrentIndicator:child]; - return [[currentIndicator backgroundColor] isEqual:[options.color withDefault:[UIColor redColor]]]; + return + [[currentIndicator backgroundColor] isEqual:[options.color withDefault:[UIColor redColor]]]; } - (UIView *)getCurrentIndicator:(UIViewController *)child { diff --git a/lib/ios/RNNModalManager.h b/lib/ios/RNNModalManager.h index 609e6bb8065..07b431b837d 100644 --- a/lib/ios/RNNModalManager.h +++ b/lib/ios/RNNModalManager.h @@ -24,4 +24,6 @@ typedef void (^RNNTransitionRejectionBlock)(NSString *_Nonnull code, NSString *_ - (void)dismissAllModalsAnimated:(BOOL)animated completion:(void (^__nullable)(void))completion; - (void)dismissAllModalsSynchronosly; +- (void)reset; + @end diff --git a/lib/ios/RNNModalManager.m b/lib/ios/RNNModalManager.m index c50ef61983d..f6b379c2765 100644 --- a/lib/ios/RNNModalManager.m +++ b/lib/ios/RNNModalManager.m @@ -143,6 +143,11 @@ - (void)dismissAllModalsSynchronosly { } } +- (void)reset { + [_presentedModals removeAllObjects]; + [_pendingModalIdsToDismiss removeAllObjects]; +} + #pragma mark - private - (void)removePendingNextModalIfOnTop:(RNNTransitionCompletionBlock)completion diff --git a/lib/ios/RNNSegmentedControl.h b/lib/ios/RNNSegmentedControl.h index 41771612a73..64ddd8d14d4 100644 --- a/lib/ios/RNNSegmentedControl.h +++ b/lib/ios/RNNSegmentedControl.h @@ -1,5 +1,5 @@ -#import #import +#import @interface RNNSegmentedControl : HMSegmentedControl diff --git a/lib/ios/RNNTabBarItemCreator.m b/lib/ios/RNNTabBarItemCreator.m index b795501f568..140c7be8961 100644 --- a/lib/ios/RNNTabBarItemCreator.m +++ b/lib/ios/RNNTabBarItemCreator.m @@ -18,11 +18,12 @@ - (UITabBarItem *)createTabBarItem:(RNNBottomTabOptions *)bottomTabOptions if (@available(iOS 13.0, *)) { if (bottomTabOptions.sfSymbol.hasValue) { - icon = [UIImage systemImageNamed: [bottomTabOptions.sfSymbol withDefault:nil]]; + icon = [UIImage systemImageNamed:[bottomTabOptions.sfSymbol withDefault:nil]]; } if (bottomTabOptions.sfSelectedSymbol.hasValue) { - selectedIcon = [UIImage systemImageNamed: [bottomTabOptions.sfSelectedSymbol withDefault:nil]]; + selectedIcon = + [UIImage systemImageNamed:[bottomTabOptions.sfSelectedSymbol withDefault:nil]]; } } diff --git a/lib/ios/RNNUIBarButtonItem.h b/lib/ios/RNNUIBarButtonItem.h index bbffeea3222..47ffde69581 100644 --- a/lib/ios/RNNUIBarButtonItem.h +++ b/lib/ios/RNNUIBarButtonItem.h @@ -15,7 +15,7 @@ typedef void (^RNNButtonPressCallback)(NSString *buttonId); iconCreator:(RNNIconCreator *)iconCreator onPress:(RNNButtonPressCallback)onPress; - (instancetype)initWithSFSymbol:(RNNButtonOptions *)buttonOptions - onPress:(RNNButtonPressCallback)onPress; + onPress:(RNNButtonPressCallback)onPress; - (instancetype)initWithIcon:(RNNButtonOptions *)buttonOptions onPress:(RNNButtonPressCallback)onPress; - (instancetype)initWithTitle:(RNNButtonOptions *)buttonOptions diff --git a/lib/ios/RNNUIBarButtonItem.m b/lib/ios/RNNUIBarButtonItem.m index 4f177c2cde0..c49cb2fb8df 100644 --- a/lib/ios/RNNUIBarButtonItem.m +++ b/lib/ios/RNNUIBarButtonItem.m @@ -21,12 +21,12 @@ - (instancetype)init { } - (instancetype)initWithSFSymbol:(RNNButtonOptions *)buttonOptions - onPress:(RNNButtonPressCallback)onPress { + onPress:(RNNButtonPressCallback)onPress { UIImage *iconImage = [UIImage alloc]; - if (@available(iOS 13.0, *)) { + if (@available(iOS 13.0, *)) { iconImage = [UIImage systemImageNamed:[buttonOptions.sfSymbol withDefault:nil]]; - } + } self = [super initWithImage:iconImage style:UIBarButtonItemStylePlain diff --git a/lib/ios/TopBarPresenter.m b/lib/ios/TopBarPresenter.m index a5b5ca1bcc7..2c9c35fe6a6 100644 --- a/lib/ios/TopBarPresenter.m +++ b/lib/ios/TopBarPresenter.m @@ -160,17 +160,21 @@ - (void)setBackButtonOptions:(RNNBackButtonOptions *)backButtonOptions { UIBarButtonItem *backItem = [[RNNUIBarBackButtonItem alloc] initWithOptions:backButtonOptions]; UINavigationItem *previousNavigationItem = previousViewControllerInStack.navigationItem; - if (@available(iOS 13.0, *)) { UIImage *sfSymbol = [UIImage systemImageNamed:[backButtonOptions.sfSymbol withDefault:nil]]; if (backButtonOptions.sfSymbol.hasValue) { - icon = color ? [sfSymbol imageWithTintColor:color renderingMode:UIImageRenderingModeAlwaysOriginal] + icon = color ? [sfSymbol imageWithTintColor:color + renderingMode:UIImageRenderingModeAlwaysOriginal] : [sfSymbol imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; } else { - icon = color ? [[icon withTintColor:color] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] : icon; + icon = color ? [[icon withTintColor:color] + imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] + : icon; } } else { - icon = color ? [[icon withTintColor:color] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] : icon; + icon = color ? [[icon withTintColor:color] + imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] + : icon; } [self setBackIndicatorImage:icon withColor:color];