<commit_before>// Copyright 2019-present the Material Components for iOS authors. 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 UIKit

import MaterialComponents.MaterialBanner
import MaterialComponents.MaterialBanner_Theming
import MaterialComponents.MaterialButtons
import MaterialComponents.MaterialButtons_Theming
import MaterialComponents.MaterialColorScheme
import MaterialComponents.MaterialContainerScheme

class BannerAutoLayoutSwiftExampleViewController: UIViewController {
  lazy var containerScheme: MDCContainerScheming = MDCContainerScheme()
  var bannerView = MDCBannerView()
  var showBannerButton = MDCButton()

  override func viewDidLoad() {
    super.viewDidLoad()

    view.backgroundColor = containerScheme.colorScheme.backgroundColor
    showBannerButton.translatesAutoresizingMaskIntoConstraints = false
    showBannerButton.applyTextTheme(withScheme: containerScheme)
    showBannerButton.setTitle("Material Banner", for: .normal)
    showBannerButton.addTarget(self, action: #selector(self.didTapShowBannerButton), for: .touchUpInside)
    view.addSubview(showBannerButton)
    showBannerButton.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
    showBannerButton.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true

    bannerView.translatesAutoresizingMaskIntoConstraints = false
    bannerView.textView.text = "Lorem ipsum dolor"
    bannerView.trailingButton.isHidden = true
    bannerView.showsDivider = true
    bannerView.layoutMargins = .zero
    let actionButton = bannerView.leadingButton
    actionButton.setTitle("Dismiss", for: .normal)
    actionButton.addTarget(self, action: #selector(self.didTapDismissOnBannerView), for: .touchUpInside)
    bannerView.applyTheme(withScheme: containerScheme)
    view.addSubview(bannerView)
    bannerView.isHidden = true
    if #available(iOS 11.0, *) {
      bannerView.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor).isActive = true
    } else {
      bannerView.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor).isActive = true
    }
    bannerView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
    bannerView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
  }

  @objc func didTapShowBannerButton() {
    bannerView.isHidden = false
    UIAccessibility.post(notification:.layoutChanged, argument: bannerView);
  }

  @objc func didTapDismissOnBannerView() {
    bannerView.isHidden = true
  }

}

// MARK: Catalog by Convention
extension BannerAutoLayoutSwiftExampleViewController {

  @objc class func catalogMetadata() -> [String: Any] {
    return [
      "breadcrumbs": ["Banner", "Banner (Swift)"],
      "primaryDemo": false,
      "presentable": true,
    ]
  }
}

// MARK: Snapshot Testing by Convention
extension BannerAutoLayoutSwiftExampleViewController {

  @objc func testDidTapShowBannerButton() {<commit_msg>[Banner] setNeedsLayout before showing Banner in BannerAutolayoutSwiftExampleViewController<commit_after>// Copyright 2019-present the Material Components for iOS authors. 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 UIKit
import MaterialComponents.MaterialBanner
import MaterialComponents.MaterialBanner_Theming 
import MaterialComponents.MaterialButtons
import MaterialComponents.MaterialButtons_Theming 
import MaterialComponents.MaterialColorScheme
import MaterialComponents.MaterialContainerScheme

class BannerAutoLayoutSwiftExampleViewController: UIViewController {
  lazy var containerScheme: MDCContainerScheming = MDCContainerScheme()
  var bannerView = MDCBannerView()
  var showBannerButton = MDCButton()

  override func viewDidLoad() {
    super.viewDidLoad()

    view.backgroundColor = containerScheme.colorScheme.backgroundColor
    showBannerButton.translatesAutoresizingMaskIntoConstraints = false
    showBannerButton.applyTextTheme(withScheme: containerScheme)
    showBannerButton.setTitle("Material Banner", for: .normal)
    showBannerButton.addTarget(
      self, action: #selector(self.didTapShowBannerButton), for: .touchUpInside)
    view.addSubview(showBannerButton)
    showBannerButton.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
    showBannerButton.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true

    bannerView.translatesAutoresizingMaskIntoConstraints = false
    bannerView.textView.text = "Lorem ipsum dolor"
    bannerView.trailingButton.isHidden = true
    bannerView.showsDivider = true
    bannerView.layoutMargins = .zero
    let actionButton = bannerView.leadingButton
    actionButton.setTitle("Dismiss", for: .normal)
    actionButton.addTarget(
      self, action: #selector(self.didTapDismissOnBannerView), for: .touchUpInside)
    bannerView.applyTheme(withScheme: containerScheme)
    view.addSubview(bannerView)
    bannerView.isHidden = true
    if #available(iOS 11.0, *) {
      bannerView.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor).isActive = true
    } else {
      bannerView.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor).isActive = true
    }
    bannerView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
    bannerView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
  }

  @objc func didTapShowBannerButton() {
    bannerView.isHidden = false
    bannerView.setNeedsLayout()
    UIAccessibility.post(notification: .layoutChanged, argument: bannerView)
  }

  @objc func didTapDismissOnBannerView() {
    bannerView.isHidden = true
  }

}

// MARK: Catalog by Convention
extension BannerAutoLayoutSwiftExampleViewController {

  @objc class func catalogMetadata() -> [String: Any] {
    return [
      "breadcrumbs": ["Banner", "Banner (Swift)"],
      "primaryDemo": false,
      "presentable": true,
    ]
  }
}

// MARK: Snapshot Testing by Convention
extension BannerAutoLayoutSwiftExampleViewController {

  @objc func testDidTapShowBannerButton() {
{'fraction_non_alphanumeric': 0.08270355054898046, 'fraction_numerical': 0.0031370312277199486, 'mean_word_length': 4.8498748957464555, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7323277', 'n_tokens_mistral': 2001, 'n_tokens_neox': 1936, 'n_words': 474}