Browse Source

modalPresentationStyle support

yogevbd 6 years ago
parent
commit
1041708fb5

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

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

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

@@ -35,8 +35,9 @@ extern const NSInteger TOP_BAR_TRANSPARENT_TAG;
35 35
 @property (nonatomic, strong) NSNumber* statusBarHideWithTopBar;
36 36
 @property (nonatomic, strong) NSString* statusBarStyle;
37 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 42
 - (UIInterfaceOrientationMask)supportedOrientations;
42 43
 

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

@@ -11,46 +11,24 @@ const NSInteger BLUR_STATUS_TAG = 78264801;
11 11
 const NSInteger BLUR_TOPBAR_TAG = 78264802;
12 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 33
 -(void)applyOn:(UIViewController<RNNRootViewProtocol> *)viewController {
56 34
 	[self.topBar applyOn:viewController];
@@ -98,7 +76,7 @@ const NSInteger TOP_BAR_TRANSPARENT_TAG = 78264803;
98 76
 		}
99 77
 		
100 78
 		backgroundImageView.layer.masksToBounds = YES;
101
-		backgroundImageView.image = self.backgroundImage;
79
+		backgroundImageView.image = [RCTConvert UIImage:self.backgroundImage];
102 80
 		[backgroundImageView setContentMode:UIViewContentModeScaleAspectFill];
103 81
 	}
104 82
 	
@@ -110,9 +88,13 @@ const NSInteger TOP_BAR_TRANSPARENT_TAG = 78264803;
110 88
 		}
111 89
 		
112 90
 		backgroundImageView.layer.masksToBounds = YES;
113
-		backgroundImageView.image = self.rootBackgroundImage;
91
+		backgroundImageView.image = [RCTConvert UIImage:self.rootBackgroundImage];
114 92
 		[backgroundImageView setContentMode:UIViewContentModeScaleAspectFill];
115 93
 	}
94
+	
95
+	if (self.modalPresentationStyle) {
96
+		viewController.modalPresentationStyle = [RCTConvert UIModalPresentationStyle:self.modalPresentationStyle];
97
+	}
116 98
 }
117 99
 
118 100
 - (UIInterfaceOrientationMask)supportedOrientations {

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

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