material-components_materia.../components/Dialogs/examples/DialogsWithEmphasisButtonExampleViewController.swift
Cody Weaver 50307bb330
[Container] Fix colorScheme and typographyScheme to be nonnull. (#6699)
## Introduction
Before we move container scheme to ready we need to have both the `colorScheme` and `typographyScheme` nonnull. By making colorScheme and typographyScheme of MDCContainerScheming nonnull, clients will reduce the amount of conditional checks required in their apps and reduce a category of potential errors (accidentally passing nil to a nonnull parameter).

## The problem
Both `colorScheme` and `typographyScheme` were nullable in the container scheme making it harder for clients to use the container scheme throughout their app on non Material UIElements, i.e. UIView.backgroundColor

## The fix
Make both of these properties nonnull.

## Additional work
- [x]  I had to update the swift examples to not be optional and I additionally removed the nil checks from the ObjC examples.
2019-02-27 15:47:26 -05:00

86 lines
3.2 KiB
Swift

// 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.MaterialButtons
import MaterialComponents.MaterialDialogs
import MaterialComponentsBeta.MaterialButtons_Theming
import MaterialComponentsBeta.MaterialContainerScheme
import MaterialComponentsBeta.MaterialDialogs_Theming
class DialogsWithEmphasisButtonExampleViewController: UIViewController {
private let materialButton = MDCButton()
var containerScheme = MDCContainerScheme()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = containerScheme.colorScheme.backgroundColor
materialButton.translatesAutoresizingMaskIntoConstraints = false
materialButton.setTitle("Material Alert With Emphasis Buttons", for: .normal)
materialButton.sizeToFit()
materialButton.addTarget(self, action: #selector(tapMaterial), for: .touchUpInside)
materialButton.applyTextTheme(withScheme: containerScheme)
self.view.addSubview(materialButton)
NSLayoutConstraint.activate([
NSLayoutConstraint(item:materialButton,
attribute: .centerX,
relatedBy: .equal,
toItem: self.view,
attribute: .centerX,
multiplier: 1.0,
constant: 0.0),
NSLayoutConstraint(item: materialButton,
attribute: .centerY,
relatedBy: .equal,
toItem: self.view,
attribute: .centerY,
multiplier: 1.0,
constant: 0.0)
])
}
@objc func tapMaterial(_ sender: Any) {
let title = "Reset Settings?"
let message = "This will reset your device to its default factory settings."
let alertController = MDCAlertController(title: title, message: message)
let mediumEmphasisAction = MDCAlertAction(title: "Cancel", emphasis: .medium, handler: nil)
mediumEmphasisAction.accessibilityIdentifier = "Cancel"
let highEmphasisAction = MDCAlertAction(title: "Accept", emphasis: .high, handler: nil)
highEmphasisAction.accessibilityIdentifier = "Accept"
alertController.addAction(mediumEmphasisAction)
alertController.addAction(highEmphasisAction)
alertController.applyTheme(withScheme: containerScheme)
present(alertController, animated: true, completion: nil)
}
}
extension DialogsWithEmphasisButtonExampleViewController {
class func catalogMetadata() -> [String: Any] {
return [
"breadcrumbs": ["Dialogs", "Dialog with Themed Emphasis Buttons"],
"primaryDemo": false,
"presentable": true,
]
}
}