-
Notifications
You must be signed in to change notification settings - Fork 944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Shapes] Initial Shape Scheme implementation #5014
[Shapes] Initial Shape Scheme implementation #5014
Conversation
This PR affects multiple components. |
MDCShapeCornerSizeTypePercentage, | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format suggested the following change:
-
@return an MDCShapeCorner. | ||
*/ | ||
- (instancetype)initWithFamily:(MDCShapeCornerFamily)cornerFamily | ||
andSize:(CGFloat)cornerSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format suggested the following change:
-- (instancetype)initWithFamily:(MDCShapeCornerFamily)cornerFamily
- andSize:(CGFloat)cornerSize;
+- (instancetype)initWithFamily:(MDCShapeCornerFamily)cornerFamily andSize:(CGFloat)cornerSize;
*/ | ||
@property(strong, nonatomic) MDCShapeCorner *bottomRightCorner; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format suggested the following change:
-
CGFloat radiusSize = [size floatValue]; | ||
self = [[MDCRoundedCornerTreatment alloc] initWithRadius:radiusSize]; | ||
break; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format suggested the following change:
- 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;
- }
+ self = [self init];
+ switch (cornerType) {
+ case MDCCornerTypeCurved: {
+ CGSize curvedSize = [size CGSizeValue];
+ self = [[MDCCurvedCornerTreatment alloc] initWithSize:curvedSize];
+ break;
CGFloat radiusSize = [size floatValue]; | ||
self = [[MDCRoundedCornerTreatment alloc] initWithRadius:radiusSize]; | ||
break; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format suggested the following change:
+ case MDCCornerTypeCut: {
+ CGFloat cutSize = [size floatValue];
+ self = [[MDCCutCornerTreatment alloc] initWithCut:cutSize];
+ break;
+ }
+ case MDCCornerTypeRounded: {
+ CGFloat radiusSize = [size floatValue];
+ self = [[MDCRoundedCornerTreatment alloc] initWithRadius:radiusSize];
+ break;
+ }
+ }
@@ -19,3 +19,4 @@ | |||
#import "MDCSlantedRectShapeGenerator.h" | |||
#import "MDCTriangleEdgeTreatment.h" | |||
#import "MDCCutCornerTreatment.h" | |||
#import "MDCCornerTreatment+CornerTypeInitalizer.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format suggested the following change:
-#import "MDCCutCornerTreatment.h"
-#import "MDCCornerTreatment+CornerTypeInitalizer.h"
@implementation MDCShapeCategory | ||
|
||
- (instancetype)init | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format suggested the following change:
-- (instancetype)init
-{
+- (instancetype)init {
} | ||
|
||
- (instancetype)initCornersWithFamily:(MDCShapeCornerFamily)cornerFamily | ||
andSize:(CGFloat)cornerSize { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format suggested the following change:
- andSize:(CGFloat)cornerSize {
+ andSize:(CGFloat)cornerSize {
_bottomLeftCorner = [[MDCShapeCorner alloc] initWithFamily:cornerFamily | ||
andSize:cornerSize]; | ||
_bottomRightCorner = [[MDCShapeCorner alloc] initWithFamily:cornerFamily | ||
andSize:cornerSize]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format suggested the following change:
- _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];
+ _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];
} | ||
|
||
@end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format suggested the following change:
-
@implementation MDCShapeCorner | ||
|
||
- (instancetype)init | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format suggested the following change:
-- (instancetype)init
-{
+- (instancetype)init {
} | ||
|
||
- (instancetype)initWithFamily:(MDCShapeCornerFamily)cornerFamily | ||
andSize:(CGFloat)cornerSize { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format suggested the following change:
-- (instancetype)initWithFamily:(MDCShapeCornerFamily)cornerFamily
- andSize:(CGFloat)cornerSize {
+- (instancetype)initWithFamily:(MDCShapeCornerFamily)cornerFamily andSize:(CGFloat)cornerSize {
case MDCShapeCornerFamilyAngled: | ||
cornerTreatment = | ||
[[MDCCornerTreatment alloc] initWithCornerType:MDCCornerTypeCut | ||
andSize:size]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format suggested the following change:
- cornerTreatment =
- [[MDCCornerTreatment alloc] initWithCornerType:MDCCornerTypeCut
- andSize:size];
+ cornerTreatment = [[MDCCornerTreatment alloc] initWithCornerType:MDCCornerTypeCut
+ andSize:size];
case MDCShapeCornerFamilyRounded: | ||
cornerTreatment = | ||
[[MDCCornerTreatment alloc] initWithCornerType:MDCCornerTypeRounded | ||
andSize:size]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format suggested the following change:
- cornerTreatment =
- [[MDCCornerTreatment alloc] initWithCornerType:MDCCornerTypeRounded
- andSize:size];
+ cornerTreatment = [[MDCCornerTreatment alloc] initWithCornerType:MDCCornerTypeRounded
+ andSize:size];
API diff detected the following changesShapeSchemeNew component. |
This PR affects multiple components. |
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#import "MDCShapeScheme.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add #import "MDCShapeCategory.h"
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For that matter, all of the public header should be listed here.
This PR affects multiple components. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with mostly documentation feedback.
|
||
MDCShapeCategory is built from 4 corners, that can be set to alter the shape value. | ||
|
||
This takes on the assumption that our settable shapes are made of 4 corners. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this sentence is communicating any new information (I think it's describing the fact that the class has four corners) - consider removing?
that are positive. | ||
|
||
When MDCShapeSizeType is MDCShapeCornerSizeTypePercentage, this accepts percentage values | ||
from 0 to 1 (0% - 100%). These values are percentages based on the height of the surface. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wording here implies that values outside of these ranges might thrown an assertion. If this is the case, document that the bounds are strictly enforced. Otherwise it may help to soften the wording here to say "values are expected to be in the range of [lower...upper]"
|
||
@return an MDCCornerTreatment. | ||
*/ | ||
- (MDCCornerTreatment *)cornerTreatmentValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have this layer of indirection? Do we intend to deprecate or replace MDCCornerTreatment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put another way - why is the logic that turns a shape corner into a corner treatment not part of the themers instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to make it so we only have to do the conversion of MDCShapeCorner
to one of the MDCCornerTreatment
instances once, rather than it being done in every one of our themers. I initially had it in the themers but it was rather messy and redundant. In terms of architecture it made sense to add a convenience converter in MDCShapeCorner
and then add additional initializers to MDCCornerTreatment
to take the needed information and initialize the right corner treatment. Do you think there is a better way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we intend to deprecate or replace MDCCornerTreatment?
What are your thoughts on this question?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think MDCCornerTreatment
fits the shape subsystem's purpose of setting corner treatments inside an MDCRectangleShapeGenerator
well. I also think that the MDCShapeCorner
encapsulates the exact relevant information needed to identify the corner values. The convertor is necessary as these two classes don't serve the same purpose. I do think that MDCCornerTreatment
is using outdated terminology, i.e., CutCorner doesn't exist anymore, it is AngledCorner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I'm not entirely convinced yet that there needs to be two APIs that accomplish similar things with different terminology and naming. I see that you feel the two APIs accomplish very specific and different purposes, but this makes me wonder if we got the API wrong in the Shapes library and should update it accordingly. The end result being that MDCShapeCorner is part of the shapes library as a replacement for MDCCornerTreatment and the scheme relies on that accordingly.
If the above is sensible I think it's fair to plan a deprecation roadmap for the two APIs that will happen over a longer period of time, but that that work wouldn't necessarily have to block this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we think we want this to be one entity, we can always add these properties to MDCCornerTreatment
and the right initializers to it as well. I felt like the division kept it cleaner. If you feel strongly about it, i can do it in this PR, as this isn't a deprecation per-say.
…nents-ios into initialshapescheme
This PR affects multiple components. |
This PR affects multiple components. |
|
||
- (MDCCornerTreatment *)cornerTreatmentValueWithViewBounds:(CGRect)bounds { | ||
MDCCornerTreatment *cornerTreatment; | ||
if (_sizeType == MDCShapeCornerSizeTypePercentage && _size <= 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This behavior looks a bit surprising if the size > 1 and we fall back to absolute size. Consider throwing an assert instead in order to enforce proper usage of the API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true, i removed the check as I don't want to enforce it.
This PR affects multiple components. |
This PR affects multiple components. |
This PR affects multiple components. |
This will be merged in the afternoon. |
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