Skip to content

Commit

Permalink
Merge branch 'release-candidate' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
jverkoey committed Oct 23, 2018
2 parents d57bd27 + 5455a4f commit 3543693
Show file tree
Hide file tree
Showing 36 changed files with 840 additions and 151 deletions.
94 changes: 94 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,97 @@
# 67.2.0

This minor release introduces new functionality for theming individual buttons of an
MDCAlertController.

## New features

It is now possible to theme MDCAlertController buttons individually using the new `emphasis`
property on `MDCAlertAction` in conjunction with the `MDCAlertControllerThemer`.

```swift
let alert = MDCAlertController(title: "Button Theming", message: "High, Medium & Low Emphasis")

alert.addAction(MDCAlertAction(title:"High", emphasis: .high, handler: <#handler#>))
alert.addAction(MDCAlertAction(title:"Medium", emphasis: .medium, handler: <#handler#>))
alert.addAction(MDCAlertAction(title:"Low", emphasis: .low, handler: <#handler#>))

MDCAlertControllerThemer.applyScheme(<#alertScheme#>, to: alert)

self.present(alert, animated: true, completion: nil)
```

## API changes

### Dialogs+DialogThemer

#### MDCAlertScheming

*new* property: `buttonScheme` in `MDCAlertScheming`

#### MDCAlertScheme

*new* property: `buttonScheme` in `MDCAlertScheme`

### Dialogs

#### MDCAlertController

*modified* property: `elevation` in `MDCAlertController`

| Type of change: | Swift declaration |
|---|---|
| From: | `var elevation: CGFloat { get set }` |
| To: | `var elevation: Int32 { get set }` |

*modified* property: `elevation` in `MDCAlertController`

| Type of change: | Declaration |
|---|---|
| From: | `@property (assign, readwrite, nonatomic) CGFloat elevation;` |
| To: | `@property (assign, readwrite, nonatomic) int elevation;` |

#### MDCActionEmphasis

*new* enum: `MDCActionEmphasis`

*new* enum value: `MDCActionEmphasisLow` in `MDCActionEmphasis`

*new* enum value: `MDCActionEmphasisMedium` in `MDCActionEmphasis`

*new* enum value: `MDCActionEmphasisHigh` in `MDCActionEmphasis`

#### MDCDialogPresentationController

*modified* property: `dialogElevation` in `MDCDialogPresentationController`

| Type of change: | Swift declaration |
|---|---|
| From: | `var dialogElevation: CGFloat { get set }` |
| To: | `var dialogElevation: Int32 { get set }` |

*modified* property: `dialogElevation` in `MDCDialogPresentationController`

| Type of change: | Declaration |
|---|---|
| From: | `@property (assign, readwrite, nonatomic) CGFloat dialogElevation;` |
| To: | `@property (assign, readwrite, nonatomic) int dialogElevation;` |

#### MDCAlertAction

*new* property: `emphasis` in `MDCAlertAction`

*new* class method: `+actionWithTitle:emphasis:handler:` in `MDCAlertAction`

## Component changes

### Dialogs

* [Fix elevation to use MDCShadowElevation](https://github.com/material-components/material-components-ios/commit/c7d4f27d0c8ee7027519196480ae3e7c0f65d8c5) (Cody Weaver)
* [Theming action buttons in DialogThemer (#5416)](https://github.com/material-components/material-components-ios/commit/325772ba5e40ce8c27cadab5f0da727dea3d05a9) (Galia Kaufman)
* [Upgrade buttons class to MDCButton (b/117543195) (#5401)](https://github.com/material-components/material-components-ios/commit/9122fc2fcba1d7464d66edc761ce9ab07db318f2) (Galia Kaufman)

---

# 67.1.0

In this minor release we provide a shadow opacity reset toggle for Flexible Header, VoiceOver and rounded corners support for the Navigation Drawer, along with bug fixes and unit tests improvements.
Expand Down
5 changes: 4 additions & 1 deletion MaterialComponents.podspec
Expand Up @@ -2,7 +2,7 @@ load 'scripts/generated/icons.rb'

Pod::Spec.new do |mdc|
mdc.name = "MaterialComponents"
mdc.version = "67.1.0"
mdc.version = "67.2.0"
mdc.authors = "The Material Components authors."
mdc.summary = "A collection of stand-alone production-ready UI libraries focused on design details."
mdc.homepage = "https://github.com/material-components/material-components-ios"
Expand Down Expand Up @@ -555,6 +555,7 @@ Pod::Spec.new do |mdc|

extension.dependency "MaterialComponents/#{extension.base_name.split('+')[0]}"
extension.dependency "MaterialComponents/Themes"
extension.dependency "MaterialComponents/Buttons+ColorThemer"
end

mdc.subspec "Dialogs+TypographyThemer" do |extension|
Expand All @@ -564,6 +565,7 @@ Pod::Spec.new do |mdc|

extension.dependency "MaterialComponents/#{extension.base_name.split('+')[0]}"
extension.dependency "MaterialComponents/schemes/Typography"
extension.dependency "MaterialComponents/Buttons+TypographyThemer"
end

mdc.subspec "Dialogs+DialogThemer" do |extension|
Expand All @@ -574,6 +576,7 @@ Pod::Spec.new do |mdc|
extension.dependency "MaterialComponents/#{extension.base_name.split('+')[0]}"
extension.dependency "MaterialComponents/Dialogs+ColorThemer"
extension.dependency "MaterialComponents/Dialogs+TypographyThemer"
extension.dependency "MaterialComponents/Buttons+ButtonThemer"
end

# FeatureHighlight
Expand Down
2 changes: 1 addition & 1 deletion MaterialComponentsAlpha.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |mdc|
mdc.name = "MaterialComponentsAlpha"
mdc.version = "67.1.0"
mdc.version = "67.2.0"
mdc.authors = "The Material Components authors."
mdc.summary = "A collection of stand-alone alpha UI libraries that are not yet guaranteed to be ready for general production use. Use with caution."
mdc.homepage = "https://github.com/material-components/material-components-ios"
Expand Down
2 changes: 1 addition & 1 deletion MaterialComponentsEarlGreyTests.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "MaterialComponentsEarlGreyTests"
s.version = "67.1.0"
s.version = "67.2.0"
s.authors = "The Material Components authors."
s.summary = "This spec is an aggregate of all the Material Components EarlGrey tests."
s.description = "This spec is made for use in the MDC Catalog."
Expand Down
2 changes: 1 addition & 1 deletion MaterialComponentsExamples.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "MaterialComponentsExamples"
s.version = "67.1.0"
s.version = "67.2.0"
s.authors = "The Material Components authors."
s.summary = "This spec is an aggregate of all the Material Components examples."
s.description = "This spec is made for use in the MDC Catalog. Used in conjunction with CatalogByConvention we create our Material Catalog."
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
67.1.0
67.2.0
2 changes: 1 addition & 1 deletion catalog/MDCCatalog/Info.plist
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>67.1.0</string>
<string>67.2.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
2 changes: 1 addition & 1 deletion catalog/MaterialCatalog/MaterialCatalog.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "MaterialCatalog"
s.version = "67.1.0"
s.version = "67.2.0"
s.summary = "Helper Objective-C classes for the MDC catalog."
s.description = "This spec is made for use in the MDC Catalog."
s.homepage = "https://github.com/material-components/material-components-ios"
Expand Down
22 changes: 22 additions & 0 deletions components/Dialogs/BUILD
Expand Up @@ -52,6 +52,25 @@ objc_bundle(
bundle_imports = [":BundleFiles"],
)

mdc_objc_library(
name = "DialogThemer",
srcs = native.glob(["src/DialogThemer/*.m"]),
hdrs = native.glob(["src/DialogThemer/*.h"]),
includes = ["src/DialogThemer"],
sdk_frameworks = [
"UIKit",
],
deps = [
":Dialogs",
"//components/Themes",
"//components/Buttons:ButtonThemer",
"//components/Buttons:ColorThemer",
":ColorThemer",
":TypographyThemer",
],
visibility = ["//visibility:public"],
)

mdc_objc_library(
name = "ColorThemer",
srcs = native.glob(["src/ColorThemer/*.m"]),
Expand All @@ -63,6 +82,7 @@ mdc_objc_library(
deps = [
":Dialogs",
"//components/Themes",
"//components/Buttons:ColorThemer",
],
visibility = ["//visibility:public"],
)
Expand All @@ -78,6 +98,7 @@ mdc_objc_library(
deps = [
":Dialogs",
"//components/schemes/Typography",
"//components/Buttons:TypographyThemer",
],
visibility = ["//visibility:public"],
)
Expand All @@ -102,6 +123,7 @@ mdc_objc_library(
],
deps = [
":Dialogs",
":DialogThemer",
":ColorThemer",
":TypographyThemer",
":private",
Expand Down
Expand Up @@ -70,6 +70,10 @@ class DialogsAlertCustomizationViewController: MDCCollectionViewController {

var menu: [String] = []

var handler: MDCActionHandler = { action in
print(action.title ?? "Some Action")
}

override func viewDidLoad() {
super.viewDidLoad()

Expand All @@ -82,6 +86,11 @@ class DialogsAlertCustomizationViewController: MDCCollectionViewController {
"Right Aligned Title with a Large Icon",
"Tinted Title Icon, No Title",
"Darker Scrim",
"Emphasis-based Button Theming",
"Text Button Theming (will be deprecated)",
"Text Button Theming (the right way)",
"Custom Button Theming",
"Unthemed Alert",
])
}

Expand Down Expand Up @@ -109,6 +118,16 @@ class DialogsAlertCustomizationViewController: MDCCollectionViewController {
return performTintedTitleIconNoTitle()
case 5:
return performScrimColor()
case 6:
return performEmphasisButtonTheming()
case 7:
return performDeprecatedTextButtonTheming() // b/117717380: Will be deprecated
case 8:
return performTextButtonThemingTheRightWay()
case 9:
return performCustomButtonTheming()
case 10:
return performUnthemed()
default:
print("No row is selected")
return nil
Expand Down Expand Up @@ -157,7 +176,7 @@ class DialogsAlertCustomizationViewController: MDCCollectionViewController {
alert.titleIcon = sampleIcon()
MDCAlertControllerThemer.applyScheme(alertScheme, to: alert)

// theming override: set the titleIconTintColor after the color scheme has been applied
// Theming override: set the titleIconTintColor after the color scheme has been applied
alert.titleIconTintColor = .red

return alert
Expand All @@ -170,13 +189,82 @@ class DialogsAlertCustomizationViewController: MDCCollectionViewController {
return alert
}

func performEmphasisButtonTheming() -> MDCAlertController {
let alert = MDCAlertController(title: "Button Theming", message: "High, Medium & Low Emphasis")
alert.addAction(MDCAlertAction(title:"High", emphasis: .high, handler: handler))
alert.addAction(MDCAlertAction(title:"Medium", emphasis: .medium, handler: handler))
alert.addAction(MDCAlertAction(title:"Low", emphasis: .low, handler: handler))
MDCAlertControllerThemer.applyScheme(alertScheme, to: alert)
return alert
}

func performDeprecatedTextButtonTheming() -> MDCAlertController {
let alert = MDCAlertController(title: "Button Theming",
message: "This method of button theming will be deprecated")
// When not specified, the action is low emphasis by default
alert.addAction(MDCAlertAction(title:"Text", handler: handler))
alert.addAction(MDCAlertAction(title:"Text", handler: handler))
alert.addAction(MDCAlertAction(title:"Text", handler: handler))
MDCAlertControllerThemer.applyScheme(alertScheme, to: alert)
alert.buttonTitleColor = .orange // b/117717380: will be deprecated
return alert
}

// The right way to select the type of buttons is by setting empahsis for actions
func performTextButtonThemingTheRightWay() -> MDCAlertController {
let alert = MDCAlertController(title: "Button Theming",
message: "Use low emphasis to present buttons as text")
// Use .low emphasis to style buttons as text buttons.
alert.addAction(MDCAlertAction(title:"Text", emphasis: .low, handler: handler))
alert.addAction(MDCAlertAction(title:"Text", emphasis: .low, handler: handler))
alert.addAction(MDCAlertAction(title:"Text", emphasis: .low, handler: handler))
MDCAlertControllerThemer.applyScheme(alertScheme, to: alert)
return alert
}

func performCustomButtonTheming() -> MDCAlertController {
let alert = MDCAlertController(title: "Custom Button Theming",
message: "Custom styling of High, Medium & Low Emphasis")
alert.titleIcon = sampleIcon()

// Use .low emphasis for styling buttons as text buttons
alert.addAction(MDCAlertAction(title:"High", emphasis: .high, handler: handler))
alert.addAction(MDCAlertAction(title:"Medium", emphasis: .medium, handler: handler))
alert.addAction(MDCAlertAction(title:"Low", emphasis: .low, handler: handler))

let scheme = MDCAlertScheme()
scheme.typographyScheme = self.typographyScheme

// Create a color theme with a different primary color
let colorScheme = MDCSemanticColorScheme()
colorScheme.primaryColor = .blue

// Assign the new color theme to both the button and the alert schemes.
let buttonScheme = MDCButtonScheme()
buttonScheme.colorScheme = colorScheme
scheme.colorScheme = colorScheme
scheme.buttonScheme = buttonScheme

MDCAlertControllerThemer.applyScheme(scheme, to: alert)
return alert
}

func performUnthemed() -> MDCAlertController {
let alert = MDCAlertController(title: "Unthemed Alert",
message: "Lorem ipsum dolor sit amet, consectetur adipiscing...")
alert.addAction(MDCAlertAction(title:"High", emphasis: .high, handler: handler))
alert.addAction(MDCAlertAction(title:"Medium", emphasis: .medium, handler: handler))
alert.addAction(MDCAlertAction(title:"Low", emphasis: .low, handler: handler))
return alert
}

private func createMDCAlertController(title: String?) -> MDCAlertController {
let alertController = MDCAlertController(title: title, message: """
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
""")
alertController.addAction(MDCAlertAction(title:"OK") { _ in print("OK") })
alertController.addAction(MDCAlertAction(title:"Cancel") { _ in print("Cancel") })
alertController.addAction(MDCAlertAction(title:"OK", handler: handler))
alertController.addAction(MDCAlertAction(title:"Cancel", handler: handler))
return alertController
}

Expand Down
21 changes: 19 additions & 2 deletions components/Dialogs/src/ColorThemer/MDCAlertColorThemer.m
Expand Up @@ -14,18 +14,35 @@

#import "MDCAlertColorThemer.h"

#import "../../../Buttons/src/ColorThemer/MaterialButtons+ColorThemer.h"
#import "../MDCAlertController+ButtonForAction.h"
#import "MaterialButtons.h"
#import "MaterialDialogs.h"

@implementation MDCAlertColorThemer

+ (void)applySemanticColorScheme:(nonnull id<MDCColorScheming>)colorScheme
toAlertController:(nonnull MDCAlertController *)alertController {
alertController.titleColor = [colorScheme.onSurfaceColor colorWithAlphaComponent:(CGFloat)0.87];
alertController.messageColor = [colorScheme.onSurfaceColor colorWithAlphaComponent:(CGFloat)0.60];
alertController.buttonTitleColor = colorScheme.primaryColor;
alertController.titleIconTintColor = colorScheme.primaryColor;
alertController.scrimColor = [colorScheme.onSurfaceColor colorWithAlphaComponent:(CGFloat)0.32];

// Apply theming to buttons based on the action emphasis
for (MDCAlertAction *action in alertController.actions) {
MDCButton *button = [alertController buttonForAction:action];
switch (action.emphasis) {
case MDCActionEmphasisHigh:
[MDCContainedButtonColorThemer applySemanticColorScheme:colorScheme toButton:button];
break;
case MDCActionEmphasisMedium:
[MDCOutlinedButtonColorThemer applySemanticColorScheme:colorScheme toButton:button];
break;
case MDCActionEmphasisLow: // fallthrough
default:
[MDCTextButtonColorThemer applySemanticColorScheme:colorScheme toButton:button];
break;
}
}
}

+ (void)applyColorScheme:(id<MDCColorScheme>)colorScheme {
Expand Down

0 comments on commit 3543693

Please sign in to comment.