Bläddra i källkod

v2-customButtons (#2637)

* v2-customButtons

* Update RNNRootViewController.m
yogevbd 6 år sedan
förälder
incheckning
e402a326a9
No account linked to committer's email address

+ 5
- 1
lib/ios/RNNNavigationButtons.m Visa fil

@@ -54,6 +54,7 @@
54 54
 -(RNNUIBarButtonItem*)buildButton: (NSDictionary*)dictionary {
55 55
 	NSString* buttonId = dictionary[@"id"];
56 56
 	NSString* title = dictionary[@"title"];
57
+	NSString* component = dictionary[@"component"];
57 58
 	
58 59
 	if (!buttonId) {
59 60
 		@throw [NSException exceptionWithName:@"NSInvalidArgumentException" reason:[@"button id is not specified " stringByAppendingString:title] userInfo:nil];
@@ -66,7 +67,10 @@
66 67
 	}
67 68
 	
68 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 74
 		barButtonItem = [[RNNUIBarButtonItem alloc] init:buttonId withIcon:iconImage];
71 75
 	} else if (title) {
72 76
 		barButtonItem = [[RNNUIBarButtonItem alloc] init:buttonId withTitle:title];

+ 1
- 0
lib/ios/RNNRootViewController.h Visa fil

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

+ 0
- 1
lib/ios/RNNRootViewController.m Visa fil

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

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

@@ -1,11 +1,14 @@
1 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 7
 @property (nonatomic, strong) NSString* buttonId;
6 8
 
7 9
 -(instancetype)init:(NSString*)buttonId withIcon:(UIImage*)iconImage;
8 10
 -(instancetype)init:(NSString*)buttonId withTitle:(NSString*)title;
11
+-(instancetype)init:(NSString*)buttonId withCustomView:(RCTRootView*)reactView;
9 12
 
10 13
 @end
11 14
 

+ 16
- 0
lib/ios/RNNUIBarButtonItem.m Visa fil

@@ -16,4 +16,20 @@
16 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 35
 @end