Skip to content

Commit

Permalink
[AppBar] Remove unnecessary logic in setContentViewController:
Browse files Browse the repository at this point in the history
Summary: Closes https://github.com/google/material-components-ios/issues/287.

Reviewers: #mdc_ios_owners, ajsecord

Reviewed By: #mdc_ios_owners, ajsecord

Projects: #material_components_ios

Differential Revision: http://codereview.cc/D490
  • Loading branch information
jverkoey committed Apr 5, 2016
1 parent c5cf080 commit e0aca65
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
11 changes: 5 additions & 6 deletions components/AppBar/src/MDCAppBarContainerViewController.m
Expand Up @@ -98,13 +98,12 @@ - (void)setContentViewController:(UIViewController *)contentViewController {
_contentViewController = contentViewController;

[self addChildViewController:contentViewController];
if ([self isViewLoaded]) {
[self.view insertSubview:contentViewController.view
belowSubview:self.appBar.headerViewController.headerView];
[contentViewController didMoveToParentViewController:self];

[_appBar.navigationBar observeNavigationItem:_contentViewController.navigationItem];
}
NSAssert(![self isViewLoaded],
@"View should not have been loaded at this point."
@" Verify that the view is not being accessed anywhere in %@ or %@.",
NSStringFromSelector(_cmd),
NSStringFromSelector(@selector(initWithContentViewController:)));
}

@end
37 changes: 37 additions & 0 deletions components/AppBar/tests/unit/AppBarContainerIssue287Tests.swift
@@ -0,0 +1,37 @@
/*
Copyright 2016-present Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import XCTest
import MaterialComponents

// Tests confirming that MDCAppBarContainerViewController doesn't loads its own view during
// initialization.
//
// Based on issue https://github.com/google/material-components-ios/issues/287
class AppBarContainerIssue287Tests: XCTestCase {

var content: UIViewController!
var container: MDCAppBarContainerViewController!

override func setUp() {
content = UIViewController()
container = MDCAppBarContainerViewController(contentViewController: content)
}

func testViewHasNotLoadedAfterInitialization() {
XCTAssertFalse(container.isViewLoaded())
}
}

0 comments on commit e0aca65

Please sign in to comment.