Skip to content
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

Merged
merged 10 commits into from
Sep 6, 2018

Conversation

yarneo
Copy link
Contributor

@yarneo yarneo commented Sep 5, 2018

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

@yarneo yarneo requested review from jverkoey and a team September 5, 2018 18:30
@material-automation
Copy link

This PR affects multiple components.

MDCShapeCornerSizeTypePercentage,
};


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;

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;


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;
}

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;
}

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"

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
{

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 {

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];

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

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
{

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 {

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];

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];

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];

@material-automation
Copy link

API diff detected the following changes

ShapeScheme

New component.

@material-automation
Copy link

This PR affects multiple components.

// See the License for the specific language governing permissions and
// limitations under the License.

#import "MDCShapeScheme.h"
Copy link
Contributor

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.

Copy link
Contributor

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.

@material-automation
Copy link

This PR affects multiple components.

Copy link
Contributor

@jverkoey jverkoey left a 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.
Copy link
Contributor

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?

components/schemes/Shape/src/MDCShapeCorner.h Show resolved Hide resolved
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.
Copy link
Contributor

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;
Copy link
Contributor

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?

Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@material-automation
Copy link

This PR affects multiple components.

@material-automation
Copy link

This PR affects multiple components.


- (MDCCornerTreatment *)cornerTreatmentValueWithViewBounds:(CGRect)bounds {
MDCCornerTreatment *cornerTreatment;
if (_sizeType == MDCShapeCornerSizeTypePercentage && _size <= 1) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@material-automation
Copy link

This PR affects multiple components.

@material-automation
Copy link

This PR affects multiple components.

@material-automation
Copy link

This PR affects multiple components.

@yarneo
Copy link
Contributor Author

yarneo commented Sep 6, 2018

This will be merged in the afternoon.

@yarneo yarneo merged commit 97b830a into material-components:develop Sep 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants