react-native-navigation的迁移库

TopBarAppearancePresenter.m 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. - (void)showBorder:(BOOL)showBorder {
  39. UIColor* shadowColor = showBorder ? [[UINavigationBarAppearance new] shadowColor] : nil;
  40. _appearance.shadowColor = shadowColor;
  41. }
  42. - (void)setBackIndicatorImage:(UIImage *)image withColor:(UIColor *)color {
  43. [_appearance setBackIndicatorImage:image transitionMaskImage:image];
  44. }
  45. - (void)setTitleAttributes:(RNNTitleOptions *)titleOptions {
  46. NSString* fontFamily = [titleOptions.fontFamily getWithDefaultValue:nil];
  47. NSString* fontWeight = [titleOptions.fontWeight getWithDefaultValue:nil];
  48. NSNumber* fontSize = [titleOptions.fontSize getWithDefaultValue:nil];
  49. UIColor* fontColor = [titleOptions.color getWithDefaultValue:nil];
  50. _appearance.titleTextAttributes = [RNNFontAttributesCreator createFromDictionary:_appearance.titleTextAttributes fontFamily:fontFamily fontSize:fontSize defaultFontSize:nil fontWeight:fontWeight color:fontColor defaultColor:nil];
  51. }
  52. - (void)setLargeTitleAttributes:(RNNLargeTitleOptions *)largeTitleOptions {
  53. NSString* fontFamily = [largeTitleOptions.fontFamily getWithDefaultValue:nil];
  54. NSString* fontWeight = [largeTitleOptions.fontWeight getWithDefaultValue:nil];
  55. NSNumber* fontSize = [largeTitleOptions.fontSize getWithDefaultValue:nil];
  56. UIColor* fontColor = [largeTitleOptions.color getWithDefaultValue:nil];
  57. _appearance.largeTitleTextAttributes = [RNNFontAttributesCreator createFromDictionary:_appearance.largeTitleTextAttributes fontFamily:fontFamily fontSize:fontSize defaultFontSize:nil fontWeight:fontWeight color:fontColor defaultColor:nil];
  58. }
  59. @end