Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Shapes] Initial Shape Scheme implementation (#5014)
This PR implements the initial Shape Scheme that is essential for allowing shape theming for components (*this doesn't include any themers and that will be included as a separate PR once this is approved*). More information can be seen in go/mdc-ios-shape-theming and go/material-shapes-eng
This closes #4609 #4612 #4613
- Loading branch information
Showing
12 changed files
with
544 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
components/private/ShapeLibrary/src/MDCCornerTreatment+CornerTypeInitalizer.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2018-present the Material Components for iOS authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#import "MaterialShapes.h" | ||
|
||
typedef NS_ENUM(NSInteger, MDCCornerType) { | ||
MDCCornerTypeCurved, | ||
MDCCornerTypeCut, | ||
MDCCornerTypeRounded | ||
}; | ||
|
||
@interface MDCCornerTreatment (CornerTypeInitalizer) | ||
|
||
- (instancetype)initWithCornerType:(MDCCornerType)cornerType andSize:(NSNumber *)size; | ||
|
||
@end |
45 changes: 45 additions & 0 deletions
45
components/private/ShapeLibrary/src/MDCCornerTreatment+CornerTypeInitalizer.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2018-present the Material Components for iOS authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#import "MDCCornerTreatment+CornerTypeInitalizer.h" | ||
|
||
#import "MDCCurvedCornerTreatment.h" | ||
#import "MDCCutCornerTreatment.h" | ||
#import "MDCRoundedCornerTreatment.h" | ||
|
||
@implementation MDCCornerTreatment (CornerTypeInitalizer) | ||
|
||
- (instancetype)initWithCornerType:(MDCCornerType)cornerType andSize:(NSNumber *)size { | ||
self = [self init]; | ||
switch (cornerType) { | ||
case MDCCornerTypeCurved: { | ||
CGSize curvedSize = [size CGSizeValue]; | ||
self = [[MDCCurvedCornerTreatment alloc] initWithSize:curvedSize]; | ||
break; | ||
} | ||
case MDCCornerTypeCut: { | ||
CGFloat cutSize = [size floatValue]; | ||
self = [[MDCCutCornerTreatment alloc] initWithCut:cutSize]; | ||
break; | ||
} | ||
case MDCCornerTypeRounded: { | ||
CGFloat radiusSize = [size floatValue]; | ||
self = [[MDCRoundedCornerTreatment alloc] initWithRadius:radiusSize]; | ||
break; | ||
} | ||
} | ||
return self; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Copyright 2018-present The Material Components for iOS Authors. All | ||
# Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
# implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
load("//:material_components_ios.bzl", | ||
"mdc_objc_library", | ||
"mdc_public_objc_library", | ||
"mdc_unit_test_suite") | ||
|
||
licenses(["notice"]) # Apache 2.0 | ||
|
||
mdc_public_objc_library( | ||
name = "Shape", | ||
deps = [ | ||
"//components/private/ShapeLibrary", | ||
], | ||
) | ||
|
||
package_group( | ||
name = "test_targets", | ||
packages = [ | ||
"//components/schemes/Shape/...", | ||
], | ||
) | ||
|
||
mdc_objc_library( | ||
name = "unit_test_sources", | ||
testonly = 1, | ||
srcs = glob(["tests/unit/*.m"]), | ||
hdrs = glob(["tests/unit/*.h"]), | ||
includes = ["src"], | ||
sdk_frameworks = [ | ||
"CoreGraphics", | ||
"UIKit", | ||
"XCTest", | ||
], | ||
deps = [ | ||
":Shape", | ||
], | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
mdc_unit_test_suite( | ||
deps = [ | ||
":unit_test_sources", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2018-present the Material Components for iOS authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "MDCShapeCorner.h" | ||
|
||
/** | ||
The MDCShapeCategory is the class containing the shape value as part of our shape scheme, | ||
MDCShapeScheme. | ||
MDCShapeCategory is built from 4 corners, that can be set to alter the shape value. | ||
*/ | ||
@interface MDCShapeCategory : NSObject | ||
|
||
/** | ||
This property represents the shape of the top left corner of the shape. | ||
*/ | ||
@property(strong, nonatomic) MDCShapeCorner *topLeftCorner; | ||
|
||
/** | ||
This property represents the shape of the top right corner of the shape. | ||
*/ | ||
@property(strong, nonatomic) MDCShapeCorner *topRightCorner; | ||
|
||
/** | ||
This property represents the shape of the bottom left corner of the shape. | ||
*/ | ||
@property(strong, nonatomic) MDCShapeCorner *bottomLeftCorner; | ||
|
||
/** | ||
This property represents the shape of the bottom right corner of the shape. | ||
*/ | ||
@property(strong, nonatomic) MDCShapeCorner *bottomRightCorner; | ||
|
||
/** | ||
The default init of the class. It sets all 4 corners with a corner family of | ||
MDCShapeCornerFamilyRounded and size of 0. This is equivalent to a "sharp" corner, or in terms of | ||
Apple's API it is the same as setting the cornerRadius to 0. | ||
@return returns an initialized MDCShapeCategory instance. | ||
*/ | ||
- (instancetype)init; | ||
|
||
/** | ||
This method is a convenience initializer of setting the shape value of all our corners at once | ||
to the provided cornerFamily and cornerSize. | ||
The outcome is a symmetrical shape that has the same values for all its corners. | ||
@param cornerFamily The family of our corner (rounded or angled). | ||
@param cornerSize The shape value of the corner. | ||
@return returns an MDCShapeCategory with the initialized values. | ||
*/ | ||
- (instancetype)initCornersWithFamily:(MDCShapeCornerFamily)cornerFamily | ||
andSize:(CGFloat)cornerSize; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2018-present the Material Components for iOS authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#import "MDCShapeCategory.h" | ||
|
||
@implementation MDCShapeCategory | ||
|
||
- (instancetype)init { | ||
return [self initCornersWithFamily:MDCShapeCornerFamilyRounded andSize:0]; | ||
} | ||
|
||
- (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]; | ||
} | ||
return self; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright 2018-present the Material Components for iOS authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "MaterialShapeLibrary.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, | ||
}; | ||
|
||
/** | ||
This enum consists of the different types of shape values that can be provided. | ||
- MDCShapeCornerSizeTypeAbsolute: If an absolute shape size is provided. | ||
- MDCShapeCornerSizeTypePercentage: If a relative shape size is provided. | ||
See MDCShapeCorner's @c size property for additional details. | ||
*/ | ||
typedef NS_ENUM(NSInteger, MDCShapeCornerSizeType) { | ||
MDCShapeCornerSizeTypeAbsolute, | ||
MDCShapeCornerSizeTypePercentage, | ||
}; | ||
|
||
/** | ||
An MDCShapeCorner is the shape value of a corner. It takes a family, a size type, and a size. | ||
*/ | ||
@interface MDCShapeCorner : NSObject | ||
|
||
/** | ||
The shape family of our corner. | ||
*/ | ||
@property(assign, nonatomic) MDCShapeCornerFamily family; | ||
|
||
/** | ||
The size type of our shape. | ||
*/ | ||
@property(assign, nonatomic) MDCShapeCornerSizeType sizeType; | ||
|
||
/** | ||
The size of our shape. | ||
When MDCShapeSizeType is MDCShapeCornerSizeTypeAbsolute, this accepts absolute values | ||
that are positive. | ||
When MDCShapeSizeType is MDCShapeCornerSizeTypePercentage, values are expected to be in the range | ||
of 0 to 1 (0% - 100%). These values are percentages based on the height of the surface. | ||
*/ | ||
@property(assign, nonatomic) CGFloat size; | ||
|
||
/** | ||
This initializer takes in a shape family and size, and returns a shape corner. | ||
@param cornerFamily The shape family. | ||
@param cornerSize The shape size. | ||
@return an MDCShapeCorner. | ||
*/ | ||
- (instancetype)initWithFamily:(MDCShapeCornerFamily)cornerFamily andSize:(CGFloat)cornerSize; | ||
|
||
/** | ||
This method returns an MDCCornerTreament representation of the MDCShapeCorner. | ||
@return an MDCCornerTreatment. | ||
*/ | ||
- (MDCCornerTreatment *)cornerTreatmentValue; | ||
|
||
/** | ||
This method returns an MDCCornerTreatment representation of the MDCShapeCorner. | ||
It receives the bounds of the shape when a percentage or relative value is given. | ||
@param bounds The bounds of the shape. | ||
@return an MDCCornerTreatment. | ||
*/ | ||
- (MDCCornerTreatment *)cornerTreatmentValueWithViewBounds:(CGRect)bounds; | ||
|
||
@end |
Oops, something went wrong.