Ported TabBarIOS to OSS and unified implementation

This commit is contained in:
Nick Lockwood
2015-03-05 17:16:19 -08:00
parent ab2537816f
commit fb2f063ef5
51 changed files with 1142 additions and 472 deletions
+64 -45
View File
@@ -2,22 +2,30 @@
#import "RCTWrapperViewController.h"
#import <UIKit/UIScrollView.h>
#import "RCTEventDispatcher.h"
#import "RCTNavItem.h"
#import "RCTUtils.h"
#import "RCTViewControllerProtocol.h"
#import "UIView+ReactKit.h"
@implementation RCTWrapperViewController
{
UIView *_wrapperView;
UIView *_contentView;
RCTEventDispatcher *_eventDispatcher;
CGFloat _previousTopLayout;
CGFloat _previousBottomLayout;
}
- (instancetype)initWithContentView:(UIView *)contentView eventDispatcher:(RCTEventDispatcher *)eventDispatcher
@synthesize currentTopLayoutGuide = _currentTopLayoutGuide;
@synthesize currentBottomLayoutGuide = _currentBottomLayoutGuide;
- (instancetype)initWithContentView:(UIView *)contentView
eventDispatcher:(RCTEventDispatcher *)eventDispatcher
{
if ((self = [super initWithNibName:nil bundle:nil])) {
if (self = [super initWithNibName:nil bundle:nil]) {
_contentView = contentView;
_eventDispatcher = eventDispatcher;
self.automaticallyAdjustsScrollViewInsets = NO;
@@ -25,80 +33,91 @@
return self;
}
- (instancetype)initWithNavItem:(RCTNavItem *)navItem eventDispatcher:(RCTEventDispatcher *)eventDispatcher
- (instancetype)initWithNavItem:(RCTNavItem *)navItem
eventDispatcher:(RCTEventDispatcher *)eventDispatcher
{
if ((self = [self initWithContentView:navItem eventDispatcher:eventDispatcher])) {
if (self = [self initWithContentView:navItem eventDispatcher:eventDispatcher]) {
_navItem = navItem;
}
return self;
}
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
_currentTopLayoutGuide = self.topLayoutGuide;
_currentBottomLayoutGuide = self.bottomLayoutGuide;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:!_navItem animated:animated];
if (!_navItem) {
return;
}
// TODO: find a way to make this less-tightly coupled to navigation controller
if ([self.parentViewController isKindOfClass:[UINavigationController class]])
{
self.navigationItem.title = _navItem.title;
[self.navigationController setNavigationBarHidden:!_navItem animated:animated];
if (!_navItem) {
return;
}
[self _configureNavBarStyle];
self.navigationItem.title = _navItem.title;
if (_navItem.rightButtonTitle.length > 0) {
self.navigationItem.rightBarButtonItem =
UINavigationBar *bar = self.navigationController.navigationBar;
if (_navItem.barTintColor) {
bar.barTintColor = _navItem.barTintColor;
}
if (_navItem.tintColor) {
BOOL canSetTintColor = _navItem.barTintColor == nil;
if (canSetTintColor) {
bar.tintColor = _navItem.tintColor;
}
}
if (_navItem.titleTextColor) {
[bar setTitleTextAttributes:@{NSForegroundColorAttributeName : _navItem.titleTextColor}];
}
if (_navItem.rightButtonTitle.length > 0) {
self.navigationItem.rightBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:_navItem.rightButtonTitle
style:UIBarButtonItemStyleDone
style:UIBarButtonItemStyleDone
target:self
action:@selector(rightButtonTapped)];
}
action:@selector(handleNavRightButtonTapped)];
}
if (_navItem.backButtonTitle.length > 0) {
self.navigationItem.backBarButtonItem =
if (_navItem.backButtonTitle.length > 0) {
self.navigationItem.backBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:_navItem.backButtonTitle
style:UIBarButtonItemStylePlain
target:nil
action:nil];
}
}
- (void)_configureNavBarStyle
{
UINavigationBar *bar = self.navigationController.navigationBar;
if (_navItem.barTintColor) {
bar.barTintColor = _navItem.barTintColor;
}
if (_navItem.tintColor) {
BOOL canSetTintColor = _navItem.barTintColor == nil;
if (canSetTintColor) {
bar.tintColor = _navItem.tintColor;
style:UIBarButtonItemStylePlain
target:nil
action:nil];
}
}
if (_navItem.titleTextColor) {
[bar setTitleTextAttributes:@{NSForegroundColorAttributeName : _navItem.titleTextColor}];
}
}
- (void)loadView
{
// Add a wrapper so that UIViewControllerWrapperView (managed by the
// add a wrapper so that UIViewControllerWrapperView (managed by the
// UINavigationController) doesn't end up resetting the frames for
// `contentView` which is a react-managed view.
self.view = [[UIView alloc] init];
[self.view addSubview:_contentView];
//`contentView` which is a react-managed view.
_wrapperView = [[UIView alloc] initWithFrame:_contentView.bounds];
[_wrapperView addSubview:_contentView];
self.view = _wrapperView;
}
- (void)rightButtonTapped
- (void)handleNavRightButtonTapped
{
[_eventDispatcher sendInputEventWithName:@"topNavRightButtonTap" body:@{@"target":_navItem.reactTag}];
[_eventDispatcher sendInputEventWithName:@"topNavRightButtonTap"
body:@{@"target":_navItem.reactTag}];
}
- (void)didMoveToParentViewController:(UIViewController *)parent
{
// There's no clear setter for navigation controllers, but did move to parent view controller
// provides the desired effect. This is called after a pop finishes, be it a swipe to go back
// or a standard tap on the back button
// There's no clear setter for navigation controllers, but did move to parent
// view controller provides the desired effect. This is called after a pop
// finishes, be it a swipe to go back or a standard tap on the back button
[super didMoveToParentViewController:parent];
if (parent == nil || [parent isKindOfClass:[UINavigationController class]]) {
[self.navigationListener wrapperViewController:self didMoveToNavigationController:(UINavigationController *)parent];