Bläddra i källkod

Prevent creation of button react view with the same componentId (#5687)

When updating buttons with mergeOptions, existing custom buttons are unmounted and then recreated. This commit adds an optimisation which prevents the react components from being recreated.
To avoid unnecessary recreation, add an `id` to the component. If an existing react view is found for that id, it will be reused.
Yogev Ben David 5 år sedan
förälder
incheckning
1807c5b48d

+ 11
- 0
lib/ios/NSArray+utils.h Visa fil

@@ -0,0 +1,11 @@
1
+#import <Foundation/Foundation.h>
2
+
3
+@interface NSArray (utils)
4
+
5
+- (NSArray *)intersect:(NSArray *)array withPropertyName:(NSString *)propertyName;
6
+
7
+- (NSArray *)difference:(NSArray *)array withPropertyName:(NSString *)propertyName;
8
+
9
+- (NSArray *)mapObjectsUsingBlock:(id (^)(id obj, NSUInteger idx))block;
10
+
11
+@end

+ 31
- 0
lib/ios/NSArray+utils.m Visa fil

@@ -0,0 +1,31 @@
1
+#import "NSArray+utils.h"
2
+
3
+@implementation NSArray (utils)
4
+
5
+- (NSArray *)intersect:(NSArray *)array withPropertyName:(NSString *)propertyName {
6
+    NSMutableArray* intersection = [NSMutableArray new];
7
+    for (NSObject* object in array) {
8
+        NSArray* filteredArray = [self filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"%@ == %@", propertyName, object]];
9
+        [intersection addObjectsFromArray:filteredArray];
10
+    }
11
+    
12
+    return [NSArray arrayWithArray:intersection];
13
+}
14
+
15
+- (NSArray *)difference:(NSArray *)array withPropertyName:(NSString *)propertyName {
16
+    NSMutableArray* diff = [NSMutableArray arrayWithArray:self];
17
+    NSArray* intersection = [self intersect:array withPropertyName:propertyName];
18
+    [diff removeObjectsInArray:intersection];
19
+    
20
+    return [NSArray arrayWithArray:diff];
21
+}
22
+
23
+- (NSArray *)mapObjectsUsingBlock:(id (^)(id obj, NSUInteger idx))block {
24
+    NSMutableArray *result = [NSMutableArray arrayWithCapacity:[self count]];
25
+    [self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
26
+        [result addObject:block(obj, idx)];
27
+    }];
28
+    return result;
29
+}
30
+
31
+@end

+ 151
- 137
lib/ios/RNNNavigationButtons.m Visa fil

@@ -7,6 +7,7 @@
7 7
 #import "UIImage+insets.h"
8 8
 #import "UIViewController+LayoutProtocol.h"
9 9
 #import "RNNFontAttributesCreator.h"
10
+#import "NSArray+utils.h"
10 11
 
11 12
 @interface RNNNavigationButtons()
12 13
 
@@ -19,167 +20,180 @@
19 20
 @implementation RNNNavigationButtons
20 21
 
21 22
 -(instancetype)initWithViewController:(UIViewController<RNNLayoutProtocol>*)viewController componentRegistry:(id)componentRegistry {
22
-	self = [super init];
23
-	
24
-	self.viewController = viewController;
25
-	self.componentRegistry = componentRegistry;
26
-	
27
-	return self;
23
+    self = [super init];
24
+    
25
+    self.viewController = viewController;
26
+    self.componentRegistry = componentRegistry;
27
+    
28
+    return self;
28 29
 }
29 30
 
30 31
 - (void)applyLeftButtons:(NSArray *)leftButtons rightButtons:(NSArray *)rightButtons defaultLeftButtonStyle:(RNNButtonOptions *)defaultLeftButtonStyle defaultRightButtonStyle:(RNNButtonOptions *)defaultRightButtonStyle {
31
-	_defaultLeftButtonStyle = defaultLeftButtonStyle;
32
-	_defaultRightButtonStyle = defaultRightButtonStyle;
33
-	if (leftButtons) {
34
-		[self setButtons:leftButtons side:@"left" animated:NO defaultStyle:_defaultLeftButtonStyle insets:[self leftButtonInsets:_defaultLeftButtonStyle.iconInsets]];
35
-	}
36
-	
37
-	if (rightButtons) {
38
-		[self setButtons:rightButtons side:@"right" animated:NO defaultStyle:_defaultRightButtonStyle insets:[self rightButtonInsets:_defaultRightButtonStyle.iconInsets]];
39
-	}
32
+    _defaultLeftButtonStyle = defaultLeftButtonStyle;
33
+    _defaultRightButtonStyle = defaultRightButtonStyle;
34
+    if (leftButtons) {
35
+        [self setButtons:leftButtons side:@"left" animated:NO defaultStyle:_defaultLeftButtonStyle insets:[self leftButtonInsets:_defaultLeftButtonStyle.iconInsets]];
36
+    }
37
+    
38
+    if (rightButtons) {
39
+        [self setButtons:rightButtons side:@"right" animated:NO defaultStyle:_defaultRightButtonStyle insets:[self rightButtonInsets:_defaultRightButtonStyle.iconInsets]];
40
+    }
40 41
 }
41 42
 
42 43
 -(void)setButtons:(NSArray*)buttons side:(NSString*)side animated:(BOOL)animated defaultStyle:(RNNButtonOptions *)defaultStyle insets:(UIEdgeInsets)insets {
43
-	NSMutableArray *barButtonItems = [NSMutableArray new];
44
-	NSArray* resolvedButtons = [self resolveButtons:buttons];
45
-	for (NSDictionary *button in resolvedButtons) {
46
-		RNNUIBarButtonItem* barButtonItem = [self buildButton:button defaultStyle:defaultStyle insets:insets];
47
-		if(barButtonItem) {
48
-			[barButtonItems addObject:barButtonItem];
49
-		}
50
-		UIColor* color = [self color:[RCTConvert UIColor:button[@"color"]] defaultColor:[defaultStyle.color getWithDefaultValue:nil]];
51
-		if (color) {
52
-			self.viewController.navigationController.navigationBar.tintColor = color;
53
-		}
54
-	}
55
-	
56
-	if ([side isEqualToString:@"left"]) {
57
-		[self.viewController.navigationItem setLeftBarButtonItems:barButtonItems animated:animated];
58
-	}
59
-	
60
-	if ([side isEqualToString:@"right"]) {
61
-		[self.viewController.navigationItem setRightBarButtonItems:barButtonItems animated:animated];
62
-	}
44
+    NSMutableArray *barButtonItems = [NSMutableArray new];
45
+    NSArray* resolvedButtons = [self resolveButtons:buttons];
46
+    for (NSDictionary *button in resolvedButtons) {
47
+        RNNUIBarButtonItem* barButtonItem = [self buildButton:button defaultStyle:defaultStyle insets:insets];
48
+        if(barButtonItem) {
49
+            [barButtonItems addObject:barButtonItem];
50
+        }
51
+        UIColor* color = [self color:[RCTConvert UIColor:button[@"color"]] defaultColor:[defaultStyle.color getWithDefaultValue:nil]];
52
+        if (color) {
53
+            self.viewController.navigationController.navigationBar.tintColor = color;
54
+        }
55
+    }
56
+    
57
+    if ([side isEqualToString:@"left"]) {
58
+        [self clearPreviousButtonViews:barButtonItems oldButtons:self.viewController.navigationItem.leftBarButtonItems];
59
+        [self.viewController.navigationItem setLeftBarButtonItems:barButtonItems animated:animated];
60
+    }
61
+    
62
+    if ([side isEqualToString:@"right"]) {
63
+        [self clearPreviousButtonViews:barButtonItems oldButtons:self.viewController.navigationItem.rightBarButtonItems];
64
+        [self.viewController.navigationItem setRightBarButtonItems:barButtonItems animated:animated];
65
+    }
66
+}
67
+
68
+- (void)clearPreviousButtonViews:(NSArray<UIBarButtonItem *> *)newButtons oldButtons:(NSArray<UIBarButtonItem *> *)oldButtons {
69
+    NSArray<UIBarButtonItem *>* removedButtons = [oldButtons difference:newButtons withPropertyName:@"customView"];
70
+    
71
+    for (UIBarButtonItem* buttonItem in removedButtons) {
72
+        RNNReactView* reactView = buttonItem.customView;
73
+        if ([reactView isKindOfClass:[RNNReactView class]]) {
74
+            [_componentRegistry removeChildComponent:reactView.componentId];
75
+        }
76
+    }
63 77
 }
64 78
 
65 79
 - (NSArray *)resolveButtons:(id)buttons {
66
-	if ([buttons isKindOfClass:[NSArray class]]) {
67
-		return buttons;
68
-	} else {
69
-		return @[buttons];
70
-	}
80
+    if ([buttons isKindOfClass:[NSArray class]]) {
81
+        return buttons;
82
+    } else {
83
+        return @[buttons];
84
+    }
71 85
 }
72 86
 
73 87
 -(RNNUIBarButtonItem*)buildButton: (NSDictionary*)dictionary defaultStyle:(RNNButtonOptions *)defaultStyle insets:(UIEdgeInsets)insets {
74
-	NSString* buttonId = dictionary[@"id"];
75
-	NSString* title = [self getValue:dictionary[@"text"] withDefault:[defaultStyle.text getWithDefaultValue:nil]];
76
-	NSDictionary* component = dictionary[@"component"];
77
-	NSString* systemItemName = dictionary[@"systemItem"];
78
-	
79
-	UIColor* color = [self color:[RCTConvert UIColor:dictionary[@"color"]] defaultColor:[defaultStyle.color getWithDefaultValue:nil]];
80
-	UIColor* disabledColor = [self color:[RCTConvert UIColor:dictionary[@"disabledColor"]] defaultColor:[defaultStyle.disabledColor getWithDefaultValue:nil]];
81
-	
82
-	if (!buttonId) {
83
-		@throw [NSException exceptionWithName:@"NSInvalidArgumentException" reason:[@"button id is not specified " stringByAppendingString:title] userInfo:nil];
84
-	}
85
-	
86
-	UIImage* defaultIcon = [defaultStyle.icon getWithDefaultValue:nil];
87
-	UIImage* iconImage = [self getValue:dictionary[@"icon"] withDefault:defaultIcon];
88
-	if (![iconImage isKindOfClass:[UIImage class]]) {
89
-		iconImage = [RCTConvert UIImage:iconImage];
90
-	}
91
-	
92
-	if (iconImage) {
93
-		iconImage = [iconImage imageWithInsets:insets];
94
-		if (color) {
95
-			iconImage = [iconImage withTintColor:color];
96
-		}
97
-	}
98
-	
99
-	
100
-	RNNUIBarButtonItem *barButtonItem;
101
-	if (component) {
102
-		RNNComponentOptions* componentOptions = [RNNComponentOptions new];
103
-		componentOptions.componentId = [[Text alloc] initWithValue:component[@"componentId"]];
104
-		componentOptions.name = [[Text alloc] initWithValue:component[@"name"]];
105
-		
106
-		RNNReactView *view = [_componentRegistry createComponentIfNotExists:componentOptions parentComponentId:self.viewController.layoutInfo.componentId reactViewReadyBlock:nil];
107
-		barButtonItem = [[RNNUIBarButtonItem alloc] init:buttonId withCustomView:view componentRegistry:_componentRegistry];
108
-	} else if (iconImage) {
109
-		barButtonItem = [[RNNUIBarButtonItem alloc] init:buttonId withIcon:iconImage];
110
-	} else if (title) {
111
-		barButtonItem = [[RNNUIBarButtonItem alloc] init:buttonId withTitle:title];
112
-		
113
-		NSMutableDictionary *buttonTextAttributes = [RCTHelpers textAttributesFromDictionary:dictionary withPrefix:@"button"];
114
-		if (buttonTextAttributes.allKeys.count > 0) {
115
-			[barButtonItem setTitleTextAttributes:buttonTextAttributes forState:UIControlStateNormal];
116
-		}
117
-	} else if (systemItemName) {
118
-		barButtonItem = [[RNNUIBarButtonItem alloc] init:buttonId withSystemItem:systemItemName];
119
-	} else {
120
-		return nil;
121
-	}
122
-	
123
-	barButtonItem.target = self.viewController;
124
-	barButtonItem.action = @selector(onButtonPress:);
125
-	
126
-	NSNumber *enabled = [self getValue:dictionary[@"enabled"] withDefault:defaultStyle.enabled.getValue];
127
-	BOOL enabledBool = enabled ? [enabled boolValue] : YES;
128
-	[barButtonItem setEnabled:enabledBool];
129
-	
130
-	NSMutableDictionary* textAttributes = [NSMutableDictionary dictionaryWithDictionary:[RNNFontAttributesCreator createWithFontFamily:dictionary[@"fontFamily"] ?: [defaultStyle.fontFamily getWithDefaultValue:nil] fontSize:dictionary[@"fontSize"] defaultFontSize:[defaultStyle.fontSize getWithDefaultValue:@(17)] fontWeight:dictionary[@"fontWeight"] color:nil defaultColor:nil]];
131
-	NSMutableDictionary* disabledTextAttributes = [NSMutableDictionary dictionaryWithDictionary:[RNNFontAttributesCreator createWithFontFamily:dictionary[@"fontFamily"] ?: [defaultStyle.fontFamily getWithDefaultValue:nil] fontSize:dictionary[@"fontSize"] defaultFontSize:[defaultStyle.fontSize getWithDefaultValue:@(17)] fontWeight:dictionary[@"fontWeight"] color:nil defaultColor:nil]];
132
-	
133
-	if (!enabledBool && disabledColor) {
134
-		color = disabledColor;
135
-		[disabledTextAttributes setObject:disabledColor forKey:NSForegroundColorAttributeName];
136
-	}
137
-	
138
-	if (color) {
139
-		[textAttributes setObject:color forKey:NSForegroundColorAttributeName];
140
-		[barButtonItem setImage:[[iconImage withTintColor:color] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
141
-		barButtonItem.tintColor = color;
142
-	}
143
-
144
-	[barButtonItem setTitleTextAttributes:textAttributes forState:UIControlStateNormal];
145
-	[barButtonItem setTitleTextAttributes:textAttributes forState:UIControlStateHighlighted];
146
-	[barButtonItem setTitleTextAttributes:disabledTextAttributes forState:UIControlStateDisabled];
147
-	
148
-	NSString *testID = dictionary[@"testID"];
149
-	if (testID)
150
-	{
151
-		barButtonItem.accessibilityIdentifier = testID;
152
-	}
153
-	
154
-	return barButtonItem;
88
+    NSString* buttonId = dictionary[@"id"];
89
+    NSString* title = [self getValue:dictionary[@"text"] withDefault:[defaultStyle.text getWithDefaultValue:nil]];
90
+    NSDictionary* component = dictionary[@"component"];
91
+    NSString* systemItemName = dictionary[@"systemItem"];
92
+    
93
+    UIColor* color = [self color:[RCTConvert UIColor:dictionary[@"color"]] defaultColor:[defaultStyle.color getWithDefaultValue:nil]];
94
+    UIColor* disabledColor = [self color:[RCTConvert UIColor:dictionary[@"disabledColor"]] defaultColor:[defaultStyle.disabledColor getWithDefaultValue:nil]];
95
+    
96
+    if (!buttonId) {
97
+        @throw [NSException exceptionWithName:@"NSInvalidArgumentException" reason:[@"button id is not specified " stringByAppendingString:title] userInfo:nil];
98
+    }
99
+    
100
+    UIImage* defaultIcon = [defaultStyle.icon getWithDefaultValue:nil];
101
+    UIImage* iconImage = [self getValue:dictionary[@"icon"] withDefault:defaultIcon];
102
+    if (![iconImage isKindOfClass:[UIImage class]]) {
103
+        iconImage = [RCTConvert UIImage:iconImage];
104
+    }
105
+    
106
+    if (iconImage) {
107
+        iconImage = [iconImage imageWithInsets:insets];
108
+        if (color) {
109
+            iconImage = [iconImage withTintColor:color];
110
+        }
111
+    }
112
+    
113
+    
114
+    RNNUIBarButtonItem *barButtonItem;
115
+    if (component) {
116
+        RNNComponentOptions* componentOptions = [RNNComponentOptions new];
117
+        componentOptions.componentId = [[Text alloc] initWithValue:component[@"componentId"]];
118
+        componentOptions.name = [[Text alloc] initWithValue:component[@"name"]];
119
+        
120
+        RNNReactView *view = [_componentRegistry createComponentIfNotExists:componentOptions parentComponentId:self.viewController.layoutInfo.componentId reactViewReadyBlock:nil];
121
+        barButtonItem = [[RNNUIBarButtonItem alloc] init:buttonId withCustomView:view];
122
+    } else if (iconImage) {
123
+        barButtonItem = [[RNNUIBarButtonItem alloc] init:buttonId withIcon:iconImage];
124
+    } else if (title) {
125
+        barButtonItem = [[RNNUIBarButtonItem alloc] init:buttonId withTitle:title];
126
+        
127
+        NSMutableDictionary *buttonTextAttributes = [RCTHelpers textAttributesFromDictionary:dictionary withPrefix:@"button"];
128
+        if (buttonTextAttributes.allKeys.count > 0) {
129
+            [barButtonItem setTitleTextAttributes:buttonTextAttributes forState:UIControlStateNormal];
130
+        }
131
+    } else if (systemItemName) {
132
+        barButtonItem = [[RNNUIBarButtonItem alloc] init:buttonId withSystemItem:systemItemName];
133
+    } else {
134
+        return nil;
135
+    }
136
+    
137
+    barButtonItem.target = self.viewController;
138
+    barButtonItem.action = @selector(onButtonPress:);
139
+    
140
+    NSNumber *enabled = [self getValue:dictionary[@"enabled"] withDefault:defaultStyle.enabled.getValue];
141
+    BOOL enabledBool = enabled ? [enabled boolValue] : YES;
142
+    [barButtonItem setEnabled:enabledBool];
143
+    
144
+    NSMutableDictionary* textAttributes = [NSMutableDictionary dictionaryWithDictionary:[RNNFontAttributesCreator createWithFontFamily:dictionary[@"fontFamily"] ?: [defaultStyle.fontFamily getWithDefaultValue:nil] fontSize:dictionary[@"fontSize"] defaultFontSize:[defaultStyle.fontSize getWithDefaultValue:@(17)] fontWeight:dictionary[@"fontWeight"] color:nil defaultColor:nil]];
145
+    NSMutableDictionary* disabledTextAttributes = [NSMutableDictionary dictionaryWithDictionary:[RNNFontAttributesCreator createWithFontFamily:dictionary[@"fontFamily"] ?: [defaultStyle.fontFamily getWithDefaultValue:nil] fontSize:dictionary[@"fontSize"] defaultFontSize:[defaultStyle.fontSize getWithDefaultValue:@(17)] fontWeight:dictionary[@"fontWeight"] color:nil defaultColor:nil]];
146
+    
147
+    if (!enabledBool && disabledColor) {
148
+        color = disabledColor;
149
+        [disabledTextAttributes setObject:disabledColor forKey:NSForegroundColorAttributeName];
150
+    }
151
+    
152
+    if (color) {
153
+        [textAttributes setObject:color forKey:NSForegroundColorAttributeName];
154
+        [barButtonItem setImage:[[iconImage withTintColor:color] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
155
+        barButtonItem.tintColor = color;
156
+    }
157
+    
158
+    [barButtonItem setTitleTextAttributes:textAttributes forState:UIControlStateNormal];
159
+    [barButtonItem setTitleTextAttributes:textAttributes forState:UIControlStateHighlighted];
160
+    [barButtonItem setTitleTextAttributes:disabledTextAttributes forState:UIControlStateDisabled];
161
+    
162
+    NSString *testID = dictionary[@"testID"];
163
+    if (testID)
164
+    {
165
+        barButtonItem.accessibilityIdentifier = testID;
166
+    }
167
+    
168
+    return barButtonItem;
155 169
 }
156 170
 
157 171
 - (UIColor *)color:(UIColor *)color defaultColor:(UIColor *)defaultColor {
158
-	if (color) {
159
-		return color;
160
-	} else if (defaultColor) {
161
-		return defaultColor;
162
-	}
163
-	
164
-	return nil;
172
+    if (color) {
173
+        return color;
174
+    } else if (defaultColor) {
175
+        return defaultColor;
176
+    }
177
+    
178
+    return nil;
165 179
 }
166 180
 
167 181
 - (id)getValue:(id)value withDefault:(id)defaultValue {
168
-	return value ? value : defaultValue;
182
+    return value ? value : defaultValue;
169 183
 }
170 184
 
171 185
 - (UIEdgeInsets)leftButtonInsets:(RNNInsetsOptions *)defaultInsets {
172
-	return UIEdgeInsetsMake([defaultInsets.top getWithDefaultValue:0],
173
-					 [defaultInsets.left getWithDefaultValue:0],
174
-					 [defaultInsets.bottom getWithDefaultValue:0],
175
-					 [defaultInsets.right getWithDefaultValue:15]);
186
+    return UIEdgeInsetsMake([defaultInsets.top getWithDefaultValue:0],
187
+                            [defaultInsets.left getWithDefaultValue:0],
188
+                            [defaultInsets.bottom getWithDefaultValue:0],
189
+                            [defaultInsets.right getWithDefaultValue:15]);
176 190
 }
177 191
 
178 192
 - (UIEdgeInsets)rightButtonInsets:(RNNInsetsOptions *)defaultInsets {
179
-	return UIEdgeInsetsMake([defaultInsets.top getWithDefaultValue:0],
180
-					 [defaultInsets.left getWithDefaultValue:15],
181
-					 [defaultInsets.bottom getWithDefaultValue:0],
182
-					 [defaultInsets.right getWithDefaultValue:0]);
193
+    return UIEdgeInsetsMake([defaultInsets.top getWithDefaultValue:0],
194
+                            [defaultInsets.left getWithDefaultValue:15],
195
+                            [defaultInsets.bottom getWithDefaultValue:0],
196
+                            [defaultInsets.right getWithDefaultValue:0]);
183 197
 }
184 198
 
185 199
 @end

+ 7
- 7
lib/ios/RNNReactComponentRegistry.m Visa fil

@@ -17,12 +17,12 @@
17 17
 }
18 18
 
19 19
 - (RNNReactView *)createComponentIfNotExists:(RNNComponentOptions *)component parentComponentId:(NSString *)parentComponentId reactViewReadyBlock:(RNNReactViewReadyCompletionBlock)reactViewReadyBlock {
20
-	NSMutableDictionary* parentComponentDict = [self componentsForParentId:parentComponentId];
20
+	NSMapTable* parentComponentDict = [self componentsForParentId:parentComponentId];
21 21
 	
22
-	RNNReactView* reactView = parentComponentDict[component.componentId.get];
22
+	RNNReactView* reactView = [parentComponentDict objectForKey:component.componentId.get];
23 23
 	if (!reactView) {
24 24
 		reactView = (RNNReactView *)[_creator createRootViewFromComponentOptions:component reactViewReadyBlock:reactViewReadyBlock];
25
-		parentComponentDict[component.componentId.get] = reactView;
25
+        [parentComponentDict setObject:reactView forKey:component.componentId.get];
26 26
 	} else if (reactViewReadyBlock) {
27 27
 		reactViewReadyBlock();
28 28
 	}
@@ -30,9 +30,9 @@
30 30
 	return reactView;
31 31
 }
32 32
 
33
-- (NSMutableDictionary *)componentsForParentId:(NSString *)parentComponentId {
33
+- (NSMapTable *)componentsForParentId:(NSString *)parentComponentId {
34 34
 	if (![_componentStore objectForKey:parentComponentId]) {
35
-		[_componentStore setObject:[NSMutableDictionary new] forKey:parentComponentId];;
35
+		[_componentStore setObject:[NSMapTable weakToStrongObjectsMapTable] forKey:parentComponentId];;
36 36
 	}
37 37
 	
38 38
 	return [_componentStore objectForKey:parentComponentId];;
@@ -49,10 +49,10 @@
49 49
 }
50 50
 
51 51
 - (void)removeChildComponent:(NSString *)childId {
52
-	NSMutableDictionary* parent;
52
+	NSMapTable* parent;
53 53
 	NSEnumerator *enumerator = _componentStore.objectEnumerator;
54 54
 	while ((parent = enumerator.nextObject)) {
55
-		if (parent[childId]) {
55
+		if ([parent objectForKey:childId]) {
56 56
 			[parent removeObjectForKey:childId];
57 57
 			return;
58 58
 		}

+ 1
- 1
lib/ios/RNNUIBarButtonItem.h Visa fil

@@ -9,7 +9,7 @@
9 9
 
10 10
 -(instancetype)init:(NSString*)buttonId withIcon:(UIImage*)iconImage;
11 11
 -(instancetype)init:(NSString*)buttonId withTitle:(NSString*)title;
12
--(instancetype)init:(NSString*)buttonId withCustomView:(RCTRootView *)reactView componentRegistry:(RNNReactComponentRegistry *)componentRegistry;
12
+-(instancetype)init:(NSString*)buttonId withCustomView:(RCTRootView *)reactView;
13 13
 -(instancetype)init:(NSString*)buttonId withSystemItem:(NSString*)systemItemName;
14 14
 
15 15
 @end

+ 5
- 15
lib/ios/RNNUIBarButtonItem.m Visa fil

@@ -7,7 +7,6 @@
7 7
 
8 8
 @property (nonatomic, strong) NSLayoutConstraint *widthConstraint;
9 9
 @property (nonatomic, strong) NSLayoutConstraint *heightConstraint;
10
-@property (nonatomic, weak) RNNReactComponentRegistry *componentRegistry;
11 10
 
12 11
 @end
13 12
 
@@ -29,29 +28,28 @@
29 28
 	return self;
30 29
 }
31 30
 
32
--(instancetype)init:(NSString*)buttonId withCustomView:(RCTRootView *)reactView componentRegistry:(RNNReactComponentRegistry *)componentRegistry {
31
+-(instancetype)init:(NSString*)buttonId withCustomView:(RCTRootView *)reactView {
33 32
 	self = [super initWithCustomView:reactView];
34 33
 	
35
-	self.componentRegistry = componentRegistry;
36 34
 	reactView.sizeFlexibility = RCTRootViewSizeFlexibilityWidthAndHeight;
37 35
 	reactView.delegate = self;
38 36
 	reactView.backgroundColor = [UIColor clearColor];
39
-	reactView.hidden = YES;
40
-	
37
+    
38
+	[NSLayoutConstraint deactivateConstraints:reactView.constraints];
41 39
 	self.widthConstraint = [NSLayoutConstraint constraintWithItem:reactView
42 40
 														attribute:NSLayoutAttributeWidth
43 41
 														relatedBy:NSLayoutRelationEqual
44 42
 														   toItem:nil
45 43
 														attribute:NSLayoutAttributeNotAnAttribute
46 44
 													   multiplier:1.0
47
-														 constant:1.0];
45
+														 constant:reactView.intrinsicContentSize.width];
48 46
 	self.heightConstraint = [NSLayoutConstraint constraintWithItem:reactView
49 47
 														 attribute:NSLayoutAttributeHeight
50 48
 														 relatedBy:NSLayoutRelationEqual
51 49
 														   	toItem:nil
52 50
 														 attribute:NSLayoutAttributeNotAnAttribute
53 51
 													   	multiplier:1.0
54
-														  constant:1.0];
52
+														  constant:reactView.intrinsicContentSize.height];
55 53
 	[NSLayoutConstraint activateConstraints:@[self.widthConstraint, self.heightConstraint]];
56 54
 	self.buttonId = buttonId;
57 55
 	return self;
@@ -65,7 +63,6 @@
65 63
 }
66 64
 
67 65
 - (void)rootViewDidChangeIntrinsicSize:(RCTRootView *)rootView {
68
-	rootView.hidden = NO;
69 66
 	self.widthConstraint.constant = rootView.intrinsicContentSize.width;
70 67
 	self.heightConstraint.constant = rootView.intrinsicContentSize.height;
71 68
 	[rootView setNeedsUpdateConstraints];
@@ -78,11 +75,4 @@
78 75
 					  afterDelay:0];
79 76
 }
80 77
 
81
-- (void)dealloc {
82
-	if ([self.customView isKindOfClass:[RNNReactView class]]) {
83
-		RNNReactView* customView = self.customView;
84
-		[self.componentRegistry removeChildComponent:customView.componentId];
85
-	}
86
-}
87
-
88 78
 @end

+ 8
- 0
lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj Visa fil

@@ -224,6 +224,8 @@
224 224
 		50CE8503217C6C9B00084EBF /* RNNSideMenuPresenterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 50CE8502217C6C9B00084EBF /* RNNSideMenuPresenterTest.m */; };
225 225
 		50D031342005149000386B3D /* RNNOverlayManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 50D031322005149000386B3D /* RNNOverlayManager.h */; };
226 226
 		50D031352005149000386B3D /* RNNOverlayManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 50D031332005149000386B3D /* RNNOverlayManager.m */; };
227
+		50DE2E45238EA14E005CD5F4 /* NSArray+utils.h in Headers */ = {isa = PBXBuildFile; fileRef = 50DE2E43238EA14E005CD5F4 /* NSArray+utils.h */; };
228
+		50DE2E46238EA14E005CD5F4 /* NSArray+utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 50DE2E44238EA14E005CD5F4 /* NSArray+utils.m */; };
227 229
 		50E02BD821A6EE0F00A43942 /* SideMenuOpenMode.h in Headers */ = {isa = PBXBuildFile; fileRef = 50E02BD621A6EE0F00A43942 /* SideMenuOpenMode.h */; };
228 230
 		50E02BD921A6EE0F00A43942 /* SideMenuOpenMode.m in Sources */ = {isa = PBXBuildFile; fileRef = 50E02BD721A6EE0F00A43942 /* SideMenuOpenMode.m */; };
229 231
 		50E02BDC21A6EE7900A43942 /* SideMenuOpenGestureModeParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 50E02BDA21A6EE7900A43942 /* SideMenuOpenGestureModeParser.m */; };
@@ -575,6 +577,8 @@
575 577
 		50D031322005149000386B3D /* RNNOverlayManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNOverlayManager.h; sourceTree = "<group>"; };
576 578
 		50D031332005149000386B3D /* RNNOverlayManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNOverlayManager.m; sourceTree = "<group>"; };
577 579
 		50DA74CF232F80FE004A00C1 /* RCTConvert+UIFontWeight.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RCTConvert+UIFontWeight.h"; sourceTree = "<group>"; };
580
+		50DE2E43238EA14E005CD5F4 /* NSArray+utils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSArray+utils.h"; sourceTree = "<group>"; };
581
+		50DE2E44238EA14E005CD5F4 /* NSArray+utils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSArray+utils.m"; sourceTree = "<group>"; };
578 582
 		50E02BD521A6E54B00A43942 /* RCTConvert+SideMenuOpenGestureMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RCTConvert+SideMenuOpenGestureMode.h"; sourceTree = "<group>"; };
579 583
 		50E02BD621A6EE0F00A43942 /* SideMenuOpenMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SideMenuOpenMode.h; sourceTree = "<group>"; };
580 584
 		50E02BD721A6EE0F00A43942 /* SideMenuOpenMode.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SideMenuOpenMode.m; sourceTree = "<group>"; };
@@ -1179,6 +1183,8 @@
1179 1183
 				E5F6C39E22DB4D0E0093C2CE /* UIViewController+Utils.m */,
1180 1184
 				50A409C8238D444900D5FF7D /* UINavigationBar+utils.h */,
1181 1185
 				50A409C9238D444900D5FF7D /* UINavigationBar+utils.m */,
1186
+				50DE2E43238EA14E005CD5F4 /* NSArray+utils.h */,
1187
+				50DE2E44238EA14E005CD5F4 /* NSArray+utils.m */,
1182 1188
 			);
1183 1189
 			name = Utils;
1184 1190
 			sourceTree = "<group>";
@@ -1307,6 +1313,7 @@
1307 1313
 				50644A2020E11A720026709C /* Constants.h in Headers */,
1308 1314
 				E5F6C3AF22DB4D0F0093C2CE /* UIView+Utils.h in Headers */,
1309 1315
 				5012241E217366D4000F5F98 /* ColorParser.h in Headers */,
1316
+				50DE2E45238EA14E005CD5F4 /* NSArray+utils.h in Headers */,
1310 1317
 				E8367B801F7A8A4700675C05 /* VICMAImageView.h in Headers */,
1311 1318
 				263905E61E4CAC950023D7D3 /* RNNSideMenuChildVC.h in Headers */,
1312 1319
 				50F5DFC51F407AA0001A00BC /* RNNStackController.h in Headers */,
@@ -1527,6 +1534,7 @@
1527 1534
 				50E5F78E223F9FAF002AFEAD /* RNNElementTransitionOptions.m in Sources */,
1528 1535
 				7365071221E4B16F004E020F /* RCTConvert+UIBarButtonSystemItem.m in Sources */,
1529 1536
 				5012241B21736678000F5F98 /* Image.m in Sources */,
1537
+				50DE2E46238EA14E005CD5F4 /* NSArray+utils.m in Sources */,
1530 1538
 				50495943216F5E5D006D2B81 /* NullBool.m in Sources */,
1531 1539
 				5038A3C7216E2D93009280BC /* Number.m in Sources */,
1532 1540
 				E5F6C3A622DB4D0F0093C2CE /* UIViewController+Utils.m in Sources */,