Browse Source

Send screen popped event only for rnn components (#6221)

* Send popped event only for rnn components

* Add native viewcontroller push and pop e2e
Yogev Ben David 4 years ago
parent
commit
0b7507d75f
No account linked to committer's email address

+ 7
- 0
e2e/ExternalComponent.test.js View File

@@ -46,4 +46,11 @@ describe('External Component', () => {
46 46
     await elementById(TestIDs.MODAL_BTN).tap();
47 47
     await expect(elementByLabel('External Component')).toBeVisible();
48 48
   });
49
+
50
+  test(':ios: Push and pop native component', async () => {
51
+    await elementById(TestIDs.PUSH_BTN).tap();
52
+    await elementById(TestIDs.PUSH_NATIVE_BTN).tap();
53
+    await elementById(TestIDs.POP_NATIVE_BTN).tap();
54
+    await expect(elementByLabel('This is an external component')).toBeVisible();
55
+  });
49 56
 });

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

@@ -80,6 +80,10 @@
80 80
 									isFocused:searchController.searchBar.isFirstResponder];
81 81
 }
82 82
 
83
+- (void)screenPopped {
84
+    [_eventEmitter sendScreenPoppedEvent:self.layoutInfo.componentId];
85
+}
86
+
83 87
 - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
84 88
 	[self.eventEmitter sendOnSearchBarCancelPressed:self.layoutInfo.componentId];
85 89
 }

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

@@ -15,16 +15,12 @@
15 15
 
16 16
 - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
17 17
     if (_presentedViewController && ![navigationController.viewControllers containsObject:_presentedViewController]) {
18
-        [self sendScreenPoppedEvent:_presentedViewController];
18
+        [_presentedViewController screenPopped];
19 19
     }
20 20
     
21 21
     _presentedViewController = viewController;
22 22
 }
23 23
 
24
-- (void)sendScreenPoppedEvent:(UIViewController *)poppedScreen {
25
-    [_eventEmitter sendScreenPoppedEvent:poppedScreen.layoutInfo.componentId];
26
-}
27
-
28 24
 - (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
29 25
 								  animationControllerForOperation:(UINavigationControllerOperation)operation
30 26
 											   fromViewController:(UIViewController*)fromVC

+ 2
- 0
lib/ios/UIViewController+LayoutProtocol.h View File

@@ -40,6 +40,8 @@ typedef void (^RNNReactViewReadyCompletionBlock)(void);
40 40
 
41 41
 - (void)componentDidDisappear;
42 42
 
43
+- (void)screenPopped;
44
+
43 45
 @property (nonatomic, retain) RNNBasePresenter* presenter;
44 46
 @property (nonatomic, retain) RNNLayoutInfo* layoutInfo;
45 47
 @property (nonatomic, strong) RNNNavigationOptions* options;

+ 4
- 0
lib/ios/UIViewController+LayoutProtocol.m View File

@@ -147,6 +147,10 @@
147 147
     return 0;
148 148
 }
149 149
 
150
+- (void)screenPopped {
151
+    
152
+}
153
+
150 154
 - (void)onChildWillAppear {
151 155
 	[self.presenter applyOptions:self.resolveOptions];
152 156
 	[self.parentViewController onChildWillAppear];

+ 1
- 1
playground/ios/NavigationTests/RNNExternalViewControllerTests.m View File

@@ -1,7 +1,7 @@
1 1
 #import <XCTest/XCTest.h>
2 2
 #import <OCMock/OCMock.h>
3 3
 #import <ReactNativeNavigation/RNNExternalViewController.h>
4
-#import <ReactNativeNavigation/RNNCustomViewController.h>
4
+#import "RNNCustomViewController.h"
5 5
 
6 6
 @interface RNNExternalViewControllerTest : XCTestCase
7 7
 

+ 20
- 6
playground/ios/playground.xcodeproj/project.pbxproj View File

@@ -11,11 +11,16 @@
11 11
 		13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB11A68108700A75B9A /* LaunchScreen.xib */; };
12 12
 		13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
13 13
 		13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
14
+		5007B4312472CA390002AA4E /* RNNNativeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5007B4302472CA390002AA4E /* RNNNativeViewController.m */; };
15
+		5007B4342472CBD40002AA4E /* RNNCustomViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5007B4322472CBD30002AA4E /* RNNCustomViewController.m */; };
16
+		5007B4352472D3C90002AA4E /* RNNNativeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5007B4302472CA390002AA4E /* RNNNativeViewController.m */; };
17
+		5007B4362472D3CC0002AA4E /* RNNCustomViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5007B4322472CBD30002AA4E /* RNNCustomViewController.m */; };
18
+		5007B4382472D9A20002AA4E /* RNNCustomViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5007B4322472CBD30002AA4E /* RNNCustomViewController.m */; };
19
+		5007B4392472D9A70002AA4E /* RNNNativeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5007B4302472CA390002AA4E /* RNNNativeViewController.m */; };
14 20
 		500E9FE72406A52100C61231 /* BottomTabPresenterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 500E9FE62406A4E200C61231 /* BottomTabPresenterTest.m */; };
15 21
 		501C86B9239FE9C400E0B631 /* UIImage+Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 501C86B8239FE9C400E0B631 /* UIImage+Utils.m */; };
16 22
 		5022EDCD2405522000852BA6 /* RNNBottomTabsPresenterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = E58D263A2385888C003F36BA /* RNNBottomTabsPresenterTest.m */; };
17 23
 		5022EDCE2405524700852BA6 /* RNNBottomTabsAppearancePresenterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 5022EDCB240551EE00852BA6 /* RNNBottomTabsAppearancePresenterTest.m */; };
18
-		50451D35204451A900695F00 /* RNNCustomViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 50451D34204451A800695F00 /* RNNCustomViewController.m */; };
19 24
 		50647FE323E3196800B92025 /* RNNExternalViewControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 50647FE223E3196800B92025 /* RNNExternalViewControllerTests.m */; };
20 25
 		50650A23242FB0F800688104 /* CommandsHandlerCreator.m in Sources */ = {isa = PBXBuildFile; fileRef = 50650A22242FB0F800688104 /* CommandsHandlerCreator.m */; };
21 26
 		5078DF39242BE8AA007B0B4F /* TestingAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 5078DF38242BE8AA007B0B4F /* TestingAppDelegate.m */; };
@@ -99,14 +104,16 @@
99 104
 		4A3340545EAAF11C1F146864 /* Pods_playground.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_playground.framework; sourceTree = BUILT_PRODUCTS_DIR; };
100 105
 		4AE37ACF6BFBAB211EE8E7E9 /* Pods-NavigationIOS12Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NavigationIOS12Tests.release.xcconfig"; path = "Target Support Files/Pods-NavigationIOS12Tests/Pods-NavigationIOS12Tests.release.xcconfig"; sourceTree = "<group>"; };
101 106
 		4C14E49C47AA48BEDE90A218 /* Pods-SnapshotTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SnapshotTests.debug.xcconfig"; path = "Target Support Files/Pods-SnapshotTests/Pods-SnapshotTests.debug.xcconfig"; sourceTree = "<group>"; };
107
+		5007B42F2472CA390002AA4E /* RNNNativeViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNNativeViewController.h; sourceTree = "<group>"; };
108
+		5007B4302472CA390002AA4E /* RNNNativeViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNNativeViewController.m; sourceTree = "<group>"; };
109
+		5007B4322472CBD30002AA4E /* RNNCustomViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNCustomViewController.m; sourceTree = "<group>"; };
110
+		5007B4332472CBD40002AA4E /* RNNCustomViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNNCustomViewController.h; sourceTree = "<group>"; };
102 111
 		500E9FE62406A4E200C61231 /* BottomTabPresenterTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BottomTabPresenterTest.m; sourceTree = "<group>"; };
103 112
 		501C86B7239FE9C400E0B631 /* UIImage+Utils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIImage+Utils.h"; sourceTree = "<group>"; };
104 113
 		501C86B8239FE9C400E0B631 /* UIImage+Utils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIImage+Utils.m"; sourceTree = "<group>"; };
105 114
 		5022EDCB240551EE00852BA6 /* RNNBottomTabsAppearancePresenterTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNBottomTabsAppearancePresenterTest.m; sourceTree = "<group>"; };
106 115
 		50364D69238E7ECC000E62A2 /* Pods_playground.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_playground.framework; sourceTree = BUILT_PRODUCTS_DIR; };
107 116
 		50364D6B238E7F0A000E62A2 /* ReactNativeNavigation.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = ReactNativeNavigation.framework; sourceTree = BUILT_PRODUCTS_DIR; };
108
-		50451D33204451A800695F00 /* RNNCustomViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNNCustomViewController.h; path = ../../../lib/ios/RNNCustomViewController.h; sourceTree = "<group>"; };
109
-		50451D34204451A800695F00 /* RNNCustomViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNNCustomViewController.m; path = ../../../lib/ios/RNNCustomViewController.m; sourceTree = "<group>"; };
110 117
 		50647FE223E3196800B92025 /* RNNExternalViewControllerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNExternalViewControllerTests.m; sourceTree = "<group>"; };
111 118
 		50650A21242FB0F800688104 /* CommandsHandlerCreator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CommandsHandlerCreator.h; sourceTree = "<group>"; };
112 119
 		50650A22242FB0F800688104 /* CommandsHandlerCreator.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CommandsHandlerCreator.m; sourceTree = "<group>"; };
@@ -211,8 +218,10 @@
211 218
 			children = (
212 219
 				13B07FAF1A68108700A75B9A /* AppDelegate.h */,
213 220
 				13B07FB01A68108700A75B9A /* AppDelegate.m */,
214
-				50451D33204451A800695F00 /* RNNCustomViewController.h */,
215
-				50451D34204451A800695F00 /* RNNCustomViewController.m */,
221
+				5007B42F2472CA390002AA4E /* RNNNativeViewController.h */,
222
+				5007B4302472CA390002AA4E /* RNNNativeViewController.m */,
223
+				5007B4332472CBD40002AA4E /* RNNCustomViewController.h */,
224
+				5007B4322472CBD30002AA4E /* RNNCustomViewController.m */,
216 225
 				5078DF37242BE8AA007B0B4F /* TestingAppDelegate.h */,
217 226
 				5078DF38242BE8AA007B0B4F /* TestingAppDelegate.m */,
218 227
 				13B07FB51A68108700A75B9A /* Images.xcassets */,
@@ -925,8 +934,9 @@
925 934
 			isa = PBXSourcesBuildPhase;
926 935
 			buildActionMask = 2147483647;
927 936
 			files = (
928
-				50451D35204451A900695F00 /* RNNCustomViewController.m in Sources */,
937
+				5007B4312472CA390002AA4E /* RNNNativeViewController.m in Sources */,
929 938
 				5078DF39242BE8AA007B0B4F /* TestingAppDelegate.m in Sources */,
939
+				5007B4342472CBD40002AA4E /* RNNCustomViewController.m in Sources */,
930 940
 				13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */,
931 941
 				13B07FC11A68108700A75B9A /* main.m in Sources */,
932 942
 			);
@@ -936,6 +946,8 @@
936 946
 			isa = PBXSourcesBuildPhase;
937 947
 			buildActionMask = 2147483647;
938 948
 			files = (
949
+				5007B4362472D3CC0002AA4E /* RNNCustomViewController.m in Sources */,
950
+				5007B4352472D3C90002AA4E /* RNNNativeViewController.m in Sources */,
939 951
 				507C80E8242A1E6F00F765F7 /* AppDelegate.m in Sources */,
940 952
 				507C80EC242BC6FB00F765F7 /* LayoutCreator.m in Sources */,
941 953
 				507C80E7242914C800F765F7 /* StackOptionsTest.m in Sources */,
@@ -959,6 +971,8 @@
959 971
 			isa = PBXSourcesBuildPhase;
960 972
 			buildActionMask = 2147483647;
961 973
 			files = (
974
+				5007B4392472D9A70002AA4E /* RNNNativeViewController.m in Sources */,
975
+				5007B4382472D9A20002AA4E /* RNNCustomViewController.m in Sources */,
962 976
 				E58D265B2385888C003F36BA /* UIViewController+RNNOptionsTest.m in Sources */,
963 977
 				E58D26532385888C003F36BA /* RNNSideMenuPresenterTest.m in Sources */,
964 978
 				50BCB27623F1A2B100D6C8E5 /* TopBarAppearancePresenterTest.m in Sources */,

+ 1
- 1
playground/ios/playground/AppDelegate.m View File

@@ -4,7 +4,7 @@
4 4
 #import <React/RCTBundleURLProvider.h>
5 5
 
6 6
 #import <ReactNativeNavigation/ReactNativeNavigation.h>
7
-#import <ReactNativeNavigation/RNNCustomViewController.h>
7
+#import "RNNCustomViewController.h"
8 8
 
9 9
 @implementation AppDelegate
10 10
 

lib/ios/RNNCustomViewController.h → playground/ios/playground/RNNCustomViewController.h View File


lib/ios/RNNCustomViewController.m → playground/ios/playground/RNNCustomViewController.m View File

@@ -1,4 +1,5 @@
1 1
 #import "RNNCustomViewController.h"
2
+#import "RNNNativeViewController.h"
2 3
 
3 4
 @implementation RNNCustomViewController {
4 5
 	NSString* _text;
@@ -16,14 +17,11 @@
16 17
 	[self addTestLabel];
17 18
 	[self addDismissModalButton];
18 19
 	[self addNavigationBarButtons];
20
+	[self addPushButton];
19 21
 	
20 22
 	[[self view] setBackgroundColor:UIColor.whiteColor];
21 23
 }
22 24
 
23
-- (void)dismissModal {
24
-	[self dismissViewControllerAnimated:YES completion:nil];
25
-}
26
-
27 25
 - (void)addDismissModalButton {
28 26
 	UIButton* dismissModalButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.center.x - 70, 300, 140, 50)];
29 27
 	dismissModalButton.backgroundColor = UIColor.systemBlueColor;
@@ -33,6 +31,15 @@
33 31
 	[self.view addSubview:dismissModalButton];
34 32
 }
35 33
 
34
+- (void)addPushButton {
35
+	UIButton* pushNativeVCButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.center.x - 70, 370, 140, 50)];
36
+	pushNativeVCButton.backgroundColor = UIColor.systemBlueColor;
37
+	pushNativeVCButton.accessibilityIdentifier = @"PUSH_NATIVE_BTN";
38
+	[pushNativeVCButton setTitle:@"Push Native VC" forState:UIControlStateNormal];
39
+	[pushNativeVCButton addTarget:self action:@selector(pushNativeVC) forControlEvents:UIControlEventTouchDown];
40
+	[self.view addSubview:pushNativeVCButton];
41
+}
42
+
36 43
 - (void)addTestLabel {
37 44
 	UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
38 45
 	label.textAlignment = NSTextAlignmentCenter;
@@ -49,6 +56,15 @@
49 56
 	self.navigationItem.rightBarButtonItem = rightButton;
50 57
 }
51 58
 
59
+- (void)dismissModal {
60
+	[self dismissViewControllerAnimated:YES completion:nil];
61
+}
62
+
63
+- (void)pushNativeVC {
64
+	RNNNativeViewController* nativeVC = [[RNNNativeViewController alloc] init];
65
+	[self.navigationController pushViewController:nativeVC animated:NO];
66
+}
67
+
52 68
 - (void)rightButtonPressed {
53 69
 	
54 70
 }

+ 5
- 0
playground/ios/playground/RNNNativeViewController.h View File

@@ -0,0 +1,5 @@
1
+#import <UIKit/UIKit.h>
2
+
3
+@interface RNNNativeViewController : UIViewController
4
+
5
+@end

+ 28
- 0
playground/ios/playground/RNNNativeViewController.m View File

@@ -0,0 +1,28 @@
1
+#import "RNNNativeViewController.h"
2
+
3
+@interface RNNNativeViewController ()
4
+
5
+@end
6
+
7
+@implementation RNNNativeViewController
8
+
9
+- (void)viewDidLoad {
10
+    [super viewDidLoad];
11
+	self.view.backgroundColor = UIColor.whiteColor;
12
+	[self addPopButton];
13
+}
14
+
15
+- (void)addPopButton {
16
+	UIButton* popNativeVCButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.center.x - 70, 370, 140, 50)];
17
+	popNativeVCButton.backgroundColor = UIColor.systemBlueColor;
18
+	popNativeVCButton.accessibilityIdentifier = @"POP_NATIVE_BTN";
19
+	[popNativeVCButton setTitle:@"Pop" forState:UIControlStateNormal];
20
+	[popNativeVCButton addTarget:self action:@selector(pop) forControlEvents:UIControlEventTouchDown];
21
+	[self.view addSubview:popNativeVCButton];
22
+}
23
+
24
+- (void)pop {
25
+	[self.navigationController popViewControllerAnimated:NO];
26
+}
27
+
28
+@end

+ 2
- 0
playground/src/testIDs.js View File

@@ -149,6 +149,8 @@ module.exports = {
149 149
   EXTERNAL_DISMISS_MODAL_BTN: 'EXTERNAL_DISMISS_MODAL_BTN',
150 150
   EXTERNAL_TOP_BAR_RIGHT_BTN: 'EXTERNAL_TOP_BAR_RIGHT_BTN',
151 151
   GOTO_SHARED_ELEMENT_SCREEN: 'GOTO_SHARED_ELEMENT_SCREEN',
152
+  PUSH_NATIVE_BTN: 'PUSH_NATIVE_BTN',
153
+  POP_NATIVE_BTN: 'POP_NATIVE_BTN',
152 154
 
153 155
   // Elements
154 156
   SCROLLVIEW_ELEMENT: `SCROLLVIEW_ELEMENT`,