react-native-navigation的迁移库

RNNNavigationControllerPresenter.m 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #import "RNNNavigationControllerPresenter.h"
  2. #import "UINavigationController+RNNOptions.h"
  3. #import "RNNNavigationController.h"
  4. #import <React/RCTConvert.h>
  5. @implementation RNNNavigationControllerPresenter
  6. - (void)applyOptions:(RNNNavigationOptions *)initialOptions {
  7. [super applyOptions:initialOptions];
  8. RNNNavigationOptions* options = [initialOptions withDefault:self.defaultOptions];
  9. RNNNavigationController* navigationController = self.bindedViewController;
  10. [navigationController rnn_setInteractivePopGestureEnabled:[options.popGesture getWithDefaultValue:YES]];
  11. [navigationController rnn_setRootBackgroundImage:[options.rootBackgroundImage getWithDefaultValue:nil]];
  12. [navigationController rnn_setNavigationBarTestID:[options.topBar.testID getWithDefaultValue:nil]];
  13. [navigationController rnn_setNavigationBarVisible:[options.topBar.visible getWithDefaultValue:YES] animated:[options.topBar.animate getWithDefaultValue:YES]];
  14. [navigationController rnn_hideBarsOnScroll:[options.topBar.hideOnScroll getWithDefaultValue:NO]];
  15. [navigationController rnn_setNavigationBarNoBorder:[options.topBar.noBorder getWithDefaultValue:NO]];
  16. [navigationController rnn_setBarStyle:[RCTConvert UIBarStyle:[options.topBar.barStyle getWithDefaultValue:@"default"]]];
  17. [navigationController rnn_setNavigationBarTranslucent:[options.topBar.background.translucent getWithDefaultValue:NO]];
  18. [navigationController rnn_setNavigationBarClipsToBounds:[options.topBar.background.clipToBounds getWithDefaultValue:NO]];
  19. [navigationController rnn_setNavigationBarBlur:[options.topBar.background.blur getWithDefaultValue:NO]];
  20. [navigationController setTopBarBackgroundColor:[options.topBar.background.color getWithDefaultValue:nil]];
  21. [navigationController rnn_setNavigationBarLargeTitleVisible:[options.topBar.largeTitle.visible getWithDefaultValue:NO]];
  22. [navigationController rnn_setNavigationBarLargeTitleFontFamily:[options.topBar.largeTitle.fontFamily getWithDefaultValue:nil] fontSize:[options.topBar.largeTitle.fontSize getWithDefaultValue:nil] color:[options.topBar.largeTitle.color getWithDefaultValue:nil]];
  23. [navigationController rnn_setNavigationBarFontFamily:[options.topBar.title.fontFamily getWithDefaultValue:nil] fontSize:[options.topBar.title.fontSize getWithDefaultValue:nil] color:[options.topBar.title.color getWithDefaultValue:nil]];
  24. [navigationController rnn_setBackButtonColor:[options.topBar.backButton.color getWithDefaultValue:nil]];
  25. [navigationController rnn_setBackButtonIcon:[options.topBar.backButton.icon getWithDefaultValue:nil] withColor:[options.topBar.backButton.color getWithDefaultValue:nil] title:[options.topBar.backButton.showTitle getWithDefaultValue:YES] ? [options.topBar.backButton.title getWithDefaultValue:nil] : @""];
  26. }
  27. - (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options {
  28. [super applyOptionsOnWillMoveToParentViewController:options];
  29. RNNNavigationController* navigationController = self.bindedViewController;
  30. [navigationController rnn_setBackButtonIcon:[options.topBar.backButton.icon getWithDefaultValue:nil] withColor:[options.topBar.backButton.color getWithDefaultValue:nil] title:[options.topBar.backButton.showTitle getWithDefaultValue:YES] ? [options.topBar.backButton.title getWithDefaultValue:nil] : @""];
  31. }
  32. - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)resolvedOptions {
  33. [super mergeOptions:options resolvedOptions:resolvedOptions];
  34. RNNNavigationController* navigationController = self.bindedViewController;
  35. RNNNavigationOptions* withDefault = (RNNNavigationOptions *)[options withDefault:self.defaultOptions];
  36. if (options.popGesture.hasValue) {
  37. [navigationController rnn_setInteractivePopGestureEnabled:withDefault.popGesture.get];
  38. }
  39. if (options.rootBackgroundImage.hasValue) {
  40. [navigationController rnn_setRootBackgroundImage:withDefault.rootBackgroundImage.get];
  41. }
  42. if (options.topBar.testID.hasValue) {
  43. [navigationController rnn_setNavigationBarTestID:withDefault.topBar.testID.get];
  44. }
  45. if (options.topBar.visible.hasValue) {
  46. [navigationController rnn_setNavigationBarVisible:withDefault.topBar.visible.get animated:[withDefault.topBar.animate getWithDefaultValue:YES]];
  47. }
  48. if (options.topBar.hideOnScroll.hasValue) {
  49. [navigationController rnn_hideBarsOnScroll:[withDefault.topBar.hideOnScroll get]];
  50. }
  51. if (options.topBar.noBorder.hasValue) {
  52. [navigationController rnn_setNavigationBarNoBorder:[withDefault.topBar.noBorder get]];
  53. }
  54. if (options.topBar.barStyle.hasValue) {
  55. [navigationController rnn_setBarStyle:[RCTConvert UIBarStyle:withDefault.topBar.barStyle.get]];
  56. }
  57. if (options.topBar.background.translucent.hasValue) {
  58. [navigationController rnn_setNavigationBarTranslucent:[withDefault.topBar.background.translucent get]];
  59. }
  60. if (options.topBar.background.clipToBounds.hasValue) {
  61. [navigationController rnn_setNavigationBarClipsToBounds:[withDefault.topBar.background.clipToBounds get]];
  62. }
  63. if (options.topBar.background.blur.hasValue) {
  64. [navigationController rnn_setNavigationBarBlur:[withDefault.topBar.background.blur get]];
  65. }
  66. if (options.topBar.background.color.hasValue) {
  67. [navigationController setTopBarBackgroundColor:withDefault.topBar.background.color.get];
  68. }
  69. if (options.topBar.largeTitle.visible.hasValue) {
  70. [navigationController rnn_setNavigationBarLargeTitleVisible:withDefault.topBar.largeTitle.visible.get];
  71. }
  72. if (options.topBar.backButton.icon.hasValue) {
  73. [navigationController rnn_setBackButtonIcon:[withDefault.topBar.backButton.icon getWithDefaultValue:nil] withColor:[withDefault.topBar.backButton.color getWithDefaultValue:nil] title:[withDefault.topBar.backButton.showTitle getWithDefaultValue:YES] ? [withDefault.topBar.backButton.title getWithDefaultValue:nil] : @""];
  74. }
  75. if (options.topBar.backButton.color.hasValue) {
  76. [navigationController rnn_setBackButtonColor:options.topBar.backButton.color.get];
  77. }
  78. [navigationController rnn_setNavigationBarLargeTitleFontFamily:[withDefault.topBar.largeTitle.fontFamily getWithDefaultValue:nil] fontSize:[withDefault.topBar.largeTitle.fontSize getWithDefaultValue:nil] color:[withDefault.topBar.largeTitle.color getWithDefaultValue:nil]];
  79. [navigationController rnn_setNavigationBarFontFamily:[withDefault.topBar.title.fontFamily getWithDefaultValue:nil] fontSize:[withDefault.topBar.title.fontSize getWithDefaultValue:nil] color:[withDefault.topBar.title.color getWithDefaultValue:nil]];
  80. }
  81. @end