react-native-navigation的迁移库

UINavigationBar+utils.m 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #import "UINavigationBar+utils.h"
  2. const NSInteger TOP_BAR_TRANSPARENT_TAG = 78264803;
  3. @implementation UINavigationBar (utils)
  4. - (void)rnn_setBackIndicatorImage:(UIImage *)image {
  5. if (@available(iOS 13.0, *)) {
  6. [[self getNavigaitonBarStandardAppearance] setBackIndicatorImage:image transitionMaskImage:image];
  7. [[self getNavigaitonBarCompactAppearance] setBackIndicatorImage:image transitionMaskImage:image];
  8. [[self getNavigaitonBarScrollEdgeAppearance] setBackIndicatorImage:image transitionMaskImage:image];
  9. } else {
  10. [self setBackIndicatorImage:image];
  11. [self setBackIndicatorTransitionMaskImage:image];
  12. }
  13. }
  14. - (void)rnn_setBackgroundColor:(UIColor *)color {
  15. CGFloat bgColorAlpha = CGColorGetAlpha(color.CGColor);
  16. if (color && bgColorAlpha == 0.0) {
  17. self.translucent = YES;
  18. [self setBackgroundColorTransparent];
  19. } else {
  20. self.translucent = NO;
  21. [self setBackgroundColor:color];
  22. }
  23. }
  24. - (void)setBackgroundColor:(UIColor *)color {
  25. if (@available(iOS 13.0, *)) {
  26. [self configureWithDefaultBackground];
  27. [self getNavigaitonBarStandardAppearance].backgroundColor = color;
  28. [self getNavigaitonBarCompactAppearance].backgroundColor = color;
  29. [self getNavigaitonBarScrollEdgeAppearance].backgroundColor = color;
  30. } else {
  31. [super setBackgroundColor:color];
  32. [self removeTransparentView];
  33. }
  34. }
  35. - (void)setBackgroundColorTransparent {
  36. if (@available(iOS 13.0, *)) {
  37. [self configureWithTransparentBackground];
  38. } else {
  39. if (![self viewWithTag:TOP_BAR_TRANSPARENT_TAG]){
  40. UIView *transparentView = [[UIView alloc] initWithFrame:CGRectZero];
  41. transparentView.backgroundColor = [UIColor clearColor];
  42. transparentView.tag = TOP_BAR_TRANSPARENT_TAG;
  43. [self insertSubview:transparentView atIndex:0];
  44. }
  45. [self setBackgroundColor:[UIColor clearColor]];
  46. self.shadowImage = [UIImage new];
  47. [self setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
  48. }
  49. }
  50. - (void)removeTransparentView {
  51. UIView *transparentView = [self viewWithTag:TOP_BAR_TRANSPARENT_TAG];
  52. if (transparentView){
  53. [transparentView removeFromSuperview];
  54. }
  55. }
  56. - (void)configureWithTransparentBackground {
  57. if (@available(iOS 13.0, *)) {
  58. [[self getNavigaitonBarStandardAppearance] configureWithTransparentBackground];
  59. [[self getNavigaitonBarCompactAppearance] configureWithTransparentBackground];
  60. [[self getNavigaitonBarScrollEdgeAppearance] configureWithTransparentBackground];
  61. }
  62. }
  63. - (void)configureWithDefaultBackground {
  64. if (@available(iOS 13.0, *)) {
  65. [[self getNavigaitonBarStandardAppearance] configureWithDefaultBackground];
  66. [[self getNavigaitonBarCompactAppearance] configureWithDefaultBackground];
  67. [[self getNavigaitonBarScrollEdgeAppearance] configureWithDefaultBackground];
  68. }
  69. }
  70. - (UINavigationBarAppearance*)getNavigaitonBarStandardAppearance API_AVAILABLE(ios(13.0)) {
  71. if (!self.standardAppearance) {
  72. self.standardAppearance = [UINavigationBarAppearance new];
  73. }
  74. return self.standardAppearance;
  75. }
  76. - (UINavigationBarAppearance*)getNavigaitonBarCompactAppearance API_AVAILABLE(ios(13.0)) {
  77. if (!self.compactAppearance) {
  78. self.compactAppearance = [UINavigationBarAppearance new];
  79. }
  80. return self.compactAppearance;
  81. }
  82. - (UINavigationBarAppearance*)getNavigaitonBarScrollEdgeAppearance API_AVAILABLE(ios(13.0)) {
  83. if (!self.scrollEdgeAppearance) {
  84. self.scrollEdgeAppearance = [UINavigationBarAppearance new];
  85. }
  86. return self.scrollEdgeAppearance;
  87. }
  88. @end