From c741ba49044e613faa0925e8b817783631629573 Mon Sep 17 00:00:00 2001 From: Yarden Eitan Date: Thu, 13 Sep 2018 15:24:29 -0400 Subject: [PATCH] [Shape]! Provide more granularity for corner setting for the theming (#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) --- .../MDCBottomSheetControllerShapeThemer.m | 9 ++++++--- .../tests/unit/BottomSheetShapeThemerTests.swift | 12 ++++++------ .../Cards/src/ShapeThemer/MDCCardsShapeThemer.m | 6 ++++-- .../Cards/tests/unit/MDCCardShapeThemerTests.swift | 2 ++ 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/components/BottomSheet/src/ShapeThemer/MDCBottomSheetControllerShapeThemer.m b/components/BottomSheet/src/ShapeThemer/MDCBottomSheetControllerShapeThemer.m index 29404996fca..b2b7429a116 100644 --- a/components/BottomSheet/src/ShapeThemer/MDCBottomSheetControllerShapeThemer.m +++ b/components/BottomSheet/src/ShapeThemer/MDCBottomSheetControllerShapeThemer.m @@ -22,8 +22,9 @@ + (void)applyShapeScheme:(id)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. @@ -31,7 +32,9 @@ + (void)applyShapeScheme:(id)shapeScheme 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]; } diff --git a/components/BottomSheet/tests/unit/BottomSheetShapeThemerTests.swift b/components/BottomSheet/tests/unit/BottomSheetShapeThemerTests.swift index 095aaa3a1d7..2afd880ec0d 100644 --- a/components/BottomSheet/tests/unit/BottomSheetShapeThemerTests.swift +++ b/components/BottomSheet/tests/unit/BottomSheetShapeThemerTests.swift @@ -15,6 +15,7 @@ import XCTest import MaterialComponents.MaterialBottomSheet import MaterialComponents.MaterialBottomSheet_ShapeThemer +import MaterialComponents.MaterialShapeLibrary class BottomSheetShapeThemerTests: XCTestCase { @@ -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 @@ -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()) } } @@ -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()) } } diff --git a/components/Cards/src/ShapeThemer/MDCCardsShapeThemer.m b/components/Cards/src/ShapeThemer/MDCCardsShapeThemer.m index ddfb04159ee..42be465d9fc 100644 --- a/components/Cards/src/ShapeThemer/MDCCardsShapeThemer.m +++ b/components/Cards/src/ShapeThemer/MDCCardsShapeThemer.m @@ -27,8 +27,10 @@ + (void)applyShapeScheme:(id)shapeScheme + (id)cardShapeGeneratorFromScheme:(id)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; } diff --git a/components/Cards/tests/unit/MDCCardShapeThemerTests.swift b/components/Cards/tests/unit/MDCCardShapeThemerTests.swift index c494c1f95f3..886266949df 100644 --- a/components/Cards/tests/unit/MDCCardShapeThemerTests.swift +++ b/components/Cards/tests/unit/MDCCardShapeThemerTests.swift @@ -15,6 +15,7 @@ import XCTest import MaterialComponents.MaterialCards import MaterialComponents.MaterialCards_ShapeThemer +import MaterialComponents.MaterialShapeLibrary class CardShapeThemerTests: XCTestCase { @@ -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