mirror of
https://github.com/material-components/material-components-ios.git
synced 2026-02-20 08:27:32 +08:00
This is the third and last part of the migration of moving the Shape libraries away from the private/ folder. Continuation to PR: #6664 and #6495 Tracking bug, progress and more details can be found here: #6494 This resolves #6494 Because Shapes and ShapeLibrary have been used in production and are an integral part of the shape scheme and theming. Moreover, with to stop the confusion of clients that the library should not be imported as it is under private, we want to migrate the Shape libs to be under components/ instead of components/private. The migration will be a 7 step migration to not break clients internally. **We have completed steps 1 to 6, This PR concludes step 7 and the entire migration** 1. move the folders to the new directory. 2. Make the old component's BUILD and Podspec targets depend on the new component (and nothing else). 3. Delete all implementation files from the old component. 4. Replace the contents of the old component's headers with import statements to the new component's header. If the new component has headers that match the old component's, then the new component's headers will need to be named uniquely for a period of time to allow clients to migrate over. 5. Once all clients have migrated from the old component, delete the old component. This is a breaking change. 6. If you had to create temporary header names in the new component, then in a separate release add the new headers that you want the new component to use. Move the content of the old headers into the new headers and replace the old headers with an import of the new headers. Migrate clients to the desired headers. 7. Once all clients have moved off of the old headers, delete the old headers.
231 lines
9.1 KiB
Objective-C
231 lines
9.1 KiB
Objective-C
// 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 "MaterialButtons+Theming.h"
|
|
#import "MaterialButtons.h"
|
|
#import "MaterialContainerScheme.h"
|
|
#import "MaterialShapeLibrary.h"
|
|
#import "MaterialShapes.h"
|
|
#import "MaterialTypography.h"
|
|
|
|
#import "supplemental/ButtonsTypicalUseSupplemental.h"
|
|
|
|
@interface ButtonsShapesExampleViewController ()
|
|
@property(nonatomic, strong) MDCFloatingButton *floatingButton;
|
|
@end
|
|
|
|
@implementation ButtonsShapesExampleViewController
|
|
|
|
- (id)init {
|
|
self = [super init];
|
|
if (self) {
|
|
self.colorScheme =
|
|
[[MDCSemanticColorScheme alloc] initWithDefaults:MDCColorSchemeDefaultsMaterial201804];
|
|
self.typographyScheme =
|
|
[[MDCTypographyScheme alloc] initWithDefaults:MDCTypographySchemeDefaultsMaterial201804];
|
|
self.containerScheme = [[MDCContainerScheme alloc] init];
|
|
self.containerScheme.colorScheme = self.colorScheme;
|
|
self.containerScheme.shapeScheme =
|
|
[[MDCShapeScheme alloc] initWithDefaults:MDCShapeSchemeDefaultsMaterial201809];
|
|
self.containerScheme.typographyScheme = self.typographyScheme;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (MDCButton *)buildCustomOutlinedButton {
|
|
MDCButton *button = [[MDCButton alloc] init];
|
|
[button setBorderWidth:1.0 forState:UIControlStateNormal];
|
|
[button setBorderColor:[UIColor colorWithWhite:(CGFloat)0.1 alpha:1]
|
|
forState:UIControlStateNormal];
|
|
return button;
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
|
|
self.view.backgroundColor = [UIColor colorWithWhite:(CGFloat)0.9 alpha:1];
|
|
UIColor *titleColor = [UIColor whiteColor];
|
|
|
|
// Raised button
|
|
|
|
MDCButton *containedButton = [[MDCButton alloc] init];
|
|
[containedButton setTitle:@"Add To Cart" forState:UIControlStateNormal];
|
|
[containedButton applyContainedThemeWithScheme:self.containerScheme];
|
|
|
|
UIImage *plusImage = [UIImage imageNamed:@"Plus"];
|
|
plusImage = [plusImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
|
|
[containedButton setImage:plusImage forState:UIControlStateNormal];
|
|
|
|
MDCRectangleShapeGenerator *raisedShapeGenerator = [[MDCRectangleShapeGenerator alloc] init];
|
|
[raisedShapeGenerator setCorners:[[MDCCutCornerTreatment alloc] initWithCut:8]];
|
|
containedButton.shapeGenerator = raisedShapeGenerator;
|
|
|
|
[containedButton sizeToFit];
|
|
[containedButton addTarget:self
|
|
action:@selector(didTap:)
|
|
forControlEvents:UIControlEventTouchUpInside];
|
|
[self.view addSubview:containedButton];
|
|
|
|
// Disabled raised button
|
|
|
|
MDCButton *disabledContainedButton = [[MDCButton alloc] init];
|
|
[disabledContainedButton setTitle:@"Disabled" forState:UIControlStateNormal];
|
|
[disabledContainedButton applyContainedThemeWithScheme:self.containerScheme];
|
|
|
|
MDCRectangleShapeGenerator *disabledRaisedShapeGenerator =
|
|
[[MDCRectangleShapeGenerator alloc] init];
|
|
MDCCurvedCornerTreatment *curvedCorners = [[MDCCurvedCornerTreatment alloc] init];
|
|
curvedCorners.size = CGSizeMake(10, 30);
|
|
[disabledRaisedShapeGenerator setCorners:curvedCorners];
|
|
disabledContainedButton.shapeGenerator = disabledRaisedShapeGenerator;
|
|
|
|
[disabledContainedButton sizeToFit];
|
|
[disabledContainedButton addTarget:self
|
|
action:@selector(didTap:)
|
|
forControlEvents:UIControlEventTouchUpInside];
|
|
[disabledContainedButton setEnabled:NO];
|
|
[self.view addSubview:disabledContainedButton];
|
|
|
|
// Flat button
|
|
|
|
MDCButton *flatButton = [[MDCButton alloc] init];
|
|
[flatButton setTitle:@"Oval Flat" forState:UIControlStateNormal];
|
|
[flatButton applyTextThemeWithScheme:self.containerScheme];
|
|
|
|
MDCPillShapeGenerator *flatShapeGenerator = [[MDCPillShapeGenerator alloc] init];
|
|
flatButton.shapeGenerator = flatShapeGenerator;
|
|
|
|
[flatButton sizeToFit];
|
|
[flatButton addTarget:self
|
|
action:@selector(didTap:)
|
|
forControlEvents:UIControlEventTouchUpInside];
|
|
[self.view addSubview:flatButton];
|
|
|
|
// Custom outlined button
|
|
|
|
MDCButton *outlinedButton = [self buildCustomOutlinedButton];
|
|
[outlinedButton setTitle:@"Button" forState:UIControlStateNormal];
|
|
[outlinedButton applyOutlinedThemeWithScheme:self.containerScheme];
|
|
|
|
MDCSlantedRectShapeGenerator *outlinedShapeGenerator = [[MDCSlantedRectShapeGenerator alloc] init];
|
|
outlinedShapeGenerator.slant = 10;
|
|
outlinedButton.shapeGenerator = outlinedShapeGenerator;
|
|
|
|
[outlinedButton sizeToFit];
|
|
[outlinedButton addTarget:self
|
|
action:@selector(didTap:)
|
|
forControlEvents:UIControlEventTouchUpInside];
|
|
[self.view addSubview:outlinedButton];
|
|
|
|
// Disabled custom outlined button
|
|
|
|
MDCButton *disabledOutlinedButton = [self buildCustomOutlinedButton];
|
|
[disabledOutlinedButton setTitle:@"Button" forState:UIControlStateNormal];
|
|
[disabledOutlinedButton applyOutlinedThemeWithScheme:self.containerScheme];
|
|
|
|
MDCRectangleShapeGenerator *disabledOutlinedShapeGenerator =
|
|
[[MDCRectangleShapeGenerator alloc] init];
|
|
[disabledOutlinedShapeGenerator
|
|
setTopEdge:[[MDCTriangleEdgeTreatment alloc] initWithSize:5 style:MDCTriangleEdgeStyleCut]];
|
|
[disabledOutlinedShapeGenerator setTopLeftCorner:[[MDCCutCornerTreatment alloc] initWithCut:10]];
|
|
[disabledOutlinedShapeGenerator
|
|
setTopRightCorner:[[MDCCurvedCornerTreatment alloc] initWithSize:CGSizeMake(5, 20)]];
|
|
[disabledOutlinedShapeGenerator
|
|
setBottomEdge:[[MDCTriangleEdgeTreatment alloc] initWithSize:5
|
|
style:MDCTriangleEdgeStyleHandle]];
|
|
[disabledOutlinedShapeGenerator
|
|
setBottomRightCorner:[[MDCCutCornerTreatment alloc] initWithCut:5]];
|
|
[disabledOutlinedShapeGenerator
|
|
setBottomLeftCorner:[[MDCCurvedCornerTreatment alloc] initWithSize:CGSizeMake(10, 5)]];
|
|
disabledOutlinedButton.shapeGenerator = disabledOutlinedShapeGenerator;
|
|
|
|
[disabledOutlinedButton sizeToFit];
|
|
[disabledOutlinedButton addTarget:self
|
|
action:@selector(didTap:)
|
|
forControlEvents:UIControlEventTouchUpInside];
|
|
[disabledOutlinedButton setEnabled:NO];
|
|
[self.view addSubview:disabledOutlinedButton];
|
|
|
|
// Floating action button
|
|
|
|
self.floatingButton = [[MDCFloatingButton alloc] init];
|
|
[self.floatingButton setTitleColor:titleColor forState:UIControlStateNormal];
|
|
[self.floatingButton setImageTintColor:UIColor.whiteColor forState:UIControlStateNormal];
|
|
[self.floatingButton setImage:plusImage forState:UIControlStateNormal];
|
|
[self.floatingButton sizeToFit];
|
|
|
|
MDCRectangleShapeGenerator *floatingShapeGenerator = [[MDCRectangleShapeGenerator alloc] init];
|
|
[floatingShapeGenerator
|
|
setCorners:[[MDCCutCornerTreatment alloc]
|
|
initWithCut:CGRectGetWidth(self.floatingButton.bounds) / 2]];
|
|
self.floatingButton.shapeGenerator = floatingShapeGenerator;
|
|
[self.floatingButton applySecondaryThemeWithScheme:self.containerScheme];
|
|
|
|
[self.floatingButton addTarget:self
|
|
action:@selector(didTap:)
|
|
forControlEvents:UIControlEventTouchUpInside];
|
|
[self.view addSubview:self.floatingButton];
|
|
|
|
self.buttons = @[
|
|
containedButton, disabledContainedButton, flatButton, outlinedButton, disabledOutlinedButton,
|
|
self.floatingButton
|
|
];
|
|
|
|
[self setupShapeExampleViews];
|
|
}
|
|
|
|
- (void)setupShapeExampleViews {
|
|
UILabel *raisedButtonLabel = [self addLabelWithText:@"Contained: Cut Corners"];
|
|
UILabel *disabledRaisedButtonLabel = [self addLabelWithText:@"Disabled Contained: Curved Cut"];
|
|
UILabel *flatButtonLabel = [self addLabelWithText:@"Flat: Oval Ink"];
|
|
UILabel *outlinedButtonLabel = [self addLabelWithText:@"Outlined: Triangular"];
|
|
UILabel *disabledOutlinedButtonLabel = [self addLabelWithText:@"Outlined Disabled: Freeform"];
|
|
UILabel *floatingDiamondLabel = [self addLabelWithText:@"Floating Action: Diamond"];
|
|
|
|
self.labels = @[
|
|
raisedButtonLabel, disabledRaisedButtonLabel, flatButtonLabel, outlinedButtonLabel,
|
|
disabledOutlinedButtonLabel, floatingDiamondLabel
|
|
];
|
|
}
|
|
|
|
- (void)didTap:(id)sender {
|
|
NSLog(@"%@ was tapped.", NSStringFromClass([sender class]));
|
|
if (sender == self.floatingButton) {
|
|
[self.floatingButton
|
|
collapse:YES
|
|
completion:^{
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)),
|
|
dispatch_get_main_queue(), ^{
|
|
[self.floatingButton expand:YES completion:nil];
|
|
});
|
|
}];
|
|
}
|
|
}
|
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
[super viewWillAppear:animated];
|
|
if (animated) {
|
|
[self.floatingButton collapse:NO completion:nil];
|
|
}
|
|
}
|
|
|
|
- (void)viewDidAppear:(BOOL)animated {
|
|
[super viewDidAppear:animated];
|
|
if (animated) {
|
|
[self.floatingButton expand:YES completion:nil];
|
|
}
|
|
}
|
|
|
|
@end
|