react-native-navigation的迁移库

TopBarAppearancePresenter.m 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. }
  17. - (void)setTranslucent:(BOOL)translucent {
  18. [super setTranslucent:translucent];
  19. [self updateBackgroundAppearance];
  20. }
  21. - (void)setTransparent:(BOOL)transparent {
  22. [self updateBackgroundAppearance];
  23. }
  24. - (void)updateBackgroundAppearance {
  25. if (self.transparent) {
  26. [self.getAppearance configureWithTransparentBackground];
  27. [self.getScrollEdgeAppearance configureWithTransparentBackground];
  28. } else if (self.backgroundColor) {
  29. [self.getAppearance configureWithOpaqueBackground];
  30. [self.getScrollEdgeAppearance configureWithOpaqueBackground];
  31. [self.getAppearance setBackgroundColor:self.backgroundColor];
  32. [self.getScrollEdgeAppearance setBackgroundColor:self.backgroundColor];
  33. } else if (self.translucent) {
  34. [self.getAppearance configureWithDefaultBackground];
  35. [self.getScrollEdgeAppearance configureWithDefaultBackground];
  36. } else {
  37. [self.getAppearance configureWithOpaqueBackground];
  38. [self.getScrollEdgeAppearance configureWithOpaqueBackground];
  39. }
  40. }
  41. - (void)showBorder:(BOOL)showBorder {
  42. UIColor* shadowColor = showBorder ? [[UINavigationBarAppearance new] shadowColor] : nil;
  43. self.getAppearance.shadowColor = shadowColor;
  44. }
  45. - (void)setBackIndicatorImage:(UIImage *)image withColor:(UIColor *)color {
  46. [self.getAppearance 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. self.getAppearance.titleTextAttributes = [RNNFontAttributesCreator createFromDictionary:self.getAppearance.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. self.getAppearance.largeTitleTextAttributes = [RNNFontAttributesCreator createFromDictionary:self.getAppearance.largeTitleTextAttributes fontFamily:fontFamily fontSize:fontSize defaultFontSize:nil fontWeight:fontWeight color:fontColor defaultColor:nil];
  61. }
  62. - (UINavigationBarAppearance *)getAppearance {
  63. return self.currentNavigationItem.standardAppearance;
  64. }
  65. - (UINavigationBarAppearance *)getScrollEdgeAppearance {
  66. return self.currentNavigationItem.scrollEdgeAppearance;
  67. }
  68. @end