react-native-navigation的迁移库

RNNNavigationOptions.m 3.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #import "RNNNavigationOptions.h"
  2. #import <React/RCTConvert.h>
  3. #import "RNNNavigationController.h"
  4. #import "RNNTabBarController.h"
  5. #import "RNNTopBarOptions.h"
  6. #import "RNNSideMenuController.h"
  7. #import "RNNRootViewController.h"
  8. #import "RNNSplitViewController.h"
  9. #import "RNNNavigationButtons.h"
  10. @implementation RNNNavigationOptions
  11. - (RNNNavigationOptions *)combineWithOptions:(RNNOptions *)options {
  12. RNNNavigationOptions *navigationOptions = [[RNNNavigationOptions alloc] initWithDict:@{}];
  13. [navigationOptions mergeOptions:self overrideOptions:YES];
  14. [navigationOptions mergeOptions:options overrideOptions:YES];
  15. return navigationOptions;
  16. }
  17. - (void)applyOn:(UIViewController *)viewController {
  18. [self.topBar applyOn:viewController];
  19. [self.bottomTabs applyOn:viewController];
  20. [self.topTab applyOn:viewController];
  21. [self.bottomTab applyOn:viewController];
  22. [self.sideMenu applyOn:viewController];
  23. [self.overlay applyOn:viewController];
  24. [self.statusBar applyOn:viewController];
  25. [self.layout applyOn:viewController];
  26. [self applyOtherOptions:self on:viewController];
  27. }
  28. - (void)applyOnNavigationController:(UINavigationController *)navigationController {
  29. [self.topBar applyOnNavigationController:navigationController];
  30. [self.statusBar applyOn:navigationController];
  31. [self.layout applyOn:navigationController];
  32. [self.bottomTab applyOn:navigationController];
  33. [self applyOtherOptions:self onNavigationController:navigationController];
  34. }
  35. - (void)applyOnTabBarController:(UITabBarController *)tabBarController {
  36. [self.bottomTabs applyOnTabBarController:tabBarController];
  37. }
  38. - (void)applyOtherOptions:(RNNNavigationOptions *)options onNavigationController:(UINavigationController*)navigationController {
  39. if (options.popGesture) {
  40. navigationController.interactivePopGestureRecognizer.enabled = [options.popGesture boolValue];
  41. }
  42. if (options.rootBackgroundImage) {
  43. UIImageView* backgroundImageView = (navigationController.view.subviews.count > 0) ? navigationController.view.subviews[0] : nil;
  44. if (![backgroundImageView isKindOfClass:[UIImageView class]]) {
  45. backgroundImageView = [[UIImageView alloc] initWithFrame:navigationController.view.bounds];
  46. [navigationController.view insertSubview:backgroundImageView atIndex:0];
  47. }
  48. backgroundImageView.layer.masksToBounds = YES;
  49. backgroundImageView.image = [options.rootBackgroundImage isKindOfClass:[UIImage class]] ? (UIImage*)options.rootBackgroundImage : [RCTConvert UIImage:options.rootBackgroundImage];
  50. [backgroundImageView setContentMode:UIViewContentModeScaleAspectFill];
  51. }
  52. }
  53. - (void)applyOtherOptions:(RNNNavigationOptions *)options on:(UIViewController*)viewController {
  54. if (options.backgroundImage) {
  55. UIImageView* backgroundImageView = (viewController.view.subviews.count > 0) ? viewController.view.subviews[0] : nil;
  56. if (![backgroundImageView isKindOfClass:[UIImageView class]]) {
  57. backgroundImageView = [[UIImageView alloc] initWithFrame:viewController.view.bounds];
  58. [viewController.view insertSubview:backgroundImageView atIndex:0];
  59. }
  60. backgroundImageView.layer.masksToBounds = YES;
  61. backgroundImageView.image = [options.backgroundImage isKindOfClass:[UIImage class]] ? (UIImage*)options.backgroundImage : [RCTConvert UIImage:options.backgroundImage];
  62. [backgroundImageView setContentMode:UIViewContentModeScaleAspectFill];
  63. }
  64. if (options.modalPresentationStyle) {
  65. viewController.modalPresentationStyle = [RCTConvert UIModalPresentationStyle:options.modalPresentationStyle];
  66. [viewController.view setBackgroundColor:[UIColor clearColor]];
  67. }
  68. if (options.modalTransitionStyle) {
  69. viewController.modalTransitionStyle = [RCTConvert UIModalTransitionStyle:options.modalTransitionStyle];
  70. }
  71. }
  72. @end