react-native-navigation的迁移库

RNNTopTabsViewController.m 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #import "RNNTopTabsViewController.h"
  2. #import "RNNSegmentedControl.h"
  3. #import "ReactNativeNavigation.h"
  4. #import "RNNComponentViewController.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)init {
  14. self = [super init];
  15. [self.view setBackgroundColor:[UIColor whiteColor]];
  16. self.edgesForExtendedLayout = UIRectEdgeNone;
  17. [self createTabBar];
  18. [self createContentView];
  19. return self;
  20. }
  21. - (UIViewController *)getCurrentChild {
  22. return _currentViewController;
  23. }
  24. - (void)createTabBar {
  25. _segmentedControl = [[RNNSegmentedControl alloc] initWithSectionTitles:@[@"", @"", @""]];
  26. _segmentedControl.frame = CGRectMake(0, 0, self.view.bounds.size.width, 50);
  27. _segmentedControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationNone;
  28. _segmentedControl.selectionStyle = HMSegmentedControlSelectionStyleBox;
  29. _segmentedControl.selectedSegmentIndex = HMSegmentedControlNoSegment;
  30. [_segmentedControl addTarget:self action:@selector(segmentedControlChangedValue:) forControlEvents:UIControlEventValueChanged];
  31. [self.view addSubview:_segmentedControl];
  32. }
  33. - (void)segmentedControlChangedValue:(HMSegmentedControl*)segmentedControl {
  34. [self setSelectedViewControllerIndex:segmentedControl.selectedSegmentIndex];
  35. }
  36. - (void)createContentView {
  37. _contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, self.view.bounds.size.width, self.view.bounds.size.height - 50)];
  38. _contentView.backgroundColor = [UIColor grayColor];
  39. [self.view addSubview:_contentView];
  40. }
  41. - (void)setSelectedViewControllerIndex:(NSUInteger)index {
  42. UIViewController *toVC = _viewControllers[index];
  43. [_contentView addSubview:toVC.view];
  44. [_currentViewController.view removeFromSuperview];
  45. _currentViewController = toVC;
  46. }
  47. - (void)setViewControllers:(NSArray *)viewControllers {
  48. _viewControllers = viewControllers;
  49. for (RNNComponentViewController* childVc in viewControllers) {
  50. [childVc.view setFrame:_contentView.bounds];
  51. // [childVc.options.topTab applyOn:childVc];
  52. [self addChildViewController:childVc];
  53. }
  54. [self setSelectedViewControllerIndex:0];
  55. }
  56. - (void)viewController:(UIViewController*)vc changedTitle:(NSString*)title {
  57. NSUInteger vcIndex = [_viewControllers indexOfObject:vc];
  58. [_segmentedControl setTitle:title atIndex:vcIndex];
  59. }
  60. - (void)viewDidLoad {
  61. [super viewDidLoad];
  62. }
  63. @end