Skip to content

Commit

Permalink
[Shape]! Provide more granularity for corner setting for the theming (#…
Browse files Browse the repository at this point in the history
…5116)

This PR allows our users to set specific corners in the shape scheme and have it applied correctly to the components.

Some components may allow only some of their corners to be set (i.e., BottomSheet)
  • Loading branch information
yarneo committed Sep 13, 2018
1 parent 67ddf9b commit c741ba4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
Expand Up @@ -22,16 +22,19 @@ + (void)applyShapeScheme:(id<MDCShapeScheming>)shapeScheme
toBottomSheetController:(MDCBottomSheetController *)bottomSheetController {
// Shape Generator for the Extended state of the Bottom Sheet.
MDCRectangleShapeGenerator *rectangleShapeExtended = [[MDCRectangleShapeGenerator alloc] init];
MDCCornerTreatment *cornerTreatmentExtended = shapeScheme.largeSurfaceShape.topLeftCorner;
[rectangleShapeExtended setCorners:cornerTreatmentExtended];
// For a Bottom Sheet the corner values that can be set are the top corners.
rectangleShapeExtended.topLeftCorner = shapeScheme.largeSurfaceShape.topLeftCorner;
rectangleShapeExtended.topRightCorner = shapeScheme.largeSurfaceShape.topRightCorner;
[bottomSheetController setShapeGenerator:rectangleShapeExtended forState:MDCSheetStateExtended];

// Shape Generator for the Preferred state of the Bottom Sheet.
// This is an override of the default scheme to fit the baseline values.
MDCRectangleShapeGenerator *rectangleShapePreferred = [[MDCRectangleShapeGenerator alloc] init];
MDCCornerTreatment *cornerTreatmentPreferred =
[[MDCRoundedCornerTreatment alloc] initWithRadius:kBottomSheetCollapsedBaselineShapeValue];
[rectangleShapePreferred setCorners:cornerTreatmentPreferred];
// For a Bottom Sheet the corner values that can be set are the top corners.
rectangleShapePreferred.topLeftCorner = cornerTreatmentPreferred;
rectangleShapePreferred.topRightCorner = cornerTreatmentPreferred;
[bottomSheetController setShapeGenerator:rectangleShapePreferred forState:MDCSheetStatePreferred];
}

Expand Down
Expand Up @@ -15,6 +15,7 @@
import XCTest
import MaterialComponents.MaterialBottomSheet
import MaterialComponents.MaterialBottomSheet_ShapeThemer
import MaterialComponents.MaterialShapeLibrary

class BottomSheetShapeThemerTests: XCTestCase {

Expand All @@ -23,6 +24,7 @@ class BottomSheetShapeThemerTests: XCTestCase {
let shapeScheme = MDCShapeScheme()
let bottomSheet = MDCBottomSheetController(contentViewController: UIViewController())
shapeScheme.largeSurfaceShape = MDCShapeCategory(cornersWith: .angled, andSize: 10)
shapeScheme.largeSurfaceShape.topRightCorner = MDCCornerTreatment.corner(withRadius: 3)
bottomSheet.setShapeGenerator(MDCRectangleShapeGenerator(), for: .extended)

// When
Expand All @@ -36,10 +38,8 @@ class BottomSheetShapeThemerTests: XCTestCase {
shapeScheme.largeSurfaceShape.topLeftCorner)
XCTAssertEqual(rectangleGenerator.topRightCorner,
shapeScheme.largeSurfaceShape.topRightCorner)
XCTAssertEqual(rectangleGenerator.bottomLeftCorner,
shapeScheme.largeSurfaceShape.bottomLeftCorner)
XCTAssertEqual(rectangleGenerator.bottomRightCorner,
shapeScheme.largeSurfaceShape.bottomRightCorner)
XCTAssertEqual(rectangleGenerator.bottomLeftCorner, MDCCornerTreatment())
XCTAssertEqual(rectangleGenerator.bottomRightCorner, MDCCornerTreatment())
}

}
Expand All @@ -62,8 +62,8 @@ class BottomSheetShapeThemerTests: XCTestCase {
if let rectangleGenerator = preferredShapeGenerator as? MDCRectangleShapeGenerator {
XCTAssertEqual(rectangleGenerator.topLeftCorner, generatedCorner)
XCTAssertEqual(rectangleGenerator.topRightCorner, generatedCorner)
XCTAssertEqual(rectangleGenerator.bottomLeftCorner, generatedCorner)
XCTAssertEqual(rectangleGenerator.bottomRightCorner, generatedCorner)
XCTAssertEqual(rectangleGenerator.bottomLeftCorner, MDCCornerTreatment())
XCTAssertEqual(rectangleGenerator.bottomRightCorner, MDCCornerTreatment())
}
}

Expand Down
6 changes: 4 additions & 2 deletions components/Cards/src/ShapeThemer/MDCCardsShapeThemer.m
Expand Up @@ -27,8 +27,10 @@ + (void)applyShapeScheme:(id<MDCShapeScheming>)shapeScheme

+ (id<MDCShapeGenerating>)cardShapeGeneratorFromScheme:(id<MDCShapeScheming>)shapeScheme {
MDCRectangleShapeGenerator *rectangleShape = [[MDCRectangleShapeGenerator alloc] init];
MDCCornerTreatment *cornerTreatment = shapeScheme.mediumSurfaceShape.topLeftCorner;
[rectangleShape setCorners:cornerTreatment];
rectangleShape.topLeftCorner = shapeScheme.mediumSurfaceShape.topLeftCorner;
rectangleShape.topRightCorner = shapeScheme.mediumSurfaceShape.topRightCorner;
rectangleShape.bottomLeftCorner = shapeScheme.mediumSurfaceShape.bottomLeftCorner;
rectangleShape.bottomRightCorner = shapeScheme.mediumSurfaceShape.bottomRightCorner;
return rectangleShape;
}

Expand Down
2 changes: 2 additions & 0 deletions components/Cards/tests/unit/MDCCardShapeThemerTests.swift
Expand Up @@ -15,6 +15,7 @@
import XCTest
import MaterialComponents.MaterialCards
import MaterialComponents.MaterialCards_ShapeThemer
import MaterialComponents.MaterialShapeLibrary

class CardShapeThemerTests: XCTestCase {

Expand All @@ -23,6 +24,7 @@ class CardShapeThemerTests: XCTestCase {
let shapeScheme = MDCShapeScheme()
let card = MDCCard()
shapeScheme.mediumSurfaceShape = MDCShapeCategory(cornersWith: .angled, andSize: 10)
shapeScheme.mediumSurfaceShape.topRightCorner = MDCCornerTreatment.corner(withRadius: 3)
card.shapeGenerator = MDCRectangleShapeGenerator()

// When
Expand Down

0 comments on commit c741ba4

Please sign in to comment.