react-native-navigation的迁移库

TopBarAppearancePresenter.m 2.7KB

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