react-native-navigation的迁移库

TopBarAppearancePresenter.m 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #import "TopBarAppearancePresenter.h"
  2. #import "RNNFontAttributesCreator.h"
  3. #import "UIViewController+LayoutProtocol.h"
  4. @interface TopBarAppearancePresenter ()
  5. @end
  6. @implementation TopBarAppearancePresenter
  7. - (void)applyOptions:(RNNTopBarOptions *)options {
  8. [self setTranslucent:[options.background.translucent getWithDefaultValue:NO]];
  9. [self setBackgroundColor:[options.background.color getWithDefaultValue:nil]];
  10. [self setTitleAttributes:options.title];
  11. [self setLargeTitleAttributes:options.largeTitle];
  12. [self showBorder:![options.noBorder getWithDefaultValue:NO]];
  13. [self setBackButtonOptions:options.backButton];
  14. }
  15. - (void)applyOptionsBeforePopping:(RNNTopBarOptions *)options {
  16. [self setBackgroundColor:[options.background.color getWithDefaultValue:nil]];
  17. }
  18. - (void)setTranslucent:(BOOL)translucent {
  19. [super setTranslucent:translucent];
  20. [self updateBackgroundAppearance];
  21. }
  22. - (void)setTransparent:(BOOL)transparent {
  23. [self updateBackgroundAppearance];
  24. }
  25. - (void)updateBackgroundAppearance {
  26. if (self.transparent) {
  27. [self.getAppearance configureWithTransparentBackground];
  28. } else if (self.backgroundColor) {
  29. [self.getAppearance setBackgroundColor:self.backgroundColor];
  30. } else if (self.translucent) {
  31. [self.getAppearance configureWithDefaultBackground];
  32. } else {
  33. [self.getAppearance configureWithOpaqueBackground];
  34. }
  35. }
  36. - (void)showBorder:(BOOL)showBorder {
  37. UIColor* shadowColor = showBorder ? [[UINavigationBarAppearance new] shadowColor] : nil;
  38. self.getAppearance.shadowColor = shadowColor;
  39. }
  40. - (void)setBackIndicatorImage:(UIImage *)image withColor:(UIColor *)color {
  41. [self.getAppearance setBackIndicatorImage:image transitionMaskImage:image];
  42. }
  43. - (void)setTitleAttributes:(RNNTitleOptions *)titleOptions {
  44. NSString* fontFamily = [titleOptions.fontFamily getWithDefaultValue:nil];
  45. NSString* fontWeight = [titleOptions.fontWeight getWithDefaultValue:nil];
  46. NSNumber* fontSize = [titleOptions.fontSize getWithDefaultValue:nil];
  47. UIColor* fontColor = [titleOptions.color getWithDefaultValue:nil];
  48. self.getAppearance.titleTextAttributes = [RNNFontAttributesCreator createFromDictionary:self.getAppearance.titleTextAttributes fontFamily:fontFamily fontSize:fontSize defaultFontSize:nil fontWeight:fontWeight color:fontColor defaultColor:nil];
  49. }
  50. - (void)setLargeTitleAttributes:(RNNLargeTitleOptions *)largeTitleOptions {
  51. NSString* fontFamily = [largeTitleOptions.fontFamily getWithDefaultValue:nil];
  52. NSString* fontWeight = [largeTitleOptions.fontWeight getWithDefaultValue:nil];
  53. NSNumber* fontSize = [largeTitleOptions.fontSize getWithDefaultValue:nil];
  54. UIColor* fontColor = [largeTitleOptions.color getWithDefaultValue:nil];
  55. self.getAppearance.largeTitleTextAttributes = [RNNFontAttributesCreator createFromDictionary:self.getAppearance.largeTitleTextAttributes fontFamily:fontFamily fontSize:fontSize defaultFontSize:nil fontWeight:fontWeight color:fontColor defaultColor:nil];
  56. }
  57. - (UINavigationBarAppearance *)getAppearance {
  58. return self.currentNavigationItem.standardAppearance;
  59. }
  60. @end