Skip to content

Commit

Permalink
Destroy buttons along with the main react view
Browse files Browse the repository at this point in the history
  • Loading branch information
yogevbd committed Oct 24, 2021
1 parent 9b0aa91 commit 27e604d
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 20 deletions.
3 changes: 2 additions & 1 deletion lib/ios/RNNBottomTabOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions lib/ios/RNNButtonBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
8 changes: 4 additions & 4 deletions lib/ios/RNNButtonOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down
3 changes: 2 additions & 1 deletion lib/ios/RNNDotIndicatorPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/ios/RNNSegmentedControl.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import <HMSegmentedControl/HMSegmentedControl.h>
#import <Foundation/Foundation.h>
#import <HMSegmentedControl/HMSegmentedControl.h>

@interface RNNSegmentedControl : HMSegmentedControl

Expand Down
5 changes: 3 additions & 2 deletions lib/ios/RNNTabBarItemCreator.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
}
}

Expand Down
4 changes: 3 additions & 1 deletion lib/ios/RNNUIBarButtonItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,4 +32,6 @@ typedef void (^RNNButtonPressCallback)(NSString *buttonId);
- (void)notifyDidAppear;
- (void)notifyDidDisappear;

- (void)invalidate;

@end
12 changes: 9 additions & 3 deletions lib/ios/RNNUIBarButtonItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -196,6 +196,12 @@ - (void)rootViewDidChangeIntrinsicSize:(RCTRootView *)rootView {
rootView.hidden = NO;
}

- (void)invalidate {
if ([self.customView isKindOfClass:[RNNReactView class]]) {
[((RNNReactView *)self.customView) invalidate];
}
}

- (void)onButtonPressed:(RNNUIBarButtonItem *)barButtonItem {
self.onPress(self.buttonId);
}
Expand Down
12 changes: 8 additions & 4 deletions lib/ios/TopBarPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
12 changes: 12 additions & 0 deletions lib/ios/UIViewController+LayoutProtocol.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

#import "RNNUIBarButtonItem.h"
#import "UIViewController+LayoutProtocol.h"
#import <objc/runtime.h>

Expand Down Expand Up @@ -105,6 +106,17 @@ - (void)destroy {
for (UIViewController *child in self.childViewControllers) {
[child destroy];
}

[self destroyButtons];
}

- (void)destroyButtons {
for (UIBarButtonItem *button in [self.navigationItem.leftBarButtonItems
arrayByAddingObjectsFromArray:self.navigationItem.rightBarButtonItems]) {
if ([button isKindOfClass:[RNNUIBarButtonItem class]]) {
[(RNNUIBarButtonItem *)button invalidate];
}
}
}

- (void)destroyReactView {
Expand Down

0 comments on commit 27e604d

Please sign in to comment.