react-native-navigation的迁移库

TopBarAppearancePresenter.m 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #import "TopBarAppearancePresenter.h"
  2. #import "RNNFontAttributesCreator.h"
  3. @interface TopBarAppearancePresenter ()
  4. @end
  5. @implementation TopBarAppearancePresenter {
  6. UINavigationBarAppearance* _appearance;
  7. }
  8. @synthesize backgroundColor = _backgroundColor;
  9. @synthesize translucent = _translucent;
  10. - (instancetype)initWithNavigationController:(UINavigationController *)boundNavigationController {
  11. self = [super initWithNavigationController:boundNavigationController];
  12. _appearance = boundNavigationController.navigationBar.standardAppearance ?: [UINavigationBarAppearance new];
  13. boundNavigationController.navigationBar.standardAppearance = _appearance;
  14. return self;
  15. }
  16. - (void)setTranslucent:(BOOL)translucent {
  17. _translucent = translucent;
  18. [self updateBackgroundAppearance];
  19. }
  20. - (void)setTransparent:(BOOL)transparent {
  21. [self updateBackgroundAppearance];
  22. }
  23. - (void)setBackgroundColor:(UIColor *)backgroundColor {
  24. _backgroundColor = backgroundColor;
  25. [self updateBackgroundAppearance];
  26. }
  27. - (void)updateBackgroundAppearance {
  28. if (self.transparent) {
  29. [_appearance configureWithTransparentBackground];
  30. } else if (_backgroundColor) {
  31. [_appearance setBackgroundColor:_backgroundColor];
  32. } else if (_translucent) {
  33. [_appearance configureWithDefaultBackground];
  34. } else {
  35. [_appearance configureWithOpaqueBackground];
  36. }
  37. }
  38. - (BOOL)transparent {
  39. return (_backgroundColor && CGColorGetAlpha(_backgroundColor.CGColor) == 0.0);
  40. }
  41. - (void)showBorder:(BOOL)showBorder {
  42. UIColor* shadowColor = showBorder ? [[UINavigationBarAppearance new] shadowColor] : nil;
  43. _appearance.shadowColor = shadowColor;
  44. }
  45. - (void)setBackIndicatorImage:(UIImage *)image withColor:(UIColor *)color {
  46. [_appearance setBackIndicatorImage:image transitionMaskImage:image];
  47. }
  48. - (void)setTitleAttributes:(RNNTitleOptions *)titleOptions {
  49. NSString* fontFamily = [titleOptions.fontFamily getWithDefaultValue:nil];
  50. NSString* fontWeight = [titleOptions.fontWeight getWithDefaultValue:nil];
  51. NSNumber* fontSize = [titleOptions.fontSize getWithDefaultValue:nil];
  52. UIColor* fontColor = [titleOptions.color getWithDefaultValue:nil];
  53. _appearance.titleTextAttributes = [RNNFontAttributesCreator createFromDictionary:_appearance.titleTextAttributes fontFamily:fontFamily fontSize:fontSize defaultFontSize:nil fontWeight:fontWeight color:fontColor defaultColor:nil];
  54. }
  55. - (void)setLargeTitleAttributes:(RNNLargeTitleOptions *)largeTitleOptions {
  56. NSString* fontFamily = [largeTitleOptions.fontFamily getWithDefaultValue:nil];
  57. NSString* fontWeight = [largeTitleOptions.fontWeight getWithDefaultValue:nil];
  58. NSNumber* fontSize = [largeTitleOptions.fontSize getWithDefaultValue:nil];
  59. UIColor* fontColor = [largeTitleOptions.color getWithDefaultValue:nil];
  60. _appearance.largeTitleTextAttributes = [RNNFontAttributesCreator createFromDictionary:_appearance.largeTitleTextAttributes fontFamily:fontFamily fontSize:fontSize defaultFontSize:nil fontWeight:fontWeight color:fontColor defaultColor:nil];
  61. }
  62. @end