Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:material-components/material-com…
Browse files Browse the repository at this point in the history
…ponents-ios into stable
  • Loading branch information
Robert Moore committed Jan 31, 2019
2 parents 5c85635 + 514e93c commit fa005e3
Show file tree
Hide file tree
Showing 62 changed files with 606 additions and 375 deletions.
4 changes: 4 additions & 0 deletions .kokoro
Expand Up @@ -81,6 +81,7 @@ fix_bazel_imports() {
rewrite_catalogs "s/import MaterialComponents.Material(.+)_(.+)/import components_\1_\2/"
rewrite_catalogs "s/import MaterialComponentsBeta.Material(.+)Scheme/import components_schemes_\1_\1 \/\/ Beta/"
rewrite_catalogs "s/import MaterialComponents.Material(.+)Scheme/import components_schemes_\1_\1/"
rewrite_examples "s/import <MaterialComponentsBeta\/(.+)>/import\/\*Material beta framework import\*\/ \"\1\"/"
rewrite_examples "s/import MaterialComponents.Material(.+)_(.+)/import components_\1_\2/"
rewrite_examples "s/import MaterialComponentsBeta.Material(.+)Beta/import components_\1_\1Beta \/\/ BetaSplit/"
rewrite_examples "s/import MaterialComponentsBeta.Material(.+)Scheme/import components_schemes_\1_\1 \/\/ Beta/"
Expand All @@ -107,6 +108,7 @@ fix_bazel_imports() {
rewrite_examples "s/import MaterialComponentsBeta.Material(.+)/import components_\1_\1 \/\/ Beta/"
rewrite_examples "s/import MaterialComponents.Material(.+)/import components_\1_\1/"
rewrite_examples "s/import MDFTextAccessibility/import material_text_accessibility_ios_MDFTextAccessibility/"
rewrite_source "s/import <MaterialComponentsBeta\/(.+)>/import\/\*Material beta framework import\*\/ \"\1\"/"
rewrite_source "s/import <Motion(.+)\/Motion.+\.h>/import \"Motion\1.h\"/"
rewrite_source "s/import <MDFTextAccessibility\/MDFTextAccessibility\.h>/import \"MDFTextAccessibility.h\"/"
rewrite_source "s/import <MaterialComponents\/Material(.+)\.h>/import\/\*Material prefix framework import\*\/ \"Material\1.h\"/"
Expand Down Expand Up @@ -141,6 +143,7 @@ fix_bazel_imports() {
rewrite_catalogs "s/import catalog_by_convention_CatalogByConvention/import CatalogByConvention/"
rewrite_catalogs "s/import material_internationalization_ios_MDFInternationalization/import MDFInternationalization/"
rewrite_catalogs "s/import material_text_accessibility_ios_MDFTextAccessibility/import MDFTextAccessibility/"
rewrite_examples "s/import\/\*Material beta framework import\*\/ \"(.+)\"/import <MaterialComponentsBeta\/\1>/"
rewrite_examples "s/import components_(.+)_\1Beta \/\/ BetaSplit/import MaterialComponentsBeta.Material\1Beta/"
rewrite_examples "s/import components_(.+)_\1 \/\/ Beta/import MaterialComponentsBeta.Material\1/"
rewrite_examples "s/import components_schemes_(.+)_.+ \/\/ Beta/import MaterialComponentsBeta.Material\1Scheme/"
Expand All @@ -150,6 +153,7 @@ fix_bazel_imports() {
rewrite_examples "s/import components_(.+)_(.+) \/\/ Beta/import MaterialComponentsBeta.Material\1_\2/"
rewrite_examples "s/import components_(.+)_(.+)/import MaterialComponents.Material\1_\2/"
rewrite_examples "s/import material_text_accessibility_ios_MDFTextAccessibility/import MDFTextAccessibility/"
rewrite_source "s/import\/\*Material beta framework import\*\/ \"(.+)\"/import <MaterialComponentsBeta\/\1>/"
rewrite_source "s/import \"Motion(.+)\.h\"/import <Motion\1\/Motion\1.h>/"
rewrite_source "s/import \"MDFTextAccessibility\.h\"/import <MDFTextAccessibility\/MDFTextAccessibility.h>/"
rewrite_source "s/import\/\*Material prefix framework import\*\/ \"Material(.+)\.h\"/import <MaterialComponents\/Material\1\.h>/"
Expand Down
5 changes: 1 addition & 4 deletions catalog/MDCCatalog/AppDelegate.swift
Expand Up @@ -67,10 +67,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, MDCAppBarNavigationContro
}

func themeDidChange(notification: NSNotification) {
guard let colorScheme = notification.userInfo?[AppTheme.globalThemeNotificationColorSchemeKey]
as? MDCColorScheming else {
return
}
let colorScheme = AppTheme.globalTheme.colorScheme
for viewController in navigationController.childViewControllers {
guard let appBar = navigationController.appBar(for: viewController) else {
continue
Expand Down
76 changes: 35 additions & 41 deletions catalog/MDCCatalog/AppTheme.swift
Expand Up @@ -15,66 +15,60 @@
import Foundation
import MaterialComponents.MaterialButtons_ButtonThemer
import MaterialComponents.MaterialColorScheme
import MaterialComponents.MaterialShapeScheme
import MaterialComponents.MaterialTypographyScheme
import MaterialComponentsBeta.MaterialContainerScheme

final class AppTheme {
let containerScheme: MDCContainerScheme
let containerScheme: MDCContainerScheming

var colorScheme: MDCColorScheming {
return containerScheme.colorScheme ?? AppTheme.defaultColorScheme
return containerScheme.colorScheme ?? MDCSemanticColorScheme(defaults: .material201804)
}

var typographyScheme: MDCTypographyScheming {
return containerScheme.typographyScheme ?? AppTheme.defaultTypographyScheme
return containerScheme.typographyScheme ?? MDCTypographyScheme(defaults: .material201804)
}

init(colorScheme: MDCColorScheming, typographyScheme: MDCTypographyScheming) {
self.containerScheme = MDCContainerScheme()
self.containerScheme.colorScheme = colorScheme as? MDCSemanticColorScheme
self.containerScheme.typographyScheme = typographyScheme as? MDCTypographyScheme
init(containerScheme: MDCContainerScheming) {
self.containerScheme = containerScheme
}

static let defaultTheme: AppTheme = {
return AppTheme(colorScheme: defaultColorScheme,
typographyScheme: defaultTypographyScheme)
}()

static var defaultColorScheme: MDCSemanticColorScheme = {
let colorScheme = MDCSemanticColorScheme()
colorScheme.primaryColor = UIColor(red: CGFloat(0x21) / 255.0,
green: CGFloat(0x21) / 255.0,
blue: CGFloat(0x21) / 255.0,
alpha: 1)
colorScheme.primaryColorVariant = .init(white: 0.7, alpha: 1)
colorScheme.secondaryColor = UIColor(red: CGFloat(0x00) / 255.0,
green: CGFloat(0xE6) / 255.0,
blue: CGFloat(0x76) / 255.0,
alpha: 1)
return colorScheme
}()

static var defaultTypographyScheme: MDCTypographyScheme = {
let typographyScheme = MDCTypographyScheme()
typographyScheme.headline1 = UIFont.systemFont(ofSize: 20)
typographyScheme.headline2 = UIFont.systemFont(ofSize: 18)
typographyScheme.headline3 = UIFont.systemFont(ofSize: 15)
return typographyScheme
}()

static var globalTheme: AppTheme = defaultTheme {
static var globalTheme = AppTheme(containerScheme: DefaultContainerScheme()) {
didSet {
NotificationCenter.default.post(name: AppTheme.didChangeGlobalThemeNotificationName,
object: nil,
userInfo:
[AppTheme.globalThemeNotificationColorSchemeKey: AppTheme.globalTheme.colorScheme,
AppTheme.globalThemeNotificationTypographySchemeKey: AppTheme.globalTheme.typographyScheme]
)
userInfo: nil)
}
}

static let didChangeGlobalThemeNotificationName =
Notification.Name("MDCCatalogDidChangeGlobalTheme")
static let globalThemeNotificationColorSchemeKey = "colorScheme"
static let globalThemeNotificationTypographySchemeKey = "typographyScheme"
}

func DefaultContainerScheme() -> MDCContainerScheme {
let containerScheme = MDCContainerScheme()

let colorScheme = MDCSemanticColorScheme()
colorScheme.primaryColor = UIColor(red: CGFloat(0x21) / 255.0,
green: CGFloat(0x21) / 255.0,
blue: CGFloat(0x21) / 255.0,
alpha: 1)
colorScheme.primaryColorVariant = .init(white: 0.7, alpha: 1)
colorScheme.secondaryColor = UIColor(red: CGFloat(0x00) / 255.0,
green: CGFloat(0xE6) / 255.0,
blue: CGFloat(0x76) / 255.0,
alpha: 1)
containerScheme.colorScheme = colorScheme

let typographyScheme = MDCTypographyScheme()
typographyScheme.headline1 = UIFont.systemFont(ofSize: 20)
typographyScheme.headline2 = UIFont.systemFont(ofSize: 18)
typographyScheme.headline3 = UIFont.systemFont(ofSize: 15)
containerScheme.typographyScheme = typographyScheme

let shapeScheme = MDCShapeScheme()
containerScheme.shapeScheme = shapeScheme

return containerScheme
}
5 changes: 1 addition & 4 deletions catalog/MDCCatalog/MDCCatalogComponentsController.swift
Expand Up @@ -116,10 +116,7 @@ class MDCCatalogComponentsController: UICollectionViewController, MDCInkTouchCon
}

func themeDidChange(notification: NSNotification) {
guard let colorScheme = notification.userInfo?[AppTheme.globalThemeNotificationColorSchemeKey]
as? MDCColorScheming else {
return
}
let colorScheme = AppTheme.globalTheme.colorScheme
MDCFlexibleHeaderColorThemer.applySemanticColorScheme(colorScheme,
to: headerViewController.headerView)
setNeedsStatusBarAppearanceUpdate()
Expand Down
3 changes: 0 additions & 3 deletions catalog/MDCCatalog/MDCCatalogTileView.swift
Expand Up @@ -55,9 +55,6 @@ class MDCCatalogTileView: UIView {
}

func themeDidChange(notification: NSNotification) {
guard notification.userInfo?[AppTheme.globalThemeNotificationColorSchemeKey] != nil else {
return
}
imageCache.removeAllObjects()
}

Expand Down
58 changes: 25 additions & 33 deletions catalog/MDCCatalog/MDCThemePickerViewController.swift
Expand Up @@ -16,19 +16,22 @@ import MDFTextAccessibility
import MaterialComponents.MaterialIcons_ic_check
import MaterialComponents.MaterialPalettes
import MaterialComponents.MaterialThemes
import MaterialComponentsBeta.MaterialContainerScheme
import UIKit

private func createSchemeWithPalette(_ palette: MDCPalette) -> MDCSemanticColorScheme {
private func schemeWithPalette(_ palette: MDCPalette) -> MDCContainerScheming {
let containerScheme = DefaultContainerScheme()

let scheme = MDCSemanticColorScheme()
scheme.primaryColor = palette.tint500
scheme.primaryColorVariant = palette.tint900
scheme.secondaryColor = scheme.primaryColor
if let onPrimaryColor = MDFTextAccessibility.textColor(fromChoices: [MDCPalette.grey.tint100,
MDCPalette.grey.tint900,
UIColor.black,
UIColor.white],
onBackgroundColor: scheme.primaryColor,
options: .preferLighter) {
MDCPalette.grey.tint900,
UIColor.black,
UIColor.white],
onBackgroundColor: scheme.primaryColor,
options: .preferLighter) {
scheme.onPrimaryColor = onPrimaryColor
}
if let onSecondaryColor = MDFTextAccessibility.textColor(fromChoices: [MDCPalette.grey.tint100,
Expand All @@ -39,18 +42,20 @@ private func createSchemeWithPalette(_ palette: MDCPalette) -> MDCSemanticColorS
options: .preferLighter) {
scheme.onSecondaryColor = onSecondaryColor
}
return scheme
containerScheme.colorScheme = scheme

return containerScheme
}

private struct MDCColorThemeCellConfiguration {
let name: String
let mainColor: UIColor
let colorScheme: () -> MDCColorScheming
let scheme: MDCContainerScheming

init(name: String, mainColor: UIColor, colorScheme: @escaping () -> MDCColorScheming) {
init(name: String, mainColor: UIColor, scheme: MDCContainerScheming) {
self.name = name
self.mainColor = mainColor
self.colorScheme = colorScheme
self.scheme = scheme
}
}

Expand All @@ -69,38 +74,26 @@ class MDCThemePickerViewController: UIViewController, UICollectionViewDataSource
private let cellReuseIdentifier = "cell"
private let colorSchemeConfigurations = [
MDCColorThemeCellConfiguration(name: "Default",
mainColor: AppTheme.defaultTheme.colorScheme.primaryColor,
colorScheme: { return AppTheme.defaultTheme.colorScheme }),
mainColor: AppTheme.globalTheme.colorScheme.primaryColor,
scheme: DefaultContainerScheme()),
MDCColorThemeCellConfiguration(name: "Blue",
mainColor: MDCPalette.blue.tint500,
colorScheme: {
return createSchemeWithPalette(MDCPalette.blue)
}),
scheme: schemeWithPalette(MDCPalette.blue)),
MDCColorThemeCellConfiguration(name: "Red",
mainColor: MDCPalette.red.tint500,
colorScheme: {
return createSchemeWithPalette(MDCPalette.red)
}),
scheme: schemeWithPalette(MDCPalette.red)),
MDCColorThemeCellConfiguration(name: "Green",
mainColor: MDCPalette.green.tint500,
colorScheme: {
return createSchemeWithPalette(MDCPalette.green)
}),
scheme: schemeWithPalette(MDCPalette.green)),
MDCColorThemeCellConfiguration(name: "Amber",
mainColor: MDCPalette.amber.tint500,
colorScheme: {
return createSchemeWithPalette(MDCPalette.amber)
}),
scheme: schemeWithPalette(MDCPalette.amber)),
MDCColorThemeCellConfiguration(name: "Pink",
mainColor: MDCPalette.pink.tint500,
colorScheme: {
return createSchemeWithPalette(MDCPalette.pink)
}),
scheme: schemeWithPalette(MDCPalette.pink)),
MDCColorThemeCellConfiguration(name: "Orange",
mainColor: MDCPalette.orange.tint500,
colorScheme: {
return createSchemeWithPalette(MDCPalette.orange)
})
scheme: schemeWithPalette(MDCPalette.orange)),
]
private let cellSize : CGFloat = 48.0 // minimum touch target
private let cellSpacing : CGFloat = 8.0
Expand Down Expand Up @@ -212,10 +205,9 @@ class MDCThemePickerViewController: UIViewController, UICollectionViewDataSource
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let colorScheme = colorSchemeConfigurations[indexPath.item].colorScheme()
navigationController?.popViewController(animated: true)
AppTheme.globalTheme = AppTheme(colorScheme: colorScheme,
typographyScheme: AppTheme.globalTheme.typographyScheme)
let scheme = colorSchemeConfigurations[indexPath.item].scheme
AppTheme.globalTheme = AppTheme(containerScheme: scheme)
}

}
Expand Down
1 change: 1 addition & 0 deletions components/BottomNavigation/BUILD
Expand Up @@ -218,6 +218,7 @@ mdc_snapshot_objc_library(
":BottomNavigation",
":ColorThemer",
":TypographyThemer",
":private",
],
)

Expand Down

0 comments on commit fa005e3

Please sign in to comment.