react-native-navigation的迁移库

RNNBackButtonOptions.m 1.7KB

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