react-native-navigation的迁移库

RNNTopTabsViewController.m 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #import "RNNTopTabsViewController.h"
  2. #import "RNNSegmentedControl.h"
  3. #import "ReactNativeNavigation.h"
  4. #import "RNNRootViewController.h"
  5. #import "UIViewController+LayoutProtocol.h"
  6. @interface RNNTopTabsViewController () {
  7. NSArray* _viewControllers;
  8. UIViewController* _currentViewController;
  9. RNNSegmentedControl* _segmentedControl;
  10. }
  11. @end
  12. @implementation RNNTopTabsViewController
  13. - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo childViewControllers:(NSArray *)childViewControllers options:(RNNNavigationOptions *)options defaultOptions:(RNNNavigationOptions *)defaultOptions presenter:(RNNViewControllerPresenter *)presenter {
  14. self = [self init];
  15. self.presenter = presenter;
  16. [self.presenter bindViewController:self];
  17. self.defaultOptions = defaultOptions;
  18. self.options = options;
  19. self.layoutInfo = layoutInfo;
  20. [self setViewControllers:childViewControllers];
  21. return self;
  22. }
  23. - (instancetype)init {
  24. self = [super init];
  25. [self.view setBackgroundColor:[UIColor whiteColor]];
  26. self.edgesForExtendedLayout = UIRectEdgeNone;
  27. [self createTabBar];
  28. [self createContentView];
  29. return self;
  30. }
  31. - (UIViewController *)getCurrentChild {
  32. return _currentViewController;
  33. }
  34. - (void)createTabBar {
  35. _segmentedControl = [[RNNSegmentedControl alloc] initWithSectionTitles:@[@"", @"", @""]];
  36. _segmentedControl.frame = CGRectMake(0, 0, self.view.bounds.size.width, 50);
  37. _segmentedControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationNone;
  38. _segmentedControl.selectionStyle = HMSegmentedControlSelectionStyleBox;
  39. _segmentedControl.selectedSegmentIndex = HMSegmentedControlNoSegment;
  40. [_segmentedControl addTarget:self action:@selector(segmentedControlChangedValue:) forControlEvents:UIControlEventValueChanged];
  41. [self.view addSubview:_segmentedControl];
  42. }
  43. - (void)segmentedControlChangedValue:(HMSegmentedControl*)segmentedControl {
  44. [self setSelectedViewControllerIndex:segmentedControl.selectedSegmentIndex];
  45. }
  46. - (void)createContentView {
  47. _contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, self.view.bounds.size.width, self.view.bounds.size.height - 50)];
  48. _contentView.backgroundColor = [UIColor grayColor];
  49. [self.view addSubview:_contentView];
  50. }
  51. - (void)setSelectedViewControllerIndex:(NSUInteger)index {
  52. UIViewController *toVC = _viewControllers[index];
  53. [_contentView addSubview:toVC.view];
  54. [_currentViewController.view removeFromSuperview];
  55. _currentViewController = toVC;
  56. }
  57. - (void)setViewControllers:(NSArray *)viewControllers {
  58. _viewControllers = viewControllers;
  59. for (RNNRootViewController* childVc in viewControllers) {
  60. [childVc.view setFrame:_contentView.bounds];
  61. // [childVc.options.topTab applyOn:childVc];
  62. [self addChildViewController:childVc];
  63. }
  64. [self setSelectedViewControllerIndex:0];
  65. }
  66. - (void)viewController:(UIViewController*)vc changedTitle:(NSString*)title {
  67. NSUInteger vcIndex = [_viewControllers indexOfObject:vc];
  68. [_segmentedControl setTitle:title atIndex:vcIndex];
  69. }
  70. - (void)viewDidLoad {
  71. [super viewDidLoad];
  72. }
  73. @end