Skip to content

Commit

Permalink
Merge branch 'release-candidate' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
galiak11 committed Mar 16, 2021
2 parents beea7e6 + 6b168e6 commit 020a956
Show file tree
Hide file tree
Showing 55 changed files with 741 additions and 1,878 deletions.
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
# 124.1.1

In this minor release we added a new Shadow Component and removed the Shrine demo.

## New features

A new Shadow Component.

## API changes

### Shadow

Use the new Shadow component to create a shadow adjusted to your elevation:


```objc
MDCShadow *lowElevationShadow = MDCShadowForElevation(2);
MDCShadow *highElevationShadow = MDCShadowForElevation(24);
```

```swift
let lowElevation = MDCShadowForElevation(2)
let highElevation = MDCShadowForElevation(24)
```

## Component changes

### Shadow

* [New in-development Shadow component (not ready for public use).](https://github.com/material-components/material-components-ios/commit/ff33bab752cb518e46d2a2d4011045d081428b80) (Ben Hamilton)

---

# 124.0.1

This patch release fixes a bug in BottomNavigation.
Expand Down
2 changes: 1 addition & 1 deletion MaterialComponents.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ load 'scripts/generated/icons.rb'

Pod::Spec.new do |mdc|
mdc.name = "MaterialComponents"
mdc.version = "124.0.1"
mdc.version = "124.1.1"
mdc.authors = "The Material Components authors."
mdc.summary = "A collection of stand-alone production-ready UI libraries focused on design details."
mdc.homepage = "https://github.com/material-components/material-components-ios"
Expand Down
2 changes: 1 addition & 1 deletion MaterialComponentsEarlGreyTests.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "MaterialComponentsEarlGreyTests"
s.version = "124.0.1"
s.version = "124.1.1"
s.authors = "The Material Components authors."
s.summary = "This spec is an aggregate of all the Material Components EarlGrey tests."
s.description = "This spec is made for use in the MDC Catalog."
Expand Down
2 changes: 1 addition & 1 deletion MaterialComponentsExamples.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "MaterialComponentsExamples"
s.version = "124.0.1"
s.version = "124.1.1"
s.authors = "The Material Components authors."
s.summary = "This spec is an aggregate of all the Material Components examples."
s.description = "This spec is made for use in the MDC Catalog. Used in conjunction with CatalogByConvention we create our Material Catalog."
Expand Down
2 changes: 1 addition & 1 deletion MaterialComponentsSnapshotTests.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ end

Pod::Spec.new do |s|
s.name = "MaterialComponentsSnapshotTests"
s.version = "124.0.1"
s.version = "124.1.1"
s.authors = "The Material Components authors."
s.summary = "This spec is an aggregate of all the Material Components snapshot tests."
s.homepage = "https://github.com/material-components/material-components-ios"
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
124.0.1
124.1.1
4 changes: 2 additions & 2 deletions catalog/MDCCatalog/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>124.0.1</string>
<string>124.1.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>124.0.1</string>
<string>124.1.1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIAppFonts</key>
Expand Down
4 changes: 2 additions & 2 deletions catalog/MDCDragons/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>124.0.1</string>
<string>124.1.1</string>
<key>CFBundleVersion</key>
<string>124.0.1</string>
<string>124.1.1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
Expand Down
2 changes: 1 addition & 1 deletion catalog/MaterialCatalog/MaterialCatalog.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "MaterialCatalog"
s.version = "124.0.1"
s.version = "124.1.1"
s.summary = "Helper Objective-C classes for the MDC catalog."
s.description = "This spec is made for use in the MDC Catalog."
s.homepage = "https://github.com/material-components/material-components-ios"
Expand Down
2 changes: 1 addition & 1 deletion components/LibraryInfo/src/MDCLibraryInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// This string is updated automatically as a part of the release process and should not be edited
// manually. Do not rename this constant or change the formatting without updating the release
// scripts.
static NSString* const kMDCLibraryInfoVersionString = @"124.0.1";
static NSString* const kMDCLibraryInfoVersionString = @"124.1.1";

@implementation MDCLibraryInfo

Expand Down
2 changes: 1 addition & 1 deletion components/LibraryInfo/tests/unit/LibraryInfoTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ - (void)testVersionFormat {
// Given

// This regex pattern does the following:
// Accept: "124.0.1", etc.
// Accept: "124.1.1", etc.
// Reject: "0.0.0", "1.2", "1", "-1.2.3", "Hi, I'm a version 1.2.3", "1.2.3 is my version", etc.
//
// Note the major version must be >= 1 since "0.0.0" is used as the version when something goes
Expand Down
64 changes: 64 additions & 0 deletions components/Shadow/src/MDCShadow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright 2021-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 <UIKit/UIKit.h>

/**
Immutable value type holding shadow metrics to apply to a view's layer. Use
`MDCShadowForElevation()` or `MDCShadowBuilder` to create this object.
*/
__attribute__((objc_subclassing_restricted)) @interface MDCShadow : NSObject

/** CALayer.shadowOpacity */
@property(nonatomic, readonly) CGFloat opacity;

/** CALayer.shadowRadius */
@property(nonatomic, readonly) CGFloat radius;

/** CALayer.shadowOffset */
@property(nonatomic, readonly) CGSize offset;

- (nonnull instancetype)init NS_UNAVAILABLE;

@end

/**
Mutable builder to construct immutable `MDCShadow` objects.
*/
__attribute__((objc_subclassing_restricted)) @interface MDCShadowBuilder : NSObject

/** CALayer.shadowOpacity */
@property(nonatomic) CGFloat opacity;

/** CALayer.shadowRadius */
@property(nonatomic) CGFloat radius;

/** CALayer.shadowOffset */
@property(nonatomic) CGSize offset;

/** Returns an immutable value type containing a snapshot of the values in this object. */
- (nonnull MDCShadow *)build;

@end

/**
Default color for a Material shadow. On iOS >= 13, this is a dynamic color.
*/
FOUNDATION_EXTERN UIColor *_Nonnull MDCShadowColor(void);

/**
Returns an `MDCShadow` representing the Material shadow metrics for the given elevation (in
points).
*/
FOUNDATION_EXTERN MDCShadow *_Nonnull MDCShadowForElevation(CGFloat elevation);
126 changes: 126 additions & 0 deletions components/Shadow/src/MDCShadow.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// Copyright 2021-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 "MDCShadow.h"

#import "MaterialAvailability.h"
#import "MDCShadow+Internal.h"

@implementation MDCShadow

- (instancetype)initWithOpacity:(CGFloat)opacity radius:(CGFloat)radius offset:(CGSize)offset {
self = [super init];
if (self) {
_opacity = opacity;
_radius = radius;
_offset = offset;
}
return self;
}

- (BOOL)isEqual:(id)other {
if (self == other) {
return YES;
}
if (![other isKindOfClass:[MDCShadow class]]) {
return NO;
}
MDCShadow *otherShadow = other;
return _opacity == otherShadow.opacity && _radius == otherShadow.radius &&
CGSizeEqualToSize(_offset, otherShadow.offset);
}

- (NSUInteger)hash {
const NSUInteger kPrime = 31;
NSUInteger result = 1;
result = result * kPrime + (NSUInteger)_opacity;
result = result * kPrime + (NSUInteger)_radius;
result = result * kPrime + (NSUInteger)(_offset.width);
result = result * kPrime + (NSUInteger)(_offset.height);
return result;
}

@end

@implementation MDCShadowBuilder

- (MDCShadow *)build {
return [[MDCShadow alloc] initWithOpacity:self.opacity radius:self.radius offset:self.offset];
}

@end

static UIColor *LightStyleShadowColor(void) {
static UIColor *lightStyleShadowColor;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
lightStyleShadowColor = [UIColor colorWithRed:0.235 green:0.251 blue:0.263 alpha:1];
});
return lightStyleShadowColor;
}

UIColor *MDCShadowColor(void) {
#if MDC_AVAILABLE_SDK_IOS(13_0)
if (@available(iOS 13.0, *)) {
return [UIColor colorWithDynamicProvider:^(UITraitCollection *traitCollection) {
switch (traitCollection.userInterfaceStyle) {
case UIUserInterfaceStyleUnspecified:
__attribute__((fallthrough));
case UIUserInterfaceStyleLight:
return LightStyleShadowColor();
case UIUserInterfaceStyleDark:
return UIColor.blackColor;
}
__builtin_unreachable();
}];
}
#endif // MDC_AVAILABLE_SDK_IOS(13_0)
return LightStyleShadowColor();
}

static int ShadowElevationToLevel(CGFloat elevation) {
if (elevation < 1) {
return 0;
}
if (elevation < 3) {
return 1;
}
if (elevation < 6) {
return 2;
}
if (elevation < 8) {
return 3;
}
if (elevation < 12) {
return 4;
}
return 5;
}

MDCShadow *MDCShadowForElevation(CGFloat elevation) {
static NSArray *shadowLevels;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
shadowLevels = @[
[[MDCShadow alloc] initWithOpacity:0 radius:0 offset:CGSizeMake(0, 0)],
[[MDCShadow alloc] initWithOpacity:0.43 radius:2.5 offset:CGSizeMake(0, 1)],
[[MDCShadow alloc] initWithOpacity:0.4 radius:3.25 offset:CGSizeMake(0, 1.25)],
[[MDCShadow alloc] initWithOpacity:0.34 radius:4.75 offset:CGSizeMake(0, 2.25)],
[[MDCShadow alloc] initWithOpacity:0.42 radius:6 offset:CGSizeMake(0, 3)],
[[MDCShadow alloc] initWithOpacity:0.4 radius:7.25 offset:CGSizeMake(0, 5)],
];
});
int shadowLevel = ShadowElevationToLevel(elevation);
return shadowLevels[shadowLevel];
}
Loading

0 comments on commit 020a956

Please sign in to comment.