Browse Source

navigator.setSubTitle() support for iOS (#1167)

Add setSubTitle implementation for iOS + docs
Loris Cro 7 years ago
parent
commit
8302064cec

+ 11
- 0
docs/screen-api.md View File

159
 });
159
 });
160
 ```
160
 ```
161
 
161
 
162
+
163
+## setSubTitle(params = {})
164
+
165
+Set the nav bar subtitle dynamically. If your subtitle doesn't change during runtime, set it when the screen is defined / pushed.
166
+
167
+```js
168
+this.props.navigator.setSubTitle({
169
+  subtitle: "Connecting..." 
170
+});
171
+```
172
+
162
 ## toggleDrawer(params = {})
173
 ## toggleDrawer(params = {})
163
 
174
 
164
 Toggle the side menu drawer assuming you have one in your app.
175
 Toggle the side menu drawer assuming you have one in your app.

+ 2
- 1
ios/Helpers/RCCTitleViewHelper.h View File

23
 - (instancetype)init:(UIViewController*)viewController
23
 - (instancetype)init:(UIViewController*)viewController
24
 navigationController:(UINavigationController*)navigationController
24
 navigationController:(UINavigationController*)navigationController
25
                title:(NSString*)title subtitle:(NSString*)subtitle
25
                title:(NSString*)title subtitle:(NSString*)subtitle
26
-      titleImageData:(id)titleImageData;
26
+      titleImageData:(id)titleImageData
27
+       isSetSubtitle:(BOOL)isSetSubtitle;
27
 
28
 
28
 -(void)setup:(NSDictionary*)style;
29
 -(void)setup:(NSDictionary*)style;
29
 
30
 

+ 8
- 1
ios/Helpers/RCCTitleViewHelper.m View File

23
 @property (nonatomic, strong) NSString *title;
23
 @property (nonatomic, strong) NSString *title;
24
 @property (nonatomic, strong) NSString *subtitle;
24
 @property (nonatomic, strong) NSString *subtitle;
25
 @property (nonatomic, strong) id titleImageData;
25
 @property (nonatomic, strong) id titleImageData;
26
+@property (nonatomic) BOOL isSetSubtitle;
26
 
27
 
27
 @property (nonatomic, strong) RCCTitleView *titleView;
28
 @property (nonatomic, strong) RCCTitleView *titleView;
28
 
29
 
35
 navigationController:(UINavigationController*)navigationController
36
 navigationController:(UINavigationController*)navigationController
36
                title:(NSString*)title subtitle:(NSString*)subtitle
37
                title:(NSString*)title subtitle:(NSString*)subtitle
37
       titleImageData:(id)titleImageData
38
       titleImageData:(id)titleImageData
39
+       isSetSubtitle:(BOOL)isSetSubtitle
40
+
38
 {
41
 {
39
     self = [super init];
42
     self = [super init];
40
     if (self) {
43
     if (self) {
41
         self.viewController = viewController;
44
         self.viewController = viewController;
42
         self.navigationController = navigationController;
45
         self.navigationController = navigationController;
43
-        self.title = [RCCTitleViewHelper validateString:title];
46
+        if(isSetSubtitle){
47
+            self.title = viewController.navigationItem.title;
48
+        } else {
49
+            self.title = [RCCTitleViewHelper validateString:title];
50
+        }
44
         self.subtitle = [RCCTitleViewHelper validateString:subtitle];
51
         self.subtitle = [RCCTitleViewHelper validateString:subtitle];
45
         self.titleImageData = titleImageData;
52
         self.titleImageData = titleImageData;
46
     }
53
     }

+ 3
- 2
ios/RCCNavigationController.m View File

333
                   props:(NSDictionary*)props
333
                   props:(NSDictionary*)props
334
                   style:(NSDictionary*)style
334
                   style:(NSDictionary*)style
335
 {
335
 {
336
-  
336
+  BOOL isSetSubtitleBool = props[@"isSetSubtitle"] ? [props[@"isSetSubtitle"] boolValue] : NO;
337
   RCCTitleViewHelper *titleViewHelper = [[RCCTitleViewHelper alloc] init:viewController
337
   RCCTitleViewHelper *titleViewHelper = [[RCCTitleViewHelper alloc] init:viewController
338
                                                     navigationController:self
338
                                                     navigationController:self
339
                                                                    title:props[@"title"]
339
                                                                    title:props[@"title"]
340
                                                                 subtitle:props[@"subtitle"]
340
                                                                 subtitle:props[@"subtitle"]
341
-                                                          titleImageData:props[@"titleImage"]];
341
+                                                          titleImageData:props[@"titleImage"]
342
+                                                           isSetSubtitle:isSetSubtitleBool];
342
   
343
   
343
   [titleViewHelper setup:style];
344
   [titleViewHelper setup:style];
344
   
345
   

+ 1
- 1
ios/RCCViewController.m View File

266
   if (self.navigationItem.titleView && [self.navigationItem.titleView isKindOfClass:[RCCTitleView class]]) {
266
   if (self.navigationItem.titleView && [self.navigationItem.titleView isKindOfClass:[RCCTitleView class]]) {
267
     
267
     
268
     RCCTitleView *titleView = (RCCTitleView *)self.navigationItem.titleView;
268
     RCCTitleView *titleView = (RCCTitleView *)self.navigationItem.titleView;
269
-    RCCTitleViewHelper *helper = [[RCCTitleViewHelper alloc] init:viewController navigationController:viewController.navigationController title:titleView.titleLabel.text subtitle:titleView.subtitleLabel.text titleImageData:nil];
269
+    RCCTitleViewHelper *helper = [[RCCTitleViewHelper alloc] init:viewController navigationController:viewController.navigationController title:titleView.titleLabel.text subtitle:titleView.subtitleLabel.text titleImageData:nil isSetSubtitle:NO];
270
     [helper setup:self.navigatorStyle];
270
     [helper setup:self.navigatorStyle];
271
   }
271
   }
272
   
272
   

+ 13
- 1
src/deprecated/platformSpecificDeprecated.ios.js View File

306
     title: params.title,
306
     title: params.title,
307
     subtitle: params.subtitle,
307
     subtitle: params.subtitle,
308
     titleImage: params.titleImage,
308
     titleImage: params.titleImage,
309
-    style: params.navigatorStyle
309
+    style: params.navigatorStyle,
310
+    isSetSubtitle: false
311
+  });
312
+}
313
+
314
+function navigatorSetSubtitle(navigator, params) {
315
+  Controllers.NavigationControllerIOS(navigator.navigatorID).setTitle({
316
+    title: params.title,
317
+    subtitle: params.subtitle,
318
+    titleImage: params.titleImage,
319
+    style: params.navigatorStyle,
320
+    isSetSubtitle: true
310
   });
321
   });
311
 }
322
 }
312
 
323
 
594
   dismissInAppNotification,
605
   dismissInAppNotification,
595
   navigatorSetButtons,
606
   navigatorSetButtons,
596
   navigatorSetTitle,
607
   navigatorSetTitle,
608
+  navigatorSetSubtitle,
597
   navigatorSetStyle,
609
   navigatorSetStyle,
598
   navigatorSetTitleImage,
610
   navigatorSetTitleImage,
599
   navigatorToggleDrawer,
611
   navigatorToggleDrawer,