react-native-navigation的迁移库

TopBarAppearancePresenter.m 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. [self.getScrollEdgeAppearance configureWithTransparentBackground];
  29. } else if (self.backgroundColor) {
  30. [self.getAppearance setBackgroundColor:self.backgroundColor];
  31. [self.getScrollEdgeAppearance setBackgroundColor:self.backgroundColor];
  32. } else if (self.translucent) {
  33. [self.getAppearance configureWithDefaultBackground];
  34. [self.getScrollEdgeAppearance configureWithDefaultBackground];
  35. } else {
  36. [self.getAppearance configureWithOpaqueBackground];
  37. [self.getScrollEdgeAppearance configureWithOpaqueBackground];
  38. }
  39. }
  40. - (void)showBorder:(BOOL)showBorder {
  41. UIColor* shadowColor = showBorder ? [[UINavigationBarAppearance new] shadowColor] : nil;
  42. self.getAppearance.shadowColor = shadowColor;
  43. }
  44. - (void)setBackIndicatorImage:(UIImage *)image withColor:(UIColor *)color {
  45. [self.getAppearance setBackIndicatorImage:image transitionMaskImage:image];
  46. }
  47. - (void)setTitleAttributes:(RNNTitleOptions *)titleOptions {
  48. NSString* fontFamily = [titleOptions.fontFamily getWithDefaultValue:nil];
  49. NSString* fontWeight = [titleOptions.fontWeight getWithDefaultValue:nil];
  50. NSNumber* fontSize = [titleOptions.fontSize getWithDefaultValue:nil];
  51. UIColor* fontColor = [titleOptions.color getWithDefaultValue:nil];
  52. self.getAppearance.titleTextAttributes = [RNNFontAttributesCreator createFromDictionary:self.getAppearance.titleTextAttributes fontFamily:fontFamily fontSize:fontSize defaultFontSize:nil fontWeight:fontWeight color:fontColor defaultColor:nil];
  53. }
  54. - (void)setLargeTitleAttributes:(RNNLargeTitleOptions *)largeTitleOptions {
  55. NSString* fontFamily = [largeTitleOptions.fontFamily getWithDefaultValue:nil];
  56. NSString* fontWeight = [largeTitleOptions.fontWeight getWithDefaultValue:nil];
  57. NSNumber* fontSize = [largeTitleOptions.fontSize getWithDefaultValue:nil];
  58. UIColor* fontColor = [largeTitleOptions.color getWithDefaultValue:nil];
  59. self.getAppearance.largeTitleTextAttributes = [RNNFontAttributesCreator createFromDictionary:self.getAppearance.largeTitleTextAttributes fontFamily:fontFamily fontSize:fontSize defaultFontSize:nil fontWeight:fontWeight color:fontColor defaultColor:nil];
  60. }
  61. - (UINavigationBarAppearance *)getAppearance {
  62. return self.currentNavigationItem.standardAppearance;
  63. }
  64. - (UINavigationBarAppearance *)getScrollEdgeAppearance {
  65. return self.currentNavigationItem.scrollEdgeAppearance;
  66. }
  67. @end