瀏覽代碼

Fixes backButton styling on iOS

yogevbd 6 年之前
父節點
當前提交
932f79bf08
共有 1 個文件被更改,包括 10 次插入2 次删除
  1. 10
    2
      lib/ios/RNNBackButtonOptions.m

+ 10
- 2
lib/ios/RNNBackButtonOptions.m 查看文件

@@ -10,14 +10,14 @@
10 10
 		[viewController.navigationController.navigationBar setBackIndicatorTransitionMaskImage:[UIImage new]];
11 11
 		
12 12
 		UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:nil action:nil];
13
-		viewController.navigationItem.backBarButtonItem = backItem;
13
+		[self setBackItem:backItem onViewController:viewController];
14 14
 	} else if (self.title) {
15 15
 		UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:self.title
16 16
 																	 style:UIBarButtonItemStylePlain
17 17
 																	target:nil
18 18
 																	action:nil];
19 19
 		
20
-		viewController.navigationItem.backBarButtonItem = backItem;
20
+		[self setBackItem:backItem onViewController:viewController];
21 21
 	}
22 22
 	
23 23
 	if (self.visible) {
@@ -29,6 +29,14 @@
29 29
 	}
30 30
 }
31 31
 
32
+- (void)setBackItem:(UIBarButtonItem *)backItem onViewController:(UIViewController *)viewController {
33
+	UINavigationController* nvc = viewController.navigationController;
34
+	if (nvc.viewControllers.count >= 2) {
35
+		UIViewController* lastViewControllerInStack = nvc.viewControllers[nvc.viewControllers.count - 2];
36
+		lastViewControllerInStack.navigationItem.backBarButtonItem = backItem;
37
+	}
38
+}
39
+
32 40
 - (UIImage *)tintedIcon {
33 41
 	UIImage *image = self.icon ? [RCTConvert UIImage:self.icon] : nil;
34 42
 	if (self.color) {