Преглед на файлове

Fix merging buttons second time doesn't work (#4243)

Yogev Ben David преди 6 години
родител
ревизия
ff02494259
No account linked to committer's email address

+ 3
- 0
lib/ios/RNNLeafProtocol.h Целия файл

@@ -1,3 +1,4 @@
1
+#import "RNNRootViewCreator.h"
1 2
 
2 3
 typedef void (^RNNReactViewReadyCompletionBlock)(void);
3 4
 
@@ -9,4 +10,6 @@ typedef void (^RNNReactViewReadyCompletionBlock)(void);
9 10
 
10 11
 - (BOOL)isCustomTransitioned;
11 12
 
13
+- (id<RNNRootViewCreator>)creator;
14
+
12 15
 @end

+ 2
- 2
lib/ios/RNNNavigationButtons.h Целия файл

@@ -1,11 +1,11 @@
1 1
 #import <Foundation/Foundation.h>
2 2
 #import <UIKit/UIKit.h>
3
-#import "RNNRootViewController.h"
4 3
 #import "RNNButtonOptions.h"
4
+#import "RNNRootViewCreator.h"
5 5
 
6 6
 @interface RNNNavigationButtons : NSObject
7 7
 
8
--(instancetype)initWithViewController:(RNNRootViewController*)viewController;
8
+-(instancetype)initWithViewController:(UIViewController*)viewController rootViewCreator:(id<RNNRootViewCreator>)creator;
9 9
 
10 10
 -(void)applyLeftButtons:(NSArray*)leftButtons rightButtons:(NSArray*)rightButtons defaultLeftButtonStyle:(RNNButtonOptions *)defaultLeftButtonStyle defaultRightButtonStyle:(RNNButtonOptions *)defaultRightButtonStyle;
11 11
 

+ 6
- 4
lib/ios/RNNNavigationButtons.m Целия файл

@@ -3,21 +3,23 @@
3 3
 #import <React/RCTConvert.h>
4 4
 #import "RCTHelpers.h"
5 5
 #import "UIImage+tint.h"
6
+#import "RNNRootViewController.h"
6 7
 
7 8
 @interface RNNNavigationButtons()
8 9
 
9
-@property (weak, nonatomic) RNNRootViewController* viewController;
10
+@property (weak, nonatomic) UIViewController* viewController;
10 11
 @property (strong, nonatomic) RNNButtonOptions* defaultLeftButtonStyle;
11 12
 @property (strong, nonatomic) RNNButtonOptions* defaultRightButtonStyle;
12
-
13
+@property (nonatomic) id<RNNRootViewCreator> creator;
13 14
 @end
14 15
 
15 16
 @implementation RNNNavigationButtons
16 17
 
17
--(instancetype)initWithViewController:(RNNRootViewController*)viewController {
18
+-(instancetype)initWithViewController:(UIViewController*)viewController rootViewCreator:(id<RNNRootViewCreator>)creator {
18 19
 	self = [super init];
19 20
 	
20 21
 	self.viewController = viewController;
22
+	self.creator = creator;
21 23
 	
22 24
 	return self;
23 25
 }
@@ -78,7 +80,7 @@
78 80
 	
79 81
 	RNNUIBarButtonItem *barButtonItem;
80 82
 	if (component) {
81
-		RCTRootView *view = (RCTRootView*)[self.viewController.creator createCustomReactView:component[@"name"] rootViewId:component[@"componentId"]];
83
+		RCTRootView *view = (RCTRootView*)[self.creator createCustomReactView:component[@"name"] rootViewId:component[@"componentId"]];
82 84
 		barButtonItem = [[RNNUIBarButtonItem alloc] init:buttonId withCustomView:view];
83 85
 	} else if (iconImage) {
84 86
 		barButtonItem = [[RNNUIBarButtonItem alloc] init:buttonId withIcon:iconImage];

+ 1
- 1
lib/ios/RNNRootViewController.m Целия файл

@@ -37,7 +37,7 @@
37 37
 	
38 38
 	self.eventEmitter = eventEmitter;
39 39
 	self.presenter = presenter;
40
-	[self.presenter bindViewController:self];
40
+	[self.presenter bindViewController:self viewCreator:self.creator];
41 41
 	self.options = options;
42 42
 	self.defaultOptions = defaultOptions;
43 43
 	

+ 0
- 57
lib/ios/RNNTopBarOptions.m Целия файл

@@ -61,62 +61,5 @@
61 61
 	return self;
62 62
 }
63 63
 
64
-- (void)applyOn:(UIViewController*)viewController {
65
-	if (self.rightButtons || self.leftButtons) {
66
-		_navigationButtons = [[RNNNavigationButtons alloc] initWithViewController:(RNNRootViewController*)viewController];
67
-		[_navigationButtons applyLeftButtons:self.leftButtons rightButtons:self.rightButtons defaultLeftButtonStyle:self.leftButtonStyle defaultRightButtonStyle:self.rightButtonStyle];
68
-	}
69
-	
70
-	self.rightButtons = nil;
71
-	self.leftButtons = nil;
72
-}
73
-
74
-//- (void)setRightButtonColor:(NSNumber *)rightButtonColor {
75
-//	_rightButtonColor = rightButtonColor;
76
-//	_rightButtonStyle.color = rightButtonColor;
77
-//}
78
-//
79
-//- (void)setRightButtonDisabledColor:(NSNumber *)rightButtonDisabledColor {
80
-//	_rightButtonDisabledColor = rightButtonDisabledColor;
81
-//	_rightButtonStyle.disabledColor = rightButtonDisabledColor;
82
-//}
83
-//
84
-//- (void)setLeftButtonColor:(NSNumber *)leftButtonColor {
85
-//	_leftButtonColor = leftButtonColor;
86
-//	_leftButtonStyle.color = leftButtonColor;
87
-//}
88
-//
89
-//- (void)setLeftButtonDisabledColor:(NSNumber *)leftButtonDisabledColor {
90
-//	_leftButtonDisabledColor = leftButtonDisabledColor;
91
-//	_leftButtonStyle.disabledColor = leftButtonDisabledColor;
92
-//}
93
-
94
-//- (void)setRightButtons:(id)rightButtons {
95
-//	if ([rightButtons isKindOfClass:[NSArray class]]) {
96
-//		_rightButtons = rightButtons;
97
-//	} else if ([rightButtons isKindOfClass:[NSDictionary class]]) {
98
-//		if (rightButtons[@"id"]) {
99
-//			_rightButtons = @[rightButtons];
100
-//		} else {
101
-//			[_rightButtonStyle mergeWith:rightButtons];
102
-//		}
103
-//	} else {
104
-//		_rightButtons = rightButtons;
105
-//	}
106
-//}
107
-//
108
-//- (void)setLeftButtons:(id)leftButtons {
109
-//	if ([leftButtons isKindOfClass:[NSArray class]]) {
110
-//		_leftButtons = leftButtons;
111
-//	} else if ([leftButtons isKindOfClass:[NSDictionary class]]) {
112
-//		if (leftButtons[@"id"]) {
113
-//			_leftButtons = @[leftButtons];
114
-//		} else {
115
-//			[_leftButtonStyle mergeWith:leftButtons];
116
-//		}
117
-//	} else {
118
-//		_leftButtons = leftButtons;
119
-//	}
120
-//}
121 64
 
122 65
 @end

+ 5
- 0
lib/ios/RNNViewControllerPresenter.h Целия файл

@@ -1,5 +1,10 @@
1 1
 #import "RNNBasePresenter.h"
2
+#import "RNNNavigationButtons.h"
2 3
 
3 4
 @interface RNNViewControllerPresenter : RNNBasePresenter
4 5
 
6
+@property (nonatomic, strong) RNNNavigationButtons* navigationButtons;
7
+
8
+- (void)bindViewController:(UIViewController *)bindedViewController viewCreator:(id<RNNRootViewCreator>)creator;
9
+
5 10
 @end

+ 5
- 8
lib/ios/RNNViewControllerPresenter.m Целия файл

@@ -1,16 +1,15 @@
1 1
 #import "RNNViewControllerPresenter.h"
2 2
 #import "UIViewController+RNNOptions.h"
3 3
 #import "UITabBarController+RNNOptions.h"
4
-#import "RNNNavigationButtons.h"
5 4
 #import "RCTConvert+Modal.h"
6 5
 #import "RNNReactView.h"
7 6
 
8
-@interface RNNViewControllerPresenter()
9
-@property (nonatomic, strong) RNNNavigationButtons* navigationButtons;
10
-@end
11
-
12 7
 @implementation RNNViewControllerPresenter
13 8
 
9
+- (void)bindViewController:(UIViewController *)bindedViewController viewCreator:(id<RNNRootViewCreator>)creator {
10
+	self.bindedViewController = bindedViewController;
11
+	_navigationButtons = [[RNNNavigationButtons alloc] initWithViewController:self.bindedViewController rootViewCreator:creator];
12
+}
14 13
 
15 14
 - (void)applyOptions:(RNNNavigationOptions *)options {
16 15
 	[super applyOptions:options];
@@ -33,8 +32,7 @@
33 32
 		[viewController rnn_setSearchBarWithPlaceholder:[options.topBar.searchBarPlaceholder getWithDefaultValue:@""]];
34 33
 	}
35 34
 	
36
-	if ((options.topBar.leftButtons || options.topBar.rightButtons) && !_navigationButtons) {
37
-		_navigationButtons = [[RNNNavigationButtons alloc] initWithViewController:(RNNRootViewController*)viewController];
35
+	if ((options.topBar.leftButtons || options.topBar.rightButtons)) {
38 36
 		[_navigationButtons applyLeftButtons:options.topBar.leftButtons rightButtons:options.topBar.rightButtons defaultLeftButtonStyle:options.topBar.leftButtonStyle defaultRightButtonStyle:options.topBar.rightButtonStyle];
39 37
 	}
40 38
 }
@@ -112,7 +110,6 @@
112 110
 	
113 111
 	if (newOptions.topBar.leftButtons || newOptions.topBar.rightButtons) {
114 112
 		RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
115
-		_navigationButtons = [[RNNNavigationButtons alloc] initWithViewController:(RNNRootViewController*)viewController];
116 113
 		[_navigationButtons applyLeftButtons:newOptions.topBar.leftButtons rightButtons:newOptions.topBar.rightButtons defaultLeftButtonStyle:buttonsResolvedOptions.topBar.leftButtonStyle defaultRightButtonStyle:buttonsResolvedOptions.topBar.rightButtonStyle];
117 114
 	}
118 115
 	

+ 9
- 1
lib/ios/ReactNativeNavigationTests/RNNViewControllerPresenterTest.m Целия файл

@@ -3,6 +3,7 @@
3 3
 #import "RNNViewControllerPresenter.h"
4 4
 #import "UIViewController+RNNOptions.h"
5 5
 #import "RNNReactView.h"
6
+#import "RNNRootViewController.h"
6 7
 
7 8
 @interface RNNViewControllerPresenterTest : XCTestCase
8 9
 
@@ -17,7 +18,7 @@
17 18
 - (void)setUp {
18 19
     [super setUp];
19 20
 	self.uut = [[RNNViewControllerPresenter alloc] init];
20
-	self.bindedViewController = [OCMockObject partialMockForObject:[UIViewController new]];
21
+	self.bindedViewController = [OCMockObject partialMockForObject:[RNNRootViewController new]];
21 22
 	[self.uut bindViewController:self.bindedViewController];
22 23
 	self.options = [[RNNNavigationOptions alloc] initEmptyOptions];
23 24
 }
@@ -67,6 +68,12 @@
67 68
     [(id)self.bindedViewController verify];
68 69
 }
69 70
 
71
+- (void)testBindViewControllerShouldCreateNavigationButtonsCreator {
72
+	RNNViewControllerPresenter* presenter = [[RNNViewControllerPresenter alloc] init];
73
+	[presenter bindViewController:self.bindedViewController viewCreator:nil];
74
+	XCTAssertNotNil(presenter.navigationButtons);
75
+}
76
+
70 77
 - (void)testApplyOptionsOnInit_shouldSetModalPresentetionStyleWithDefault {
71 78
 	[[(id)self.bindedViewController expect] rnn_setModalPresentationStyle:UIModalPresentationFullScreen];
72 79
 	[self.uut applyOptionsOnInit:self.options];
@@ -125,4 +132,5 @@
125 132
     [(id)self.bindedViewController verify];
126 133
 }
127 134
 
135
+
128 136
 @end