Skip to content

Commit

Permalink
[Shapes] merge MDCShapeCorner and MDCCornerTreatment into one (#5090)
Browse files Browse the repository at this point in the history
This will allow us to set percentage support for a corner treatment as a follow up PR. Reason being is that the MDCCornerTreatment is part of the shape of the component itself, and hence has control to set the value of the corner when it is right in the lifecycle and the frame has been set. If we keep the percentage value setting in the Shape Themer, then the themer could be applied too early in the lifecycle and thus take a percentage off a 0 value (frame height).

Overall this simplifies the API and causes less duplication.

The other approach would be to *also* add percentage support to MDCCornerTreatment and leave MDCShapeCorner as is, but that would just make it too cumbersome and redundant.
  • Loading branch information
yarneo committed Sep 11, 2018
1 parent b8090cb commit 75ddb21
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 189 deletions.
Expand Up @@ -22,8 +22,7 @@ + (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 cornerTreatmentValue];
MDCCornerTreatment *cornerTreatmentExtended = shapeScheme.largeSurfaceShape.topLeftCorner;
[rectangleShapeExtended setCorners:cornerTreatmentExtended];
[bottomSheetController setShapeGenerator:rectangleShapeExtended forState:MDCSheetStateExtended];

Expand Down
Expand Up @@ -33,13 +33,13 @@ class BottomSheetShapeThemerTests: XCTestCase {
XCTAssert(extendedShapeGenerator is MDCRectangleShapeGenerator)
if let rectangleGenerator = extendedShapeGenerator as? MDCRectangleShapeGenerator {
XCTAssertEqual(rectangleGenerator.topLeftCorner,
shapeScheme.largeSurfaceShape.topLeftCorner.cornerTreatmentValue())
shapeScheme.largeSurfaceShape.topLeftCorner)
XCTAssertEqual(rectangleGenerator.topRightCorner,
shapeScheme.largeSurfaceShape.topRightCorner.cornerTreatmentValue())
shapeScheme.largeSurfaceShape.topRightCorner)
XCTAssertEqual(rectangleGenerator.bottomLeftCorner,
shapeScheme.largeSurfaceShape.bottomLeftCorner.cornerTreatmentValue())
shapeScheme.largeSurfaceShape.bottomLeftCorner)
XCTAssertEqual(rectangleGenerator.bottomRightCorner,
shapeScheme.largeSurfaceShape.bottomRightCorner.cornerTreatmentValue())
shapeScheme.largeSurfaceShape.bottomRightCorner)
}

}
Expand Down
3 changes: 1 addition & 2 deletions components/Cards/src/ShapeThemer/MDCCardsShapeThemer.m
Expand Up @@ -27,8 +27,7 @@ + (void)applyShapeScheme:(id<MDCShapeScheming>)shapeScheme

+ (id<MDCShapeGenerating>)cardShapeGeneratorFromScheme:(id<MDCShapeScheming>)shapeScheme {
MDCRectangleShapeGenerator *rectangleShape = [[MDCRectangleShapeGenerator alloc] init];
MDCCornerTreatment *cornerTreatment =
shapeScheme.mediumSurfaceShape.topLeftCorner.cornerTreatmentValue;
MDCCornerTreatment *cornerTreatment = shapeScheme.mediumSurfaceShape.topLeftCorner;
[rectangleShape setCorners:cornerTreatment];
return rectangleShape;
}
Expand Down
16 changes: 8 additions & 8 deletions components/Cards/tests/unit/MDCCardShapeThemerTests.swift
Expand Up @@ -31,13 +31,13 @@ class CardShapeThemerTests: XCTestCase {
// Then
XCTAssert(card.shapeGenerator is MDCRectangleShapeGenerator);
XCTAssertEqual((card.shapeGenerator as! MDCRectangleShapeGenerator).topLeftCorner,
shapeScheme.mediumSurfaceShape.topLeftCorner.cornerTreatmentValue())
shapeScheme.mediumSurfaceShape.topLeftCorner)
XCTAssertEqual((card.shapeGenerator as! MDCRectangleShapeGenerator).topRightCorner,
shapeScheme.mediumSurfaceShape.topRightCorner.cornerTreatmentValue())
shapeScheme.mediumSurfaceShape.topRightCorner)
XCTAssertEqual((card.shapeGenerator as! MDCRectangleShapeGenerator).bottomLeftCorner,
shapeScheme.mediumSurfaceShape.bottomLeftCorner.cornerTreatmentValue())
shapeScheme.mediumSurfaceShape.bottomLeftCorner)
XCTAssertEqual((card.shapeGenerator as! MDCRectangleShapeGenerator).bottomRightCorner,
shapeScheme.mediumSurfaceShape.bottomRightCorner.cornerTreatmentValue())
shapeScheme.mediumSurfaceShape.bottomRightCorner)
}

func testCardCollectionCellShapeThemer() {
Expand All @@ -53,12 +53,12 @@ class CardShapeThemerTests: XCTestCase {
// Then
XCTAssert(cardCell.shapeGenerator is MDCRectangleShapeGenerator);
XCTAssertEqual((cardCell.shapeGenerator as! MDCRectangleShapeGenerator).topLeftCorner,
shapeScheme.mediumSurfaceShape.topLeftCorner.cornerTreatmentValue())
shapeScheme.mediumSurfaceShape.topLeftCorner)
XCTAssertEqual((cardCell.shapeGenerator as! MDCRectangleShapeGenerator).topRightCorner,
shapeScheme.mediumSurfaceShape.topRightCorner.cornerTreatmentValue())
shapeScheme.mediumSurfaceShape.topRightCorner)
XCTAssertEqual((cardCell.shapeGenerator as! MDCRectangleShapeGenerator).bottomLeftCorner,
shapeScheme.mediumSurfaceShape.bottomLeftCorner.cornerTreatmentValue())
shapeScheme.mediumSurfaceShape.bottomLeftCorner)
XCTAssertEqual((cardCell.shapeGenerator as! MDCRectangleShapeGenerator).bottomRightCorner,
shapeScheme.mediumSurfaceShape.bottomRightCorner.cornerTreatmentValue())
shapeScheme.mediumSurfaceShape.bottomRightCorner)
}
}
21 changes: 16 additions & 5 deletions components/schemes/Shape/src/MDCShapeCategory.h
Expand Up @@ -13,7 +13,18 @@
// limitations under the License.

#import <Foundation/Foundation.h>
#import "MDCShapeCorner.h"
#import "MaterialShapes.h"

/**
This enum consists of the different types of shape corners.
- MDCShapeCornerFamilyRounded: A rounded corner.
- MDCShapeCornerFamilyAngled: An angled/cut corner.
*/
typedef NS_ENUM(NSInteger, MDCShapeCornerFamily) {
MDCShapeCornerFamilyRounded,
MDCShapeCornerFamilyAngled,
};

/**
The MDCShapeCategory is the class containing the shape value as part of our shape scheme,
Expand All @@ -26,22 +37,22 @@
/**
This property represents the shape of the top left corner of the shape.
*/
@property(strong, nonatomic) MDCShapeCorner *topLeftCorner;
@property(strong, nonatomic) MDCCornerTreatment *topLeftCorner;

/**
This property represents the shape of the top right corner of the shape.
*/
@property(strong, nonatomic) MDCShapeCorner *topRightCorner;
@property(strong, nonatomic) MDCCornerTreatment *topRightCorner;

/**
This property represents the shape of the bottom left corner of the shape.
*/
@property(strong, nonatomic) MDCShapeCorner *bottomLeftCorner;
@property(strong, nonatomic) MDCCornerTreatment *bottomLeftCorner;

/**
This property represents the shape of the bottom right corner of the shape.
*/
@property(strong, nonatomic) MDCShapeCorner *bottomRightCorner;
@property(strong, nonatomic) MDCCornerTreatment *bottomRightCorner;

/**
The default init of the class. It sets all 4 corners with a corner family of
Expand Down
18 changes: 14 additions & 4 deletions components/schemes/Shape/src/MDCShapeCategory.m
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#import "MDCShapeCategory.h"
#import "MaterialShapeLibrary.h"

@implementation MDCShapeCategory

Expand All @@ -23,10 +24,19 @@ - (instancetype)init {
- (instancetype)initCornersWithFamily:(MDCShapeCornerFamily)cornerFamily
andSize:(CGFloat)cornerSize {
if (self = [super init]) {
_topLeftCorner = [[MDCShapeCorner alloc] initWithFamily:cornerFamily andSize:cornerSize];
_topRightCorner = [[MDCShapeCorner alloc] initWithFamily:cornerFamily andSize:cornerSize];
_bottomLeftCorner = [[MDCShapeCorner alloc] initWithFamily:cornerFamily andSize:cornerSize];
_bottomRightCorner = [[MDCShapeCorner alloc] initWithFamily:cornerFamily andSize:cornerSize];
MDCCornerTreatment *cornerTreatment;
switch (cornerFamily) {
case MDCShapeCornerFamilyAngled:
cornerTreatment = [MDCCornerTreatment cornerWithCut:cornerSize];
break;
case MDCShapeCornerFamilyRounded:
cornerTreatment = [MDCCornerTreatment cornerWithRadius:cornerSize];
break;
}
_topLeftCorner = cornerTreatment;
_topRightCorner = cornerTreatment;
_bottomLeftCorner = cornerTreatment;
_bottomRightCorner = cornerTreatment;
}
return self;
}
Expand Down
93 changes: 0 additions & 93 deletions components/schemes/Shape/src/MDCShapeCorner.h

This file was deleted.

70 changes: 0 additions & 70 deletions components/schemes/Shape/src/MDCShapeCorner.m

This file was deleted.

1 change: 0 additions & 1 deletion components/schemes/Shape/src/MaterialShapeScheme.h
Expand Up @@ -13,5 +13,4 @@
// limitations under the License.

#import "MDCShapeCategory.h"
#import "MDCShapeCorner.h"
#import "MDCShapeScheme.h"

0 comments on commit 75ddb21

Please sign in to comment.