Browse Source

handle buttonPressed event in rootViewController

yogevbd 6 years ago
parent
commit
26616fc4cc
3 changed files with 13 additions and 10 deletions
  1. 1
    5
      lib/ios/RNNNavigationButtons.m
  2. 8
    5
      lib/ios/RNNRootViewController.h
  3. 4
    0
      lib/ios/RNNRootViewController.m

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

@@ -93,7 +93,7 @@
93 93
 		return nil;
94 94
 	}
95 95
 	
96
-	barButtonItem.target = self;
96
+	barButtonItem.target = self.viewController;
97 97
 	barButtonItem.action = @selector(onButtonPress:);
98 98
 	
99 99
 	NSNumber *enabled = [self getValue:dictionary[@"enabled"] withDefault:defaultStyle.enabled];
@@ -171,8 +171,4 @@
171 171
 	return value ? value : defaultValue;
172 172
 }
173 173
 
174
--(void)onButtonPress:(RNNUIBarButtonItem*)barButtonItem {
175
-	[self.viewController.eventEmitter sendOnNavigationButtonPressed:self.viewController.componentId buttonId:barButtonItem.buttonId];
176
-}
177
-
178 174
 @end

+ 8
- 5
lib/ios/RNNRootViewController.h View File

@@ -5,6 +5,7 @@
5 5
 #import "RNNEventEmitter.h"
6 6
 #import "RNNNavigationOptions.h"
7 7
 #import "RNNAnimator.h"
8
+#import "RNNUIBarButtonItem.h"
8 9
 
9 10
 typedef void (^RNNReactViewReadyCompletionBlock)(void);
10 11
 
@@ -19,11 +20,11 @@ typedef void (^RNNReactViewReadyCompletionBlock)(void);
19 20
 
20 21
 
21 22
 - (instancetype)initWithName:(NSString*)name
22
-				withOptions:(RNNNavigationOptions*)options
23
-			withComponentId:(NSString*)componentId
24
-			rootViewCreator:(id<RNNRootViewCreator>)creator
25
-			   eventEmitter:(RNNEventEmitter*)eventEmitter
26
-		  isExternalComponent:(BOOL)isExternalComponent;
23
+				 withOptions:(RNNNavigationOptions*)options
24
+			 withComponentId:(NSString*)componentId
25
+			 rootViewCreator:(id<RNNRootViewCreator>)creator
26
+				eventEmitter:(RNNEventEmitter*)eventEmitter
27
+		 isExternalComponent:(BOOL)isExternalComponent;
27 28
 
28 29
 - (void)applyTopTabsOptions;
29 30
 - (BOOL)isCustomViewController;
@@ -33,4 +34,6 @@ typedef void (^RNNReactViewReadyCompletionBlock)(void);
33 34
 - (void)applyModalOptions;
34 35
 - (void)optionsUpdated;
35 36
 
37
+-(void)onButtonPress:(RNNUIBarButtonItem *)barButtonItem;
38
+
36 39
 @end

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

@@ -361,6 +361,10 @@
361 361
 	return actions;
362 362
 }
363 363
 
364
+-(void)onButtonPress:(RNNUIBarButtonItem *)barButtonItem {
365
+	[self.eventEmitter sendOnNavigationButtonPressed:self.componentId buttonId:barButtonItem.buttonId];
366
+}
367
+
364 368
 /**
365 369
  *	fix for #877, #878
366 370
  */