Browse Source

modalPresentationStyle support

yogevbd 6 years ago
parent
commit
1041708fb5

+ 1
- 0
docs/docs/styling.md View File

65
   popGesture: true,
65
   popGesture: true,
66
   backgroundImage: require('background.png'),
66
   backgroundImage: require('background.png'),
67
   rootBackgroundImage: require('rootBackground.png'),
67
   rootBackgroundImage: require('rootBackground.png'),
68
+  modalPresentationStyle: 'formSheet', // Supported styles are: 'formSheet', 'pageSheet', 'overFullScreen', 'overCurrentContext', 'currentContext', 'popOver', 'fullScreen' and 'none'.
68
   topBar: {
69
   topBar: {
69
     visible: true,
70
     visible: true,
70
     leftButtons: [{
71
     leftButtons: [{

+ 3
- 2
lib/ios/RNNNavigationOptions.h View File

35
 @property (nonatomic, strong) NSNumber* statusBarHideWithTopBar;
35
 @property (nonatomic, strong) NSNumber* statusBarHideWithTopBar;
36
 @property (nonatomic, strong) NSString* statusBarStyle;
36
 @property (nonatomic, strong) NSString* statusBarStyle;
37
 @property (nonatomic, strong) NSNumber* popGesture;
37
 @property (nonatomic, strong) NSNumber* popGesture;
38
-@property (nonatomic, strong) UIImage* backgroundImage;
39
-@property (nonatomic, strong) UIImage* rootBackgroundImage;
38
+@property (nonatomic, strong) NSDictionary* backgroundImage;
39
+@property (nonatomic, strong) NSDictionary* rootBackgroundImage;
40
+@property (nonatomic, strong) NSString* modalPresentationStyle;
40
 
41
 
41
 - (UIInterfaceOrientationMask)supportedOrientations;
42
 - (UIInterfaceOrientationMask)supportedOrientations;
42
 
43
 

+ 20
- 38
lib/ios/RNNNavigationOptions.m View File

11
 const NSInteger BLUR_TOPBAR_TAG = 78264802;
11
 const NSInteger BLUR_TOPBAR_TAG = 78264802;
12
 const NSInteger TOP_BAR_TRANSPARENT_TAG = 78264803;
12
 const NSInteger TOP_BAR_TRANSPARENT_TAG = 78264803;
13
 
13
 
14
-@implementation RNNNavigationOptions
14
+@implementation RCTConvert (UIModalPresentationStyle)
15
 
15
 
16
--(instancetype)init {
17
-	return [self initWithDict:@{}];
18
-}
16
+RCT_ENUM_CONVERTER(UIModalPresentationStyle,
17
+				   (@{@"fullScreen": @(UIModalPresentationFullScreen),
18
+					  @"pageSheet": @(UIModalPresentationPageSheet),
19
+					  @"formSheet": @(UIModalPresentationFormSheet),
20
+					  @"currentContext": @(UIModalPresentationCurrentContext),
21
+					  @"custom": @(UIModalPresentationCustom),
22
+					  @"overFullScreen": @(UIModalPresentationOverFullScreen),
23
+					  @"overCurrentContext": @(UIModalPresentationOverCurrentContext),
24
+					  @"popover": @(UIModalPresentationPopover),
25
+					  @"none": @(UIModalPresentationNone)
26
+					  }), UIModalPresentationFullScreen, integerValue)
19
 
27
 
20
--(instancetype)initWithDict:(NSDictionary *)options {
21
-	self = [super init];
22
-	self.statusBarHidden = [options objectForKey:@"statusBarHidden"];
23
-	self.statusBarBlur = [options objectForKey:@"statusBarBlur"];
24
-	self.statusBarStyle = [options objectForKey:@"statusBarStyle"];
25
-	self.screenBackgroundColor = [options objectForKey:@"screenBackgroundColor"];
26
-	self.backButtonTransition = [options objectForKey:@"backButtonTransition"];
27
-	self.orientation = [options objectForKey:@"orientation"];
28
-	self.topBar = [[RNNTopBarOptions alloc] initWithDict:[options objectForKey:@"topBar"]];
29
-	self.topTab = [[RNNTopTabOptions alloc] initWithDict:[options objectForKey:@"topTab"]];
30
-	self.bottomTabs = [[RNNBottomTabsOptions alloc] initWithDict:[options objectForKey:@"bottomTabs"]];
31
-	self.sideMenu = [[RNNSideMenuOptions alloc] initWithDict:[options objectForKey:@"sideMenu"]];
32
-	self.backgroundImage = [RCTConvert UIImage:[options objectForKey:@"backgroundImage"]];
33
-	self.rootBackgroundImage = [RCTConvert UIImage:[options objectForKey:@"rootBackgroundImage"]];
34
-	self.bottomTab = [[RNNBottomTabOptions alloc] initWithDict:[options objectForKey:@"bottomTab"]];
35
-	self.overlay = [[RNNOverlayOptions alloc] initWithDict:[options objectForKey:@"overlay"]];
36
-	self.customTransition = [[RNNAnimationOptions alloc] initWithDict:[options objectForKey:@"customTransition"]];
37
-	self.animations = [[RNNTransitionsOptions alloc] initWithDict:[options objectForKey:@"animations"]];
28
+@end
38
 
29
 
39
-	return self;
40
-}
30
+@implementation RNNNavigationOptions
41
 
31
 
42
--(void)mergeWith:(NSDictionary *)otherOptions {
43
-	for (id key in otherOptions) {
44
-		if ([self hasProperty:key]) {
45
-			if ([[self valueForKey:key] isKindOfClass:[RNNOptions class]]) {
46
-				RNNOptions* options = [self valueForKey:key];
47
-				[options mergeWith:[otherOptions objectForKey:key]];
48
-			} else {
49
-				[self setValue:[otherOptions objectForKey:key] forKey:key];
50
-			}
51
-		}
52
-	}
53
-}
54
 
32
 
55
 -(void)applyOn:(UIViewController<RNNRootViewProtocol> *)viewController {
33
 -(void)applyOn:(UIViewController<RNNRootViewProtocol> *)viewController {
56
 	[self.topBar applyOn:viewController];
34
 	[self.topBar applyOn:viewController];
98
 		}
76
 		}
99
 		
77
 		
100
 		backgroundImageView.layer.masksToBounds = YES;
78
 		backgroundImageView.layer.masksToBounds = YES;
101
-		backgroundImageView.image = self.backgroundImage;
79
+		backgroundImageView.image = [RCTConvert UIImage:self.backgroundImage];
102
 		[backgroundImageView setContentMode:UIViewContentModeScaleAspectFill];
80
 		[backgroundImageView setContentMode:UIViewContentModeScaleAspectFill];
103
 	}
81
 	}
104
 	
82
 	
110
 		}
88
 		}
111
 		
89
 		
112
 		backgroundImageView.layer.masksToBounds = YES;
90
 		backgroundImageView.layer.masksToBounds = YES;
113
-		backgroundImageView.image = self.rootBackgroundImage;
91
+		backgroundImageView.image = [RCTConvert UIImage:self.rootBackgroundImage];
114
 		[backgroundImageView setContentMode:UIViewContentModeScaleAspectFill];
92
 		[backgroundImageView setContentMode:UIViewContentModeScaleAspectFill];
115
 	}
93
 	}
94
+	
95
+	if (self.modalPresentationStyle) {
96
+		viewController.modalPresentationStyle = [RCTConvert UIModalPresentationStyle:self.modalPresentationStyle];
97
+	}
116
 }
98
 }
117
 
99
 
118
 - (UIInterfaceOrientationMask)supportedOrientations {
100
 - (UIInterfaceOrientationMask)supportedOrientations {

+ 2
- 2
lib/ios/ReactNativeNavigationTests/RNNCommandsHandlerTest.m View File

62
 }
62
 }
63
 
63
 
64
 -(void)testDynamicStylesMergeWithStaticStyles {
64
 -(void)testDynamicStylesMergeWithStaticStyles {
65
-	RNNNavigationOptions* initialOptions = [[RNNNavigationOptions alloc] init];
65
+	RNNNavigationOptions* initialOptions = [[RNNNavigationOptions alloc] initWithDict:@{}];
66
 	initialOptions.topBar.title.text = @"the title";
66
 	initialOptions.topBar.title.text = @"the title";
67
 	RNNRootViewController* vc = [[RNNRootViewController alloc] initWithName:@"name"
67
 	RNNRootViewController* vc = [[RNNRootViewController alloc] initWithName:@"name"
68
 																withOptions:initialOptions
68
 																withOptions:initialOptions
77
 	[self.store setReadyToReceiveCommands:true];
77
 	[self.store setReadyToReceiveCommands:true];
78
 	[self.store setComponent:vc componentId:@"componentId"];
78
 	[self.store setComponent:vc componentId:@"componentId"];
79
 	
79
 	
80
-	NSDictionary* dictFromJs = @{@"topBar": @{@"backgroundColor" :@(0xFFFF0000)}};
80
+	NSDictionary* dictFromJs = @{@"topBar": @{@"background" : @{@"color" : @(0xFFFF0000)}}};
81
 	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
81
 	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
82
 
82
 
83
 	[self.uut mergeOptions:@"componentId" options:dictFromJs completion:^{
83
 	[self.uut mergeOptions:@"componentId" options:dictFromJs completion:^{