Skip to content

Commit

Permalink
[AppBar] Clarify the purpose of the example supplemental view control…
Browse files Browse the repository at this point in the history
…lers.

The prior names of composed vs inherited didn't meaningfully translate to the intended purpose of the two view controllers, which is to provide harnesses within which the flexible header can be placed either as a child or as a sibling to its tracking scroll view. This distinction is important because the flexible header behaves differently when it is a child of its tracking scroll view, as is the case when using UITableViewController.

PiperOrigin-RevId: 310869953
  • Loading branch information
Jeff Verkoeyen authored and material-automation committed May 11, 2020
1 parent 783c9de commit 580a1ec
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 29 deletions.
10 changes: 5 additions & 5 deletions components/AppBar/examples/AppBarAnimatedGlitchExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class AppBarAnimatedJumpExample: UIViewController {
@objc var containerScheme: MDCContainerScheming = MDCContainerScheme()

fileprivate let tabs = [
SimpleComposedTableViewController(title: "First"),
SimpleComposedTableViewController(title: "Second"),
SimpleComposedTableViewController(title: "Third"),
SiblingOfTrackingScrollViewViewController(title: "First"),
SiblingOfTrackingScrollViewViewController(title: "Second"),
SiblingOfTrackingScrollViewViewController(title: "Third"),
]
private var currentTab: SimpleComposedTableViewController? = nil
private var currentTab: SiblingOfTrackingScrollViewViewController? = nil

lazy var tabBar: MDCTabBar = {
let tabBar = MDCTabBar()
Expand Down Expand Up @@ -73,7 +73,7 @@ class AppBarAnimatedJumpExample: UIViewController {
switchToTab(tabs[0], animated: false)
}

fileprivate func switchToTab(_ tab: SimpleComposedTableViewController, animated: Bool = true) {
fileprivate func switchToTab(_ tab: SiblingOfTrackingScrollViewViewController, animated: Bool = true) {

appBarViewController.headerView.trackingScrollWillChange(toScroll: tab.tableView)

Expand Down
8 changes: 4 additions & 4 deletions components/AppBar/examples/AppBarGlitchExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class AppBarJumpExample: UIViewController {
lazy var appBarViewController: MDCAppBarViewController = self.makeAppBar()
@objc var containerScheme: MDCContainerScheming = MDCContainerScheme()

fileprivate let firstTab = SimpleComposedTableViewController()
fileprivate let secondTab = SimpleComposedTableViewController()
private var currentTab: SimpleComposedTableViewController? = nil
fileprivate let firstTab = SiblingOfTrackingScrollViewViewController()
fileprivate let secondTab = SiblingOfTrackingScrollViewViewController()
private var currentTab: SiblingOfTrackingScrollViewViewController? = nil

lazy var tabBar: MDCTabBar = {
let tabBar = MDCTabBar()
Expand Down Expand Up @@ -69,7 +69,7 @@ class AppBarJumpExample: UIViewController {
switchToTab(firstTab)
}

fileprivate func switchToTab(_ tab: SimpleComposedTableViewController) {
fileprivate func switchToTab(_ tab: SiblingOfTrackingScrollViewViewController) {

appBarViewController.headerView.trackingScrollWillChange(toScroll: tab.tableView)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class AppBarInheritedAnimatedJumpExample: UIViewController {
@objc var containerScheme: MDCContainerScheming = MDCContainerScheme()

fileprivate let tabs = [
SimpleInheritedTableViewController(title: "First"),
SimpleInheritedTableViewController(title: "Second"),
SimpleInheritedTableViewController(title: "Third"),
ChildOfTrackingScrollViewViewController(title: "First"),
ChildOfTrackingScrollViewViewController(title: "Second"),
ChildOfTrackingScrollViewViewController(title: "Third"),
]
private var currentTab: SimpleInheritedTableViewController? = nil
private var currentTab: ChildOfTrackingScrollViewViewController? = nil

lazy var tabBar: MDCTabBar = {
let tabBar = MDCTabBar()
Expand Down Expand Up @@ -73,7 +73,7 @@ class AppBarInheritedAnimatedJumpExample: UIViewController {
switchToTab(tabs[0], animated: false)
}

fileprivate func switchToTab(_ tab: SimpleInheritedTableViewController, animated: Bool = true) {
fileprivate func switchToTab(_ tab: ChildOfTrackingScrollViewViewController, animated: Bool = true) {

appBarViewController.headerView.trackingScrollWillChange(toScroll: tab.tableView)

Expand Down
8 changes: 4 additions & 4 deletions components/AppBar/examples/AppBarManualTabsExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class AppBarManualTabsExample: UIViewController {
lazy var appBarViewController: MDCAppBarViewController = self.makeAppBar()
@objc var containerScheme: MDCContainerScheming = MDCContainerScheme()

fileprivate let firstTab = SimpleInheritedTableViewController()
fileprivate let secondTab = SimpleInheritedTableViewController()
private var currentTab: SimpleInheritedTableViewController? = nil
fileprivate let firstTab = ChildOfTrackingScrollViewViewController()
fileprivate let secondTab = ChildOfTrackingScrollViewViewController()
private var currentTab: ChildOfTrackingScrollViewViewController? = nil

lazy var tabBar: MDCTabBar = {
let tabBar = MDCTabBar()
Expand Down Expand Up @@ -73,7 +73,7 @@ class AppBarManualTabsExample: UIViewController {
switchToTab(firstTab)
}

fileprivate func switchToTab(_ tab: SimpleInheritedTableViewController) {
fileprivate func switchToTab(_ tab: ChildOfTrackingScrollViewViewController) {
appBarViewController.headerView.trackingScrollWillChange(toScroll: tab.tableView)

if let currentTab = currentTab {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
import UIKit
import MaterialComponents.MaterialFlexibleHeader

/// A table view controller which inherits directly from UITableViewController.
/// A table view controller that subclasses UITableViewController.
///
/// This intentionally sets things up such that its view is a subclass of UIScrollView, which is
/// handled specially by some components.
class SimpleInheritedTableViewController: UITableViewController {
/// The purpose of this view controller is to demonstrate how the flexible header view interacts
/// with view controllers whose self.view *is* the tracking scroll view. In cases like these, the
/// flexible header view often needs to be added as a subview of the tracking scroll view.
class ChildOfTrackingScrollViewViewController: UITableViewController {

init(title: String? = nil) {
super.init(nibName: nil, bundle: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
import UIKit
import MaterialComponents.MaterialFlexibleHeader

/// A simple table view controller which is manually composed.
/// A table view controller that adds a UITableView as a child of its view.
///
/// This view controller is meaningfully *not* a subclass of UITableViewController and its view is
/// not a UIScrollView subclass. This avoids logic which might attempt to be smart by detecting
/// these cases.
class SimpleComposedTableViewController: UIViewController {
/// The purpose of this view controller is to demonstrate how the flexible header view interacts
/// with view controllers whose self.view is *not* the tracking scroll view. In cases like these,
/// the flexible header view can be added as a sibling to the tracking scroll view.
class SiblingOfTrackingScrollViewViewController: UIViewController {

init(title: String? = nil) {
super.init(nibName: nil, bundle: nil)
Expand Down Expand Up @@ -50,7 +50,7 @@ class SimpleComposedTableViewController: UIViewController {
}
}

extension SimpleComposedTableViewController: UITableViewDataSource {
extension SiblingOfTrackingScrollViewViewController: UITableViewDataSource {

func numberOfSections(in tableView: UITableView) -> Int {
return 1
Expand All @@ -61,7 +61,7 @@ extension SimpleComposedTableViewController: UITableViewDataSource {
}
}

extension SimpleComposedTableViewController: UITableViewDelegate {
extension SiblingOfTrackingScrollViewViewController: UITableViewDelegate {

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
Expand Down

0 comments on commit 580a1ec

Please sign in to comment.