react-native-navigation的迁移库

RNNBackButtonOptions.m 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #import "RNNBackButtonOptions.h"
  2. #import "UIImage+tint.h"
  3. @implementation RNNBackButtonOptions
  4. - (void)applyOn:(UIViewController *)viewController {
  5. if (self.visible) {
  6. viewController.navigationItem.hidesBackButton = ![self.visible boolValue];
  7. }
  8. [self applyOnNavigationController:viewController.navigationController];
  9. }
  10. - (void)applyOnNavigationController:(UINavigationController *)navigationController {
  11. UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
  12. UIImage* tintedIcon = self.tintedIconIfAvailable;
  13. if (tintedIcon) {
  14. backItem.image = tintedIcon;
  15. [navigationController.navigationBar setBackIndicatorImage:[UIImage new]];
  16. [navigationController.navigationBar setBackIndicatorTransitionMaskImage:[UIImage new]];
  17. }
  18. if (self.color) {
  19. backItem.tintColor = [RCTConvert UIColor:self.color];
  20. }
  21. if (self.showTitle && ![self.showTitle boolValue]) {
  22. self.title = @"";
  23. }
  24. [self setBackItem:backItem onNavigationController:navigationController];
  25. }
  26. - (void)setBackItem:(UIBarButtonItem *)backItem onNavigationController:(UINavigationController *)navigationController {
  27. NSArray *viewControllers = navigationController.viewControllers;
  28. UIViewController *lastViewControllerInStack = [viewControllers lastObject];
  29. backItem.title = self.title ? self.title : lastViewControllerInStack.navigationItem.title;
  30. lastViewControllerInStack.navigationItem.backBarButtonItem = backItem;
  31. }
  32. - (UIImage *)tintedIconIfAvailable {
  33. if (self.icon) {
  34. UIImage *image = [RCTConvert UIImage:self.icon];
  35. return self.color
  36. ? [[image withTintColor:[RCTConvert UIColor:self.color]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
  37. : image;
  38. }
  39. return nil;
  40. }
  41. @end