Преглед изворни кода

Fix bottom tabs attach mode (#5757)

Improved attach mode together unit test
Yogev Ben David пре 5 година
родитељ
комит
e236cb9f5a

+ 2
- 2
lib/ios/BottomTabsAttachMode.h Прегледај датотеку

@@ -1,4 +1,4 @@
1
-#import "Text.h"
1
+#import "Enum.h"
2 2
 
3 3
 typedef NS_ENUM(NSInteger, AttachMode) {
4 4
     BottomTabsAttachModeTogether = 0,
@@ -6,7 +6,7 @@ typedef NS_ENUM(NSInteger, AttachMode) {
6 6
     BottomTabsAttachModeOnSwitchToTab
7 7
 };
8 8
 
9
-@interface BottomTabsAttachMode : Text
9
+@interface BottomTabsAttachMode : Enum
10 10
 
11 11
 - (AttachMode)get;
12 12
 

+ 2
- 6
lib/ios/BottomTabsAttachMode.m Прегледај датотеку

@@ -3,12 +3,8 @@
3 3
 
4 4
 @implementation BottomTabsAttachMode
5 5
 
6
-- (AttachMode)get {
7
-    return [self.class AttachMode:[super get]];
8
-}
9
-
10
-- (AttachMode)getWithDefaultValue:(id)defaultValue {
11
-    return [self.class AttachMode:[super getWithDefaultValue:defaultValue]];
6
+- (AttachMode)convertString:(NSString *)string {
7
+    return [self.class AttachMode:string];
12 8
 }
13 9
 
14 10
 RCT_ENUM_CONVERTER(AttachMode,

+ 12
- 0
lib/ios/Enum.h Прегледај датотеку

@@ -0,0 +1,12 @@
1
+#import <Foundation/Foundation.h>
2
+#import "Param.h"
3
+
4
+@interface Enum : Param
5
+
6
+- (int)get;
7
+
8
+- (int)getWithDefaultValue:(int)defaultValue;
9
+
10
+- (int)convertString:(NSString *)string;
11
+
12
+@end

+ 22
- 0
lib/ios/Enum.m Прегледај датотеку

@@ -0,0 +1,22 @@
1
+#import "Enum.h"
2
+
3
+@implementation Enum
4
+
5
+- (int)get {
6
+    return [self convertString:super.get];
7
+}
8
+
9
+- (int)getWithDefaultValue:(int)defaultValue {
10
+    NSString* value = [super getWithDefaultValue:nil];
11
+	if (value) {
12
+        return [self convertString:value];
13
+    } else {
14
+        return defaultValue;
15
+    }
16
+}
17
+
18
+- (int)convertString:(NSString *)string {
19
+    return 0;
20
+}
21
+
22
+@end

+ 8
- 0
lib/ios/EnumParser.h Прегледај датотеку

@@ -0,0 +1,8 @@
1
+#import <Foundation/Foundation.h>
2
+#import "Enum.h"
3
+
4
+@interface EnumParser : NSObject
5
+
6
++ (Enum *)parse:(NSDictionary *)json key:(NSString *)key ofClass:(Class)class;
7
+
8
+@end

+ 13
- 0
lib/ios/EnumParser.m Прегледај датотеку

@@ -0,0 +1,13 @@
1
+#import "EnumParser.h"
2
+#import "NullEnum.h"
3
+
4
+@implementation EnumParser
5
+
6
++ (Enum *)parse:(NSDictionary *)json key:(NSString *)key ofClass:(Class)class {
7
+	if (json[key]) {
8
+		return [json[key] isKindOfClass:[NSString class]] ? [[class alloc] initWithValue:json[key]] : [NullEnum new];
9
+	}
10
+	return [NullEnum new];
11
+}
12
+
13
+@end

+ 5
- 0
lib/ios/NullEnum.h Прегледај датотеку

@@ -0,0 +1,5 @@
1
+#import "Enum.h"
2
+
3
+@interface NullEnum : Enum
4
+
5
+@end

+ 10
- 0
lib/ios/NullEnum.m Прегледај датотеку

@@ -0,0 +1,10 @@
1
+#import "NullEnum.h"
2
+
3
+@implementation NullEnum
4
+
5
+- (instancetype)init {
6
+	self = [super initWithValue:nil];
7
+	return self;
8
+}
9
+
10
+@end

+ 1
- 1
lib/ios/RNNBottomTabsOptions.m Прегледај датотеку

@@ -20,7 +20,7 @@
20 20
 	self.barStyle = [TextParser parse:dict key:@"barStyle"];
21 21
 	self.fontFamily = [TextParser parse:dict key:@"fontFamily"];
22 22
 	self.titleDisplayMode = [TextParser parse:dict key:@"titleDisplayMode"];
23
-    self.tabsAttachMode = [TextParser parse:dict key:@"tabsAttachMode"];
23
+    self.tabsAttachMode = (BottomTabsAttachMode *)[EnumParser parse:dict key:@"tabsAttachMode" ofClass:BottomTabsAttachMode.class];
24 24
 	
25 25
 	return self;
26 26
 }

+ 2
- 2
lib/ios/RNNComponentViewController.m Прегледај датотеку

@@ -52,8 +52,8 @@
52 52
 - (void)render {
53 53
     if (!self.waitForRender)
54 54
         [self readyForPresentation];
55
-    else
56
-        [self renderReactViewIfNeeded];
55
+
56
+    [self renderReactViewIfNeeded];
57 57
 }
58 58
 
59 59
 - (void)renderReactViewIfNeeded {

+ 1
- 0
lib/ios/RNNOptions.h Прегледај датотеку

@@ -8,6 +8,7 @@
8 8
 #import "ImageParser.h"
9 9
 #import "IntNumberParser.h"
10 10
 #import "DoubleParser.h"
11
+#import "EnumParser.h"
11 12
 
12 13
 @interface RNNOptions : NSObject
13 14
 

+ 24
- 0
lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj Прегледај датотеку

@@ -215,6 +215,12 @@
215 215
 		50887CA920F26BFE00D06111 /* RNNOverlayWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 50887CA720F26BFD00D06111 /* RNNOverlayWindow.m */; };
216 216
 		50887CAA20F26BFE00D06111 /* RNNOverlayWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = 50887CA820F26BFE00D06111 /* RNNOverlayWindow.h */; };
217 217
 		508EBDBD2278746400BEC144 /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 508EBDBA2278742700BEC144 /* JavaScriptCore.framework */; };
218
+		509416A323A11C340036092C /* Enum.h in Headers */ = {isa = PBXBuildFile; fileRef = 509416A123A11C340036092C /* Enum.h */; };
219
+		509416A423A11C340036092C /* Enum.m in Sources */ = {isa = PBXBuildFile; fileRef = 509416A223A11C340036092C /* Enum.m */; };
220
+		509416A723A11C630036092C /* EnumParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 509416A523A11C630036092C /* EnumParser.h */; };
221
+		509416A823A11C630036092C /* EnumParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 509416A623A11C630036092C /* EnumParser.m */; };
222
+		509416AB23A11CB20036092C /* NullEnum.h in Headers */ = {isa = PBXBuildFile; fileRef = 509416A923A11CB20036092C /* NullEnum.h */; };
223
+		509416AC23A11CB20036092C /* NullEnum.m in Sources */ = {isa = PBXBuildFile; fileRef = 509416AA23A11CB20036092C /* NullEnum.m */; };
218 224
 		50967F5B232FC2C200BEEA92 /* RNNFontAttributesCreatorTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 50967F5A232FC2C200BEEA92 /* RNNFontAttributesCreatorTest.m */; };
219 225
 		509B2480217873FF00C83C23 /* UINavigationController+RNNOptionsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 509B247F217873FF00C83C23 /* UINavigationController+RNNOptionsTest.m */; };
220 226
 		509B258F2178BE7A00C83C23 /* RNNStackPresenterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 509B258E2178BE7A00C83C23 /* RNNStackPresenterTest.m */; };
@@ -585,6 +591,12 @@
585 591
 		50887CA720F26BFD00D06111 /* RNNOverlayWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNOverlayWindow.m; sourceTree = "<group>"; };
586 592
 		50887CA820F26BFE00D06111 /* RNNOverlayWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNNOverlayWindow.h; sourceTree = "<group>"; };
587 593
 		508EBDBA2278742700BEC144 /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
594
+		509416A123A11C340036092C /* Enum.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Enum.h; sourceTree = "<group>"; };
595
+		509416A223A11C340036092C /* Enum.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Enum.m; sourceTree = "<group>"; };
596
+		509416A523A11C630036092C /* EnumParser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EnumParser.h; sourceTree = "<group>"; };
597
+		509416A623A11C630036092C /* EnumParser.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EnumParser.m; sourceTree = "<group>"; };
598
+		509416A923A11CB20036092C /* NullEnum.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NullEnum.h; sourceTree = "<group>"; };
599
+		509416AA23A11CB20036092C /* NullEnum.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NullEnum.m; sourceTree = "<group>"; };
588 600
 		50967F5A232FC2C200BEEA92 /* RNNFontAttributesCreatorTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNFontAttributesCreatorTest.m; sourceTree = "<group>"; };
589 601
 		509B247F217873FF00C83C23 /* UINavigationController+RNNOptionsTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UINavigationController+RNNOptionsTest.m"; sourceTree = "<group>"; };
590 602
 		509B258E2178BE7A00C83C23 /* RNNStackPresenterTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNStackPresenterTest.m; sourceTree = "<group>"; };
@@ -910,10 +922,14 @@
910 922
 				5012241521736667000F5F98 /* Color.m */,
911 923
 				5012241821736678000F5F98 /* Image.h */,
912 924
 				5012241921736678000F5F98 /* Image.m */,
925
+				509416A123A11C340036092C /* Enum.h */,
926
+				509416A223A11C340036092C /* Enum.m */,
913 927
 				50E02BD621A6EE0F00A43942 /* SideMenuOpenMode.h */,
914 928
 				50E02BD721A6EE0F00A43942 /* SideMenuOpenMode.m */,
915 929
 				50495940216F5E5D006D2B81 /* NullBool.h */,
916 930
 				50495941216F5E5D006D2B81 /* NullBool.m */,
931
+				509416A923A11CB20036092C /* NullEnum.h */,
932
+				509416AA23A11CB20036092C /* NullEnum.m */,
917 933
 				50495948216F5FE6006D2B81 /* NullText.h */,
918 934
 				50495949216F5FE6006D2B81 /* NullText.m */,
919 935
 				50495950216F62BD006D2B81 /* NullNumber.h */,
@@ -959,6 +975,8 @@
959 975
 				5039559A2174867000B0A663 /* DoubleParser.m */,
960 976
 				309874E37C7E9764C7B694E5 /* DotIndicatorParser.m */,
961 977
 				309871FBA64AD937CEF3E191 /* DotIndicatorParser.h */,
978
+				509416A523A11C630036092C /* EnumParser.h */,
979
+				509416A623A11C630036092C /* EnumParser.m */,
962 980
 			);
963 981
 			name = Parsers;
964 982
 			sourceTree = "<group>";
@@ -1337,6 +1355,7 @@
1337 1355
 				504AFE761FFFF1E00076E904 /* RNNNavigationOptions.h in Headers */,
1338 1356
 				504AFE771FFFF1E20076E904 /* RNNTopBarOptions.h in Headers */,
1339 1357
 				5038A3CE216E35E0009280BC /* Dictionary.h in Headers */,
1358
+				509416A323A11C340036092C /* Enum.h in Headers */,
1340 1359
 				26916C981E4B9E7700D13680 /* RNNReactRootViewCreator.h in Headers */,
1341 1360
 				5012241A21736678000F5F98 /* Image.h in Headers */,
1342 1361
 				506A2B1420973DFD00F43A95 /* RNNErrorHandler.h in Headers */,
@@ -1361,6 +1380,7 @@
1361 1380
 				50E02BDD21A6EE7900A43942 /* SideMenuOpenGestureModeParser.h in Headers */,
1362 1381
 				5038A3B5216DF602009280BC /* UINavigationController+RNNOptions.h in Headers */,
1363 1382
 				50E5F78D223F9FAF002AFEAD /* RNNElementTransitionOptions.h in Headers */,
1383
+				509416AB23A11CB20036092C /* NullEnum.h in Headers */,
1364 1384
 				E5F6C3A422DB4D0F0093C2CE /* UIColor+RNNUtils.h in Headers */,
1365 1385
 				5038A3C1216E1E66009280BC /* RNNFontAttributesCreator.h in Headers */,
1366 1386
 				5016E8EF20209690009D4F7C /* RNNCustomTitleView.h in Headers */,
@@ -1396,6 +1416,7 @@
1396 1416
 				7BEF0D181E437684003E96B0 /* RNNComponentViewController.h in Headers */,
1397 1417
 				7B1126A61E2D2B6C00F9B03B /* RNNBridgeModule.h in Headers */,
1398 1418
 				E8DA24401F97459B00CD552B /* RNNElementFinder.h in Headers */,
1419
+				509416A723A11C630036092C /* EnumParser.h in Headers */,
1399 1420
 				50AB0B1C2255F8640039DAED /* UIViewController+LayoutProtocol.h in Headers */,
1400 1421
 				50D031342005149000386B3D /* RNNOverlayManager.h in Headers */,
1401 1422
 				50E5F7952240EBD6002AFEAD /* RNNAnimationsTransitionDelegate.h in Headers */,
@@ -1606,6 +1627,7 @@
1606 1627
 			buildActionMask = 2147483647;
1607 1628
 			files = (
1608 1629
 				50C4A497206BDDBB00DB292E /* RNNSubtitleOptions.m in Sources */,
1630
+				509416A823A11C630036092C /* EnumParser.m in Sources */,
1609 1631
 				50A409CB238D444900D5FF7D /* UINavigationBar+utils.m in Sources */,
1610 1632
 				50AB0B1D2255F8640039DAED /* UIViewController+LayoutProtocol.m in Sources */,
1611 1633
 				263905B41E4C6F440023D7D3 /* MMDrawerVisualState.m in Sources */,
@@ -1623,6 +1645,7 @@
1623 1645
 				501CD320214A5B6900A6E225 /* RNNLayoutInfo.m in Sources */,
1624 1646
 				7BEF0D191E437684003E96B0 /* RNNComponentViewController.m in Sources */,
1625 1647
 				50415CBB20553B8E00BB682E /* RNNScreenTransition.m in Sources */,
1648
+				509416A423A11C340036092C /* Enum.m in Sources */,
1626 1649
 				E8A5CD531F464F0400E89D0D /* RNNAnimator.m in Sources */,
1627 1650
 				50CB3B6A1FDE911400AA153B /* RNNSideMenuOptions.m in Sources */,
1628 1651
 				261F0E6B1E6F028A00989DE2 /* RNNNavigationStackManager.m in Sources */,
@@ -1640,6 +1663,7 @@
1640 1663
 				7B1126A01E2D263F00F9B03B /* RNNEventEmitter.m in Sources */,
1641 1664
 				A7626BFD1FC2FB2C00492FB8 /* RNNTopBarOptions.m in Sources */,
1642 1665
 				5050465521F8F4490035497A /* RNNReactComponentRegistry.m in Sources */,
1666
+				509416AC23A11CB20036092C /* NullEnum.m in Sources */,
1643 1667
 				50570BEB2063E09B006A1B5C /* RNNTitleViewHelper.m in Sources */,
1644 1668
 				263905E71E4CAC950023D7D3 /* RNNSideMenuChildVC.m in Sources */,
1645 1669
 				50495957216F6B3D006D2B81 /* DictionaryParser.m in Sources */,

+ 12
- 7
playground/ios/NavigationTests/RNNCommandsHandlerTest.m Прегледај датотеку

@@ -54,6 +54,7 @@
54 54
 @property (nonatomic, strong) id controllerFactory;
55 55
 @property (nonatomic, strong) id overlayManager;
56 56
 @property (nonatomic, strong) id eventEmmiter;
57
+@property (nonatomic, strong) id creator;
57 58
 
58 59
 @end
59 60
 
@@ -61,22 +62,25 @@
61 62
 
62 63
 - (void)setUp {
63 64
 	[super setUp];
65
+	self.creator = [OCMockObject partialMockForObject:[RNNTestRootViewCreator new]];
64 66
 	self.mainWindow = [OCMockObject partialMockForObject:[UIWindow new]];
65 67
 	self.eventEmmiter = [OCMockObject partialMockForObject:[RNNEventEmitter new]];
66 68
 	self.overlayManager = [OCMockObject partialMockForObject:[RNNOverlayManager new]];
67 69
 	self.modalManager = [OCMockObject partialMockForObject:[RNNModalManager new]];
68 70
 	self.controllerFactory = [OCMockObject partialMockForObject:[[RNNControllerFactory alloc] initWithRootViewCreator:nil eventEmitter:self.eventEmmiter store:nil componentRegistry:nil andBridge:nil bottomTabsAttachModeFactory:[BottomTabsAttachModeFactory new]]];
69 71
 	self.uut = [[RNNCommandsHandler alloc] initWithControllerFactory:self.controllerFactory eventEmitter:self.eventEmmiter stackManager:[RNNNavigationStackManager new] modalManager:self.modalManager overlayManager:self.overlayManager mainWindow:_mainWindow];
70
-	self.vc1 = self.generateComponent;
71
-	self.vc2 = self.generateComponent;
72
-	self.vc3 = self.generateComponent;
72
+	self.vc1 = [self generateComponentWithComponentId:@"1"];
73
+	self.vc2 = [self generateComponentWithComponentId:@"2"];
74
+	self.vc3 = [self generateComponentWithComponentId:@"3"];
73 75
 	_nvc = [[MockUINavigationController alloc] init];
74 76
 	[_nvc setViewControllers:@[self.vc1, self.vc2, self.vc3]];
75 77
 	OCMStub([self.sharedApplication keyWindow]).andReturn(self.mainWindow);
76 78
 }
77 79
 
78
-- (RNNComponentViewController *)generateComponent {
79
-	return [[RNNComponentViewController alloc] initWithLayoutInfo:nil rootViewCreator:[[RNNTestRootViewCreator alloc] init] eventEmitter:nil presenter:[RNNComponentPresenter new] options:[[RNNNavigationOptions alloc] initWithDict:@{}] defaultOptions:nil];
80
+- (RNNComponentViewController *)generateComponentWithComponentId:(NSString *)componentId {
81
+	RNNLayoutInfo* layoutInfo = [[RNNLayoutInfo alloc] init];
82
+	layoutInfo.componentId = componentId;
83
+	return [[RNNComponentViewController alloc] initWithLayoutInfo:layoutInfo rootViewCreator:_creator eventEmitter:nil presenter:[RNNComponentPresenter new] options:[[RNNNavigationOptions alloc] initWithDict:@{}] defaultOptions:nil];
80 84
 }
81 85
 
82 86
 - (void)testAssertReadyForEachMethodThrowsExceptoins {
@@ -187,7 +191,7 @@
187 191
 
188 192
 - (void)testShowOverlay_withCreatedLayout {
189 193
 	[self.uut setReadyToReceiveCommands:true];
190
-	UIViewController* layoutVC = self.generateComponent;
194
+	UIViewController* layoutVC = [self generateComponentWithComponentId:nil];
191 195
 	OCMStub([self.controllerFactory createLayout:[OCMArg any]]).andReturn(layoutVC);
192 196
 	
193 197
 	[[self.overlayManager expect] showOverlayWindow:[OCMArg any]];
@@ -364,7 +368,6 @@
364 368
 	[self.uut setReadyToReceiveCommands:true];
365 369
 	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
366 370
 	options.bottomTabs.tabsAttachMode = [[BottomTabsAttachMode alloc] initWithValue:@"together"];
367
-	options.animations.setRoot.waitForRender = [[Bool alloc] initWithBOOL:YES];
368 371
 
369 372
 	BottomTabsBaseAttacher* attacher = [[[BottomTabsAttachModeFactory alloc] initWithDefaultOptions:nil] fromOptions:options];
370 373
 	RNNBottomTabsController* tabBarController = [[RNNBottomTabsController alloc] initWithLayoutInfo:nil creator:nil options:options defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions] presenter:[RNNBasePresenter new] eventEmitter:_eventEmmiter childViewControllers:@[_vc1, _vc2] bottomTabsAttacher:attacher];
@@ -374,6 +377,8 @@
374 377
 	[self.uut setRoot:@{} commandId:@"" completion:^{}];
375 378
 	XCTAssertTrue(_vc1.isViewLoaded);
376 379
 	XCTAssertTrue(_vc2.isViewLoaded);
380
+	XCTAssertEqual(_vc1.view.tag, 1);
381
+	XCTAssertEqual(_vc2.view.tag, 2);
377 382
 }
378 383
 
379 384
 - (void)testSetRoot_withBottomTabsAttachModeOnSwitchToTab {

+ 1
- 0
playground/ios/NavigationTests/RNNTestRootViewCreator.m Прегледај датотеку

@@ -4,6 +4,7 @@
4 4
 
5 5
 - (UIView*)createRootView:(NSString*)name rootViewId:(NSString*)rootViewId reactViewReadyBlock:(RNNReactViewReadyCompletionBlock)reactViewReadyBlock {
6 6
 	UIView *view = [[UIView alloc] init];
7
+	view.tag = [rootViewId intValue];
7 8
 	return view;
8 9
 }
9 10