Browse Source

v2-customButtons (#2637)

* v2-customButtons

* Update RNNRootViewController.m
yogevbd 6 years ago
parent
commit
e402a326a9
No account linked to committer's email address

+ 5
- 1
lib/ios/RNNNavigationButtons.m View File

54
 -(RNNUIBarButtonItem*)buildButton: (NSDictionary*)dictionary {
54
 -(RNNUIBarButtonItem*)buildButton: (NSDictionary*)dictionary {
55
 	NSString* buttonId = dictionary[@"id"];
55
 	NSString* buttonId = dictionary[@"id"];
56
 	NSString* title = dictionary[@"title"];
56
 	NSString* title = dictionary[@"title"];
57
+	NSString* component = dictionary[@"component"];
57
 	
58
 	
58
 	if (!buttonId) {
59
 	if (!buttonId) {
59
 		@throw [NSException exceptionWithName:@"NSInvalidArgumentException" reason:[@"button id is not specified " stringByAppendingString:title] userInfo:nil];
60
 		@throw [NSException exceptionWithName:@"NSInvalidArgumentException" reason:[@"button id is not specified " stringByAppendingString:title] userInfo:nil];
66
 	}
67
 	}
67
 	
68
 	
68
 	RNNUIBarButtonItem *barButtonItem;
69
 	RNNUIBarButtonItem *barButtonItem;
69
-	if (iconImage) {
70
+	if (component) {
71
+		RCTRootView *view = (RCTRootView*)[self.viewController.creator createRootView:component rootViewId:buttonId];
72
+		barButtonItem = [[RNNUIBarButtonItem alloc] init:buttonId withCustomView:view];
73
+	} else if (iconImage) {
70
 		barButtonItem = [[RNNUIBarButtonItem alloc] init:buttonId withIcon:iconImage];
74
 		barButtonItem = [[RNNUIBarButtonItem alloc] init:buttonId withIcon:iconImage];
71
 	} else if (title) {
75
 	} else if (title) {
72
 		barButtonItem = [[RNNUIBarButtonItem alloc] init:buttonId withTitle:title];
76
 		barButtonItem = [[RNNUIBarButtonItem alloc] init:buttonId withTitle:title];

+ 1
- 0
lib/ios/RNNRootViewController.h View File

15
 @property (nonatomic, strong) RNNEventEmitter *eventEmitter;
15
 @property (nonatomic, strong) RNNEventEmitter *eventEmitter;
16
 @property (nonatomic, strong) NSString* componentId;
16
 @property (nonatomic, strong) NSString* componentId;
17
 @property (nonatomic, strong) RNNTopTabsViewController* topTabsViewController;
17
 @property (nonatomic, strong) RNNTopTabsViewController* topTabsViewController;
18
+@property (nonatomic) id<RNNRootViewCreator> creator;
18
 @property (nonatomic, strong) RNNAnimator* animator;
19
 @property (nonatomic, strong) RNNAnimator* animator;
19
 
20
 
20
 -(instancetype)initWithName:(NSString*)name
21
 -(instancetype)initWithName:(NSString*)name

+ 0
- 1
lib/ios/RNNRootViewController.m View File

7
 @interface RNNRootViewController()
7
 @interface RNNRootViewController()
8
 @property (nonatomic, strong) NSString* componentName;
8
 @property (nonatomic, strong) NSString* componentName;
9
 @property (nonatomic) BOOL _statusBarHidden;
9
 @property (nonatomic) BOOL _statusBarHidden;
10
-@property (nonatomic) id<RNNRootViewCreator> creator;
11
 @end
10
 @end
12
 
11
 
13
 @implementation RNNRootViewController
12
 @implementation RNNRootViewController

+ 4
- 1
lib/ios/RNNUIBarButtonItem.h View File

1
 #import <Foundation/Foundation.h>
1
 #import <Foundation/Foundation.h>
2
+#import <React/RCTRootView.h>
3
+#import <React/RCTRootViewDelegate.h>
2
 
4
 
3
-@interface RNNUIBarButtonItem : UIBarButtonItem
5
+@interface RNNUIBarButtonItem : UIBarButtonItem <RCTRootViewDelegate>
4
 
6
 
5
 @property (nonatomic, strong) NSString* buttonId;
7
 @property (nonatomic, strong) NSString* buttonId;
6
 
8
 
7
 -(instancetype)init:(NSString*)buttonId withIcon:(UIImage*)iconImage;
9
 -(instancetype)init:(NSString*)buttonId withIcon:(UIImage*)iconImage;
8
 -(instancetype)init:(NSString*)buttonId withTitle:(NSString*)title;
10
 -(instancetype)init:(NSString*)buttonId withTitle:(NSString*)title;
11
+-(instancetype)init:(NSString*)buttonId withCustomView:(RCTRootView*)reactView;
9
 
12
 
10
 @end
13
 @end
11
 
14
 

+ 16
- 0
lib/ios/RNNUIBarButtonItem.m View File

16
 	return self;
16
 	return self;
17
 }
17
 }
18
 
18
 
19
+-(instancetype)init:(NSString*)buttonId withCustomView:(RCTRootView *)reactView {
20
+	self = [super initWithCustomView:reactView];
21
+	
22
+	reactView.sizeFlexibility = RCTRootViewSizeFlexibilityWidthAndHeight;
23
+	reactView.delegate = self;
24
+	reactView.backgroundColor = [UIColor clearColor];
25
+	self.buttonId = buttonId;
26
+	return self;
27
+}
28
+
29
+- (void)rootViewDidChangeIntrinsicSize:(RCTRootView *)rootView {
30
+	CGSize size = rootView.intrinsicContentSize;
31
+	rootView.frame = CGRectMake(0, 0, size.width, size.height);
32
+	self.width = size.width;
33
+}
34
+
19
 @end
35
 @end