react-native-navigation的迁移库

RNNBackButtonOptions.m 1.3KB

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