浏览代码

External components fixes (#5896)

* Fix external components layout

* Fix external component navigationItem options resolving

* f
Yogev Ben David 4 年前
父节点
当前提交
4d9f866097

+ 5
- 0
e2e/ExternalComponent.test.js 查看文件

@@ -41,4 +41,9 @@ describe('External Component', () => {
41 41
     await elementById(TestIDs.EXTERNAL_DISMISS_MODAL_BTN).tap();
42 42
     await expect(elementById(TestIDs.NAVIGATION_SCREEN)).toBeVisible();
43 43
   });
44
+
45
+  test(':ios: External component should receive options', async () => {
46
+    await elementById(TestIDs.MODAL_BTN).tap();
47
+    await expect(elementByLabel('External Component')).toBeVisible();
48
+  });
44 49
 });

+ 1
- 1
lib/ios/RNNControllerFactory.m 查看文件

@@ -124,7 +124,7 @@
124 124
 - (UIViewController *)createExternalComponent:(RNNLayoutNode*)node {
125 125
 	RNNLayoutInfo* layoutInfo = [[RNNLayoutInfo alloc] initWithNode:node];
126 126
 	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:node.data[@"options"]];
127
-	RNNComponentPresenter* presenter = [[RNNComponentPresenter alloc] initWithDefaultOptions:_defaultOptions];
127
+	RNNComponentPresenter* presenter = [[RNNComponentPresenter alloc] initWithComponentRegistry:_componentRegistry defaultOptions:_defaultOptions];
128 128
 	
129 129
 	UIViewController* externalVC = [_store getExternalComponent:layoutInfo bridge:_bridge];
130 130
 	

+ 2
- 1
lib/ios/RNNExternalViewController.m 查看文件

@@ -5,7 +5,8 @@
5 5
 }
6 6
 
7 7
 - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo eventEmitter:(RNNEventEmitter *)eventEmitter presenter:(RNNComponentPresenter *)presenter options:(RNNNavigationOptions *)options defaultOptions:(RNNNavigationOptions *)defaultOptions viewController:(UIViewController *)viewController {
8
-	self = [super initWithLayoutInfo:layoutInfo rootViewCreator:nil eventEmitter:eventEmitter presenter:presenter options:options defaultOptions:defaultOptions];
8
+    _boundViewController = viewController;
9
+    self = [super initWithLayoutInfo:layoutInfo rootViewCreator:nil eventEmitter:eventEmitter presenter:presenter options:options defaultOptions:defaultOptions];
9 10
     [self bindViewController:viewController];
10 11
 	return self;
11 12
 }

+ 29
- 0
playground/ios/NavigationTests/RNNExternalViewControllerTests.m 查看文件

@@ -0,0 +1,29 @@
1
+#import <XCTest/XCTest.h>
2
+#import <OCMock/OCMock.h>
3
+#import <ReactNativeNavigation/RNNExternalViewController.h>
4
+#import <ReactNativeNavigation/RNNCustomViewController.h>
5
+
6
+@interface RNNExternalViewControllerTest : XCTestCase
7
+
8
+@property (nonatomic, strong) RNNExternalViewController* uut;
9
+@property (nonatomic, strong) RNNCustomViewController* customViewController;
10
+
11
+@end
12
+
13
+@implementation RNNExternalViewControllerTest
14
+
15
+- (void)setUp {
16
+	[super setUp];
17
+	self.customViewController = [[RNNCustomViewController alloc] init];
18
+	RNNLayoutInfo* layoutInfo = [[RNNLayoutInfo alloc] init];
19
+	layoutInfo.componentId = @"externalComponentId";
20
+	RNNComponentPresenter* presenter = [[RNNComponentPresenter alloc] initWithComponentRegistry:nil defaultOptions:nil];
21
+	self.uut = [[RNNExternalViewController alloc] initWithLayoutInfo:layoutInfo eventEmitter:nil presenter:presenter options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil viewController:self.customViewController];
22
+}
23
+
24
+- (void)testLoadView_withMainScreenBounds {
25
+	XCTAssertTrue(CGRectEqualToRect(self.uut.view.bounds, UIScreen.mainScreen.bounds));
26
+}
27
+
28
+
29
+@end

+ 4
- 0
playground/ios/playground.xcodeproj/project.pbxproj 查看文件

@@ -13,6 +13,7 @@
13 13
 		13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
14 14
 		501C86B9239FE9C400E0B631 /* UIImage+Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 501C86B8239FE9C400E0B631 /* UIImage+Utils.m */; };
15 15
 		50451D35204451A900695F00 /* RNNCustomViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 50451D34204451A800695F00 /* RNNCustomViewController.m */; };
16
+		50647FE323E3196800B92025 /* RNNExternalViewControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 50647FE223E3196800B92025 /* RNNExternalViewControllerTests.m */; };
16 17
 		50996C6823AA477400008F89 /* RNNRootViewControllerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 50996C6723AA477400008F89 /* RNNRootViewControllerTest.m */; };
17 18
 		50996C6923AA487800008F89 /* RNNTestRootViewCreator.m in Sources */ = {isa = PBXBuildFile; fileRef = E58D263D2385888C003F36BA /* RNNTestRootViewCreator.m */; };
18 19
 		67C681D42B662A53F29C19DA /* Pods_NavigationIOS12Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DEE0B5D45FD34FBABC6586CF /* Pods_NavigationIOS12Tests.framework */; };
@@ -83,6 +84,7 @@
83 84
 		50364D6B238E7F0A000E62A2 /* ReactNativeNavigation.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = ReactNativeNavigation.framework; sourceTree = BUILT_PRODUCTS_DIR; };
84 85
 		50451D33204451A800695F00 /* RNNCustomViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNNCustomViewController.h; path = ../../../lib/ios/RNNCustomViewController.h; sourceTree = "<group>"; };
85 86
 		50451D34204451A800695F00 /* RNNCustomViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNNCustomViewController.m; path = ../../../lib/ios/RNNCustomViewController.m; sourceTree = "<group>"; };
87
+		50647FE223E3196800B92025 /* RNNExternalViewControllerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNExternalViewControllerTests.m; sourceTree = "<group>"; };
86 88
 		50996C5D23AA46DD00008F89 /* NavigationIOS12Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NavigationIOS12Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
87 89
 		50996C6123AA46DD00008F89 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
88 90
 		50996C6723AA477400008F89 /* RNNRootViewControllerTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNRootViewControllerTest.m; sourceTree = "<group>"; };
@@ -271,6 +273,7 @@
271 273
 				E58D263B2385888C003F36BA /* UITabBarController+RNNOptionsTest.m */,
272 274
 				E58D26252385888B003F36BA /* UIViewController+LayoutProtocolTest.m */,
273 275
 				E58D263E2385888C003F36BA /* UIViewController+RNNOptionsTest.m */,
276
+				50647FE223E3196800B92025 /* RNNExternalViewControllerTests.m */,
274 277
 				E58D262E2385888B003F36BA /* utils */,
275 278
 				E58D261F238587F4003F36BA /* Info.plist */,
276 279
 			);
@@ -735,6 +738,7 @@
735 738
 			files = (
736 739
 				E58D265B2385888C003F36BA /* UIViewController+RNNOptionsTest.m in Sources */,
737 740
 				E58D26532385888C003F36BA /* RNNSideMenuPresenterTest.m in Sources */,
741
+				50647FE323E3196800B92025 /* RNNExternalViewControllerTests.m in Sources */,
738 742
 				E58D264D2385888C003F36BA /* RNNOverlayManagerTest.m in Sources */,
739 743
 				501C86B9239FE9C400E0B631 /* UIImage+Utils.m in Sources */,
740 744
 				E58D265F2385888C003F36BA /* RNNBasePresenterTest.m in Sources */,

+ 7
- 0
playground/src/screens/ExternalComponentScreen.js 查看文件

@@ -51,6 +51,13 @@ class ExternalComponentScreen extends React.Component {
51 51
           name: Screens.NativeScreen,
52 52
           passProps: {
53 53
             text: 'External component in deep stack'
54
+          },
55
+          options: {
56
+            topBar: {
57
+              title: {
58
+                text: 'External Component'
59
+              }
60
+            }
54 61
           }
55 62
         }
56 63
       }