Преглед на файлове

Ensure that styles set on individual buttons are not overridden (#2200)

This fixes a bug where navigator-level styles could override styles on a specific button.
Eli Perkins преди 7 години
родител
ревизия
2b966e50ca
променени са 1 файла, в които са добавени 24 реда и са изтрити 8 реда
  1. 24
    8
      ios/RCCViewController.m

+ 24
- 8
ios/RCCViewController.m Целия файл

@@ -399,21 +399,37 @@ const NSInteger TRANSPARENT_NAVBAR_TAG = 78264803;
399 399
       ) {
400 400
     
401 401
     for (UIBarButtonItem *item in viewController.navigationItem.leftBarButtonItems) {
402
-      [item setTitleTextAttributes:navButtonTextAttributes forState:UIControlStateNormal];
403
-      
404 402
       if (leftNavButtonTextAttributes.allKeys.count > 0) {
405
-        [item setTitleTextAttributes:leftNavButtonTextAttributes forState:UIControlStateNormal];
403
+        NSDictionary *previousAttributes = [item titleTextAttributesForState:UIControlStateNormal];
404
+        NSMutableDictionary *mergedAttributes;
405
+
406
+        if (leftNavButtonTextAttributes.allKeys.count > 0) {
407
+          mergedAttributes = [leftNavButtonTextAttributes mutableCopy];
408
+        } else {
409
+          mergedAttributes = [navButtonTextAttributes mutableCopy];
410
+        }
411
+
412
+        [mergedAttributes addEntriesFromDictionary:previousAttributes];
413
+
414
+        [item setTitleTextAttributes:[mergedAttributes copy] forState:UIControlStateNormal];
406 415
       }
407 416
     }
408
-    
417
+
409 418
     for (UIBarButtonItem *item in viewController.navigationItem.rightBarButtonItems) {
410
-      [item setTitleTextAttributes:navButtonTextAttributes forState:UIControlStateNormal];
411
-      
419
+      NSDictionary *previousAttributes = [item titleTextAttributesForState:UIControlStateNormal];
420
+      NSMutableDictionary *mergedAttributes;
421
+
412 422
       if (rightNavButtonTextAttributes.allKeys.count > 0) {
413
-        [item setTitleTextAttributes:rightNavButtonTextAttributes forState:UIControlStateNormal];
423
+        mergedAttributes = [rightNavButtonTextAttributes mutableCopy];
424
+      } else {
425
+        mergedAttributes = [navButtonTextAttributes mutableCopy];
414 426
       }
427
+
428
+      [mergedAttributes addEntriesFromDictionary:previousAttributes];
429
+
430
+      [item setTitleTextAttributes:[mergedAttributes copy] forState:UIControlStateNormal];
415 431
     }
416
-    
432
+
417 433
     // At the moment, this seems to be the only thing that gets the back button correctly
418 434
     [navButtonTextAttributes removeObjectForKey:NSForegroundColorAttributeName];
419 435
     [[UIBarButtonItem appearance] setTitleTextAttributes:navButtonTextAttributes forState:UIControlStateNormal];