Kaynağa Gözat

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

Add setSubTitle implementation for iOS + docs
Loris Cro 7 yıl önce
ebeveyn
işleme
8302064cec

+ 11
- 0
docs/screen-api.md Dosyayı Görüntüle

@@ -159,6 +159,17 @@ this.props.navigator.setTitle({
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 173
 ## toggleDrawer(params = {})
163 174
 
164 175
 Toggle the side menu drawer assuming you have one in your app.

+ 2
- 1
ios/Helpers/RCCTitleViewHelper.h Dosyayı Görüntüle

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

+ 8
- 1
ios/Helpers/RCCTitleViewHelper.m Dosyayı Görüntüle

@@ -23,6 +23,7 @@
23 23
 @property (nonatomic, strong) NSString *title;
24 24
 @property (nonatomic, strong) NSString *subtitle;
25 25
 @property (nonatomic, strong) id titleImageData;
26
+@property (nonatomic) BOOL isSetSubtitle;
26 27
 
27 28
 @property (nonatomic, strong) RCCTitleView *titleView;
28 29
 
@@ -35,12 +36,18 @@
35 36
 navigationController:(UINavigationController*)navigationController
36 37
                title:(NSString*)title subtitle:(NSString*)subtitle
37 38
       titleImageData:(id)titleImageData
39
+       isSetSubtitle:(BOOL)isSetSubtitle
40
+
38 41
 {
39 42
     self = [super init];
40 43
     if (self) {
41 44
         self.viewController = viewController;
42 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 51
         self.subtitle = [RCCTitleViewHelper validateString:subtitle];
45 52
         self.titleImageData = titleImageData;
46 53
     }

+ 3
- 2
ios/RCCNavigationController.m Dosyayı Görüntüle

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

+ 1
- 1
ios/RCCViewController.m Dosyayı Görüntüle

@@ -266,7 +266,7 @@ const NSInteger TRANSPARENT_NAVBAR_TAG = 78264803;
266 266
   if (self.navigationItem.titleView && [self.navigationItem.titleView isKindOfClass:[RCCTitleView class]]) {
267 267
     
268 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 270
     [helper setup:self.navigatorStyle];
271 271
   }
272 272
   

+ 13
- 1
src/deprecated/platformSpecificDeprecated.ios.js Dosyayı Görüntüle

@@ -306,7 +306,18 @@ function navigatorSetTitle(navigator, params) {
306 306
     title: params.title,
307 307
     subtitle: params.subtitle,
308 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,6 +605,7 @@ export default {
594 605
   dismissInAppNotification,
595 606
   navigatorSetButtons,
596 607
   navigatorSetTitle,
608
+  navigatorSetSubtitle,
597 609
   navigatorSetStyle,
598 610
   navigatorSetTitleImage,
599 611
   navigatorToggleDrawer,