From a9b6ca12b5cba778176b7cb129e866b8669ac8bc Mon Sep 17 00:00:00 2001 From: Nobody Date: Wed, 20 Jan 2021 12:17:24 -0800 Subject: [PATCH 01/11] [Dialogs] Adding customized interface orientations and transition style support to the alert dialog. Adding APIs to customize interface orientations and transition style. PiperOrigin-RevId: 352847879 --- components/Dialogs/src/MDCAlertController.h | 34 +++++++++++++++++-- components/Dialogs/src/MDCAlertController.m | 36 ++++++++++++++------- 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/components/Dialogs/src/MDCAlertController.h b/components/Dialogs/src/MDCAlertController.h index 7898f20d230..fef88628c1f 100644 --- a/components/Dialogs/src/MDCAlertController.h +++ b/components/Dialogs/src/MDCAlertController.h @@ -12,6 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +#import +#import + #import "MaterialButtons.h" // TODO(b/151929968): Delete import of delegate headers when client code has been migrated to no // longer import delegates as transitive dependencies. @@ -19,9 +22,6 @@ #import "MaterialElevation.h" #import "MaterialShadowElevations.h" -#import -#import - @class MDCAlertAction; @class MDCAlertController; @protocol MDCAlertControllerDelegate; @@ -388,6 +388,34 @@ typedef NS_ENUM(NSInteger, MDCContentHorizontalAlignment) { */ @property(nonatomic, assign) BOOL orderVerticalActionsByEmphasis; +/** + A Boolean value that indicates whether the alert's contents autorotates. + + Defaults to UIKit's shouldAutorotate. +*/ +@property(nonatomic) BOOL shouldAutorotateOverride; + +/** + A bit mask that specifies which orientations the view controller supports. + + Defaults to UIKit's supportedInterfaceOrientations. +*/ +@property(nonatomic) UIInterfaceOrientationMask supportedInterfaceOrientationsOverride; + +/** + The interface orientation to use when presenting the alert. + + Defaults to UIKit's preferredInterfaceOrientationForPresentation. +*/ +@property(nonatomic) UIInterfaceOrientation preferredInterfaceOrientationForPresentationOverride; + +/** + The transition style to use when presenting the view controller override. + + Defaults to UIKit's modalTransitionStyle. +*/ +@property(nonatomic) UIModalTransitionStyle modalTransitionStyleOverride; + @end #pragma mark - MDCAlertAction diff --git a/components/Dialogs/src/MDCAlertController.m b/components/Dialogs/src/MDCAlertController.m index a3ad893b94b..04edbbc1e86 100644 --- a/components/Dialogs/src/MDCAlertController.m +++ b/components/Dialogs/src/MDCAlertController.m @@ -12,23 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "MDCAlertController.h" - -#import "MaterialButtons.h" #import "MDCAlertController+Customize.h" -#import "MDCAlertControllerDelegate.h" -#import "MDCAlertControllerView.h" -#import "MDCDialogPresentationController.h" -#import "MDCDialogTransitionController.h" -#import "UIViewController+MaterialDialogs.h" -#import "MaterialTypography.h" -#import "MaterialMath.h" -#import #import "private/MDCAlertActionManager.h" #import "private/MDCAlertControllerView+Private.h" #import "private/MaterialDialogsStrings.h" #import "private/MaterialDialogsStrings_table.h" +#import "MaterialDialogs.h" +#import "MaterialElevation.h" +#import "MaterialShadowElevations.h" +#import "MaterialMath.h" // The Bundle for string resources. static NSString *const kMaterialDialogsBundle = @"MaterialDialogs.bundle"; @@ -180,6 +173,11 @@ - (nonnull instancetype)initWithTitle:(nullable NSString *)title { _adjustsFontForContentSizeCategoryWhenScaledFontIsUnavailable = YES; _shadowColor = UIColor.blackColor; _mdc_overrideBaseElevation = -1; + _shouldAutorotateOverride = super.shouldAutorotate; + _supportedInterfaceOrientationsOverride = super.supportedInterfaceOrientations; + _preferredInterfaceOrientationForPresentationOverride = + super.preferredInterfaceOrientationForPresentation; + _modalTransitionStyleOverride = super.modalTransitionStyle; super.transitioningDelegate = _transitionController; super.modalPresentationStyle = UIModalPresentationCustom; @@ -740,6 +738,22 @@ - (void)viewWillTransitionToSize:(CGSize)size completion:nil]; } +- (BOOL)shouldAutorotate { + return _shouldAutorotateOverride; +} + +- (UIInterfaceOrientationMask)supportedInterfaceOrientations { + return _supportedInterfaceOrientationsOverride; +} + +- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { + return _preferredInterfaceOrientationForPresentationOverride; +} + +- (UIModalTransitionStyle)modalTransitionStyle { + return _modalTransitionStyleOverride; +} + #pragma mark - Resource bundle + (NSBundle *)bundle { From 3f7cc9f51cf9ea9287b3e817bc730eaac31bd87e Mon Sep 17 00:00:00 2001 From: Andrew Overton Date: Thu, 21 Jan 2021 13:10:42 -0800 Subject: [PATCH 02/11] [Chips] Add docs for MDCChipField PiperOrigin-RevId: 353086025 --- components/Chips/src/MDCChipField.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/components/Chips/src/MDCChipField.h b/components/Chips/src/MDCChipField.h index 7c417cd88c4..b293434ad17 100644 --- a/components/Chips/src/MDCChipField.h +++ b/components/Chips/src/MDCChipField.h @@ -58,6 +58,18 @@ typedef NS_OPTIONS(NSUInteger, MDCChipFieldDelimiter) { MDCChipFieldDelimiterAll = 0xFFFFFFFF }; +/** + This class provides an "input chips" experience on iOS, where chip creation is + coordinated with a user's text input. It manages an @c MDCTextField and a series of @c + MDCChipViews. When the user hits the return key, new chips are added. When the client hits the + delete button and the text field has no text, the last chip is deleted. + + @note The input chip experience this class provides is incomplete. For example, it only supports + chips laid out in multiple rows, as opposed to the single-row input chips you'd fine in an email + "to" field. Additionally, it does not theme the chips with the Material chip styles. It is + currently not considered high priority to provide these features, but if you are interested in + them, or any others, please consider filing a bug or reaching out to the Material iOS team. + */ @interface MDCChipField : UIView /** From d5bba14e9a51405ee2ed868fd630d852c49d0c6e Mon Sep 17 00:00:00 2001 From: Yarden Eitan Date: Fri, 22 Jan 2021 12:09:09 -0800 Subject: [PATCH 03/11] [List] Use isKindOfClass to ensure there is support for all MDCShadowLayer's subclasses. PiperOrigin-RevId: 353292179 --- components/List/src/MDCBaseCell.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/List/src/MDCBaseCell.m b/components/List/src/MDCBaseCell.m index 7efcbfca0e8..fa8bc431efc 100644 --- a/components/List/src/MDCBaseCell.m +++ b/components/List/src/MDCBaseCell.m @@ -15,8 +15,10 @@ #import "MDCBaseCell.h" #import "MDCSelfSizingLayoutAttributes.h" +#import "MaterialElevation.h" #import "MaterialInk.h" #import "MaterialRipple.h" +#import "MaterialShadowElevations.h" #import "MaterialShadowLayer.h" @interface MDCBaseCell () @@ -208,7 +210,7 @@ - (UIColor *)rippleColor { } - (MDCShadowLayer *)shadowLayer { - if ([self.layer isMemberOfClass:[MDCShadowLayer class]]) { + if ([self.layer isKindOfClass:[MDCShadowLayer class]]) { return (MDCShadowLayer *)self.layer; } return nil; From c727b890df3c0766706ad8000649f7733cdef997 Mon Sep 17 00:00:00 2001 From: Cody Weaver Date: Fri, 22 Jan 2021 12:11:43 -0800 Subject: [PATCH 04/11] [Buttons] Add documentation for Enums. PiperOrigin-RevId: 353292772 --- components/Buttons/src/MDCFloatingButton+Animation.h | 4 ++++ components/Buttons/src/MDCFloatingButton.h | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/components/Buttons/src/MDCFloatingButton+Animation.h b/components/Buttons/src/MDCFloatingButton+Animation.h index 5b9c53d1689..8b7a360e312 100644 --- a/components/Buttons/src/MDCFloatingButton+Animation.h +++ b/components/Buttons/src/MDCFloatingButton+Animation.h @@ -14,6 +14,10 @@ #import "MDCFloatingButton.h" +/** + This category is used to animate @c MDCFloatingButton instances, to expand or + collapse. + */ @interface MDCFloatingButton (Animation) /** diff --git a/components/Buttons/src/MDCFloatingButton.h b/components/Buttons/src/MDCFloatingButton.h index e23e9e69035..a76414c4f02 100644 --- a/components/Buttons/src/MDCFloatingButton.h +++ b/components/Buttons/src/MDCFloatingButton.h @@ -34,6 +34,11 @@ typedef NS_ENUM(NSInteger, MDCFloatingButtonShape) { MDCFloatingButtonShapeMini = 1 }; +/** + Size of Material Floating button. + + The expanded mode should only be used when text and an icon are used. + */ typedef NS_ENUM(NSInteger, MDCFloatingButtonMode) { /** The floating button is a circle with its contents centered. @@ -46,6 +51,12 @@ typedef NS_ENUM(NSInteger, MDCFloatingButtonMode) { MDCFloatingButtonModeExpanded = 1, }; +/** + Image location of Material Floating button. + + If the button is @c MDCFloatingButtonModeExpanded this determines where the + text is rendered in relation to the icon. + */ typedef NS_ENUM(NSInteger, MDCFloatingButtonImageLocation) { /** The image of the floating button is on the leading side of the title. From 1fefeaf03268b9126dfaea00907a9bb5362560e5 Mon Sep 17 00:00:00 2001 From: Alyssa Weiss Date: Fri, 22 Jan 2021 13:38:23 -0800 Subject: [PATCH 05/11] Add BOOL property for whether or not the height of the bottom sheet should adjust for safe area insets. PiperOrigin-RevId: 353309637 --- .../src/MDCBottomSheetController.h | 10 +++ .../src/MDCBottomSheetController.m | 13 ++++ .../MDCBottomSheetPresentationController.h | 10 +++ .../MDCBottomSheetPresentationController.m | 18 +++++ .../src/MDCBottomSheetTransitionController.h | 10 +++ .../src/MDCBottomSheetTransitionController.m | 7 ++ .../src/private/MDCSheetContainerView.h | 8 ++- .../src/private/MDCSheetContainerView.m | 29 +++++--- .../unit/MDCBottomSheetCustomizationTests.m | 63 +++++++++++++++- ...DCBottomSheetPresentationControllerTests.m | 72 +++++++++++++++++++ 10 files changed, 229 insertions(+), 11 deletions(-) diff --git a/components/BottomSheet/src/MDCBottomSheetController.h b/components/BottomSheet/src/MDCBottomSheetController.h index fa4d065f702..e6b806cc282 100644 --- a/components/BottomSheet/src/MDCBottomSheetController.h +++ b/components/BottomSheet/src/MDCBottomSheetController.h @@ -121,6 +121,16 @@ */ @property(nonatomic, assign) MDCShadowElevation elevation; +/** + Whether or not the height of the bottom sheet should adjust to include extra height for any bottom + safe area insets. If, for example, this is set to @c YES, and the preferred content size height is + 100 and the screen has a bottom safe area inset of 10, the total height of the displayed bottom + sheet height would be 110. If set to @c NO, the height would be 100. + + Defaults to @c YES. + */ +@property(nonatomic, assign) BOOL adjustHeightForSafeAreaInsets; + /** Bottom sheet controllers must be created with @c initWithContentViewController:. */ diff --git a/components/BottomSheet/src/MDCBottomSheetController.m b/components/BottomSheet/src/MDCBottomSheetController.m index 9fa68e9f3b2..eb1e1c000eb 100644 --- a/components/BottomSheet/src/MDCBottomSheetController.m +++ b/components/BottomSheet/src/MDCBottomSheetController.m @@ -18,7 +18,11 @@ #import "MDCBottomSheetPresentationController.h" #import "MDCBottomSheetPresentationControllerDelegate.h" #import "MDCBottomSheetTransitionController.h" +#import "MDCSheetState.h" #import "UIViewController+MaterialBottomSheet.h" +#import "MaterialElevation.h" +#import "MaterialShadowElevations.h" +#import "MaterialShapes.h" #import "MaterialMath.h" static const CGFloat kElevationSpreadMaskAffordance = 50.0f; @@ -48,6 +52,7 @@ - (nonnull instancetype)initWithContentViewController: _transitionController = [[MDCBottomSheetTransitionController alloc] init]; _transitionController.dismissOnBackgroundTap = YES; _transitionController.dismissOnDraggingDownSheet = YES; + _transitionController.adjustHeightForSafeAreaInsets = YES; super.transitioningDelegate = _transitionController; super.modalPresentationStyle = UIModalPresentationCustom; _shapeGenerators = [NSMutableDictionary dictionary]; @@ -269,6 +274,14 @@ - (UIColor *)scrimColor { return _transitionController.scrimColor; } +- (void)setAdjustHeightForSafeAreaInsets:(BOOL)adjustHeightForSafeAreaInsets { + _transitionController.adjustHeightForSafeAreaInsets = adjustHeightForSafeAreaInsets; +} + +- (BOOL)adjustHeightForSafeAreaInsets { + return _transitionController.adjustHeightForSafeAreaInsets; +} + - (void)setIsScrimAccessibilityElement:(BOOL)isScrimAccessibilityElement { _transitionController.isScrimAccessibilityElement = isScrimAccessibilityElement; } diff --git a/components/BottomSheet/src/MDCBottomSheetPresentationController.h b/components/BottomSheet/src/MDCBottomSheetPresentationController.h index eded9683b38..0bf90bd9039 100644 --- a/components/BottomSheet/src/MDCBottomSheetPresentationController.h +++ b/components/BottomSheet/src/MDCBottomSheetPresentationController.h @@ -68,6 +68,16 @@ */ @property(nonatomic, assign) CGFloat preferredSheetHeight; +/** +Whether or not the height of the bottom sheet should adjust to include extra height for any bottom +safe area insets. If, for example, this is set to @c YES, and the preferredSheetHeight is +100 and the screen has a bottom safe area inset of 10, the total height of the displayed bottom +sheet height would be 110. If set to @c NO, the height would be 100. + +Defaults to @c YES. +*/ +@property(nonatomic, assign) BOOL adjustHeightForSafeAreaInsets; + /** Customize the color of the background scrim. diff --git a/components/BottomSheet/src/MDCBottomSheetPresentationController.m b/components/BottomSheet/src/MDCBottomSheetPresentationController.m index 297c4446f40..d6ae0dbf26e 100644 --- a/components/BottomSheet/src/MDCBottomSheetPresentationController.m +++ b/components/BottomSheet/src/MDCBottomSheetPresentationController.m @@ -68,6 +68,16 @@ @implementation MDCBottomSheetPresentationController { @synthesize delegate; +- (instancetype)initWithPresentedViewController:(UIViewController *)presentedViewController + presentingViewController:(UIViewController *)presentingViewController { + self = [super initWithPresentedViewController:presentedViewController + presentingViewController:presentingViewController]; + if (self) { + _adjustHeightForSafeAreaInsets = YES; + } + return self; +} + - (UIView *)presentedView { return self.sheetView; } @@ -126,6 +136,7 @@ - (void)presentationTransitionWillBegin { self.sheetView.delegate = self; self.sheetView.autoresizingMask = UIViewAutoresizingFlexibleHeight; self.sheetView.dismissOnDraggingDownSheet = self.dismissOnDraggingDownSheet; + self.sheetView.adjustHeightForSafeAreaInsets = self.adjustHeightForSafeAreaInsets; [containerView addSubview:_dimmingView]; [containerView addSubview:self.sheetView]; @@ -301,6 +312,13 @@ - (void)setPreferredSheetHeight:(CGFloat)preferredSheetHeight { [self updatePreferredSheetHeight]; } +- (void)setAdjustHeightForSafeAreaInsets:(BOOL)adjustHeightForSafeAreaInsets { + _adjustHeightForSafeAreaInsets = adjustHeightForSafeAreaInsets; + if (_sheetView) { + _sheetView.adjustHeightForSafeAreaInsets = adjustHeightForSafeAreaInsets; + } +} + - (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection { [super traitCollectionDidChange:previousTraitCollection]; diff --git a/components/BottomSheet/src/MDCBottomSheetTransitionController.h b/components/BottomSheet/src/MDCBottomSheetTransitionController.h index 4322750fcde..c2d72108812 100644 --- a/components/BottomSheet/src/MDCBottomSheetTransitionController.h +++ b/components/BottomSheet/src/MDCBottomSheetTransitionController.h @@ -63,6 +63,16 @@ */ @property(nonatomic, assign) CGFloat preferredSheetHeight; +/** +Whether or not the height of the bottom sheet should adjust to include extra height for any bottom +safe area insets. If, for example, this is set to @c YES, and the preferred content size height is +100 and the screen has a bottom safe area inset of 10, the total height of the displayed bottom +sheet height would be 110. If set to @c NO, the height would be 100. + +Defaults to @c YES. +*/ +@property(nonatomic, assign) BOOL adjustHeightForSafeAreaInsets; + @end @interface MDCBottomSheetTransitionController (ScrimAccessibility) diff --git a/components/BottomSheet/src/MDCBottomSheetTransitionController.m b/components/BottomSheet/src/MDCBottomSheetTransitionController.m index 55a6d5f00ca..5e1eef3ae50 100644 --- a/components/BottomSheet/src/MDCBottomSheetTransitionController.m +++ b/components/BottomSheet/src/MDCBottomSheetTransitionController.m @@ -42,6 +42,7 @@ - (instancetype)init { self = [super init]; if (self) { _scrimAccessibilityTraits = UIAccessibilityTraitButton; + _adjustHeightForSafeAreaInsets = YES; } return self; } @@ -62,6 +63,7 @@ - (instancetype)init { presentationController.scrimAccessibilityHint = _scrimAccessibilityHint; presentationController.scrimAccessibilityLabel = _scrimAccessibilityLabel; presentationController.preferredSheetHeight = _preferredSheetHeight; + presentationController.adjustHeightForSafeAreaInsets = _adjustHeightForSafeAreaInsets; _currentPresentationController = presentationController; return presentationController; } @@ -170,6 +172,11 @@ - (UIColor *)scrimColor { return _scrimColor; } +- (void)setAdjustHeightForSafeAreaInsets:(BOOL)adjustHeightForSafeAreaInsets { + _adjustHeightForSafeAreaInsets = adjustHeightForSafeAreaInsets; + _currentPresentationController.adjustHeightForSafeAreaInsets = adjustHeightForSafeAreaInsets; +} + - (void)setIsScrimAccessibilityElement:(BOOL)isScrimAccessibilityElement { _isScrimAccessibilityElement = isScrimAccessibilityElement; _currentPresentationController.isScrimAccessibilityElement = isScrimAccessibilityElement; diff --git a/components/BottomSheet/src/private/MDCSheetContainerView.h b/components/BottomSheet/src/private/MDCSheetContainerView.h index 31f2d084d18..662eec2823f 100644 --- a/components/BottomSheet/src/private/MDCSheetContainerView.h +++ b/components/BottomSheet/src/private/MDCSheetContainerView.h @@ -22,6 +22,13 @@ @property(nonatomic, weak, nullable) id delegate; @property(nonatomic, readonly) MDCSheetState sheetState; @property(nonatomic) CGFloat preferredSheetHeight; +/** +Whether or not the height of the view should adjust to include extra height for any bottom + safe area insets. If, for example, this is set to @c YES, and the preferredSheetHeight is + 100 and the screen has a bottom safe area inset of 10, the total height of the displayed bottom + sheet height would be 110. If set to @c NO, the height would be 100. + */ +@property(nonatomic, assign) BOOL adjustHeightForSafeAreaInsets; @property(nonatomic) BOOL willBeDismissed; /** @@ -37,4 +44,3 @@ - (nullable instancetype)initWithCoder:(nullable NSCoder *)aDecoder NS_UNAVAILABLE; @end - diff --git a/components/BottomSheet/src/private/MDCSheetContainerView.m b/components/BottomSheet/src/private/MDCSheetContainerView.m index 5193092fb95..8a808be9093 100644 --- a/components/BottomSheet/src/private/MDCSheetContainerView.m +++ b/components/BottomSheet/src/private/MDCSheetContainerView.m @@ -172,12 +172,13 @@ - (void)safeAreaInsetsDidChange { if (@available(iOS 11.0, *)) { [super safeAreaInsetsDidChange]; - _preferredSheetHeight = self.originalPreferredSheetHeight + self.safeAreaInsets.bottom; - - UIEdgeInsets contentInset = self.sheet.scrollView.contentInset; - contentInset.bottom = MAX(contentInset.bottom, self.safeAreaInsets.bottom); - self.sheet.scrollView.contentInset = contentInset; + if (self.adjustHeightForSafeAreaInsets) { + _preferredSheetHeight = self.originalPreferredSheetHeight + self.safeAreaInsets.bottom; + UIEdgeInsets contentInset = self.sheet.scrollView.contentInset; + contentInset.bottom = MAX(contentInset.bottom, self.safeAreaInsets.bottom); + self.sheet.scrollView.contentInset = contentInset; + } CGRect scrollViewFrame = CGRectStandardize(self.sheet.scrollView.frame); scrollViewFrame.size = CGSizeMake(scrollViewFrame.size.width, CGRectGetHeight(self.frame)); self.sheet.scrollView.frame = scrollViewFrame; @@ -219,12 +220,12 @@ - (void)layoutSubviews { } } -- (void)setPreferredSheetHeight:(CGFloat)preferredSheetHeight { - self.originalPreferredSheetHeight = preferredSheetHeight; - +- (void)updateSheetHeight { CGFloat adjustedPreferredSheetHeight = self.originalPreferredSheetHeight; if (@available(iOS 11.0, *)) { - adjustedPreferredSheetHeight += self.safeAreaInsets.bottom; + if (self.adjustHeightForSafeAreaInsets) { + adjustedPreferredSheetHeight += self.safeAreaInsets.bottom; + } } if (_preferredSheetHeight == adjustedPreferredSheetHeight) { @@ -240,6 +241,16 @@ - (void)setPreferredSheetHeight:(CGFloat)preferredSheetHeight { } } +- (void)setPreferredSheetHeight:(CGFloat)preferredSheetHeight { + self.originalPreferredSheetHeight = preferredSheetHeight; + [self updateSheetHeight]; +} + +- (void)setAdjustHeightForSafeAreaInsets:(BOOL)adjustHeightForSafeAreaInsets { + _adjustHeightForSafeAreaInsets = adjustHeightForSafeAreaInsets; + [self updateSheetHeight]; +} + // Slides the sheet position downwards, so the right amount peeks above the bottom of the superview. - (void)updateSheetFrame { [self.animator removeAllBehaviors]; diff --git a/components/BottomSheet/tests/unit/MDCBottomSheetCustomizationTests.m b/components/BottomSheet/tests/unit/MDCBottomSheetCustomizationTests.m index 8313a680702..787bd07bbfe 100644 --- a/components/BottomSheet/tests/unit/MDCBottomSheetCustomizationTests.m +++ b/components/BottomSheet/tests/unit/MDCBottomSheetCustomizationTests.m @@ -17,7 +17,6 @@ #import #import "../../src/private/MDCSheetContainerView.h" -#import "MaterialShadowElevations.h" /** Used to test the elevation @c MDCBottomSheetPresentationController and it's @c sheetView. */ @interface MDCBottomSheetPresentationController (MDCElevationTesting) @@ -93,4 +92,66 @@ - (void)testApplyingScrimColorToSheet { XCTAssertEqualObjects(self.presentationController.scrimColor, scrimColor); } +// Test that the presentation controller's and sheet view's adjustHeightForSafeAreaInsets is set to +// YES as the default. +- (void)testDefaultadjustHeightForSafeAreaInsetsSheet { + // When + // Ensure that the presentation controller is allocated after the bottom sheet because the + // property is set on the presentation controller via the transition controller which keeps + // references to the properties it sets on the presentaiton controller but not the presentation + // conrollter itself. + self.presentationController = self.bottomSheet.mdc_bottomSheetPresentationController; + + // Ensure that the bottom sheet has created all of the necessary internal storage for + // presentation by pretending to start the presentation. + [self.presentationController presentationTransitionWillBegin]; + + // Then + XCTAssertTrue(self.bottomSheet.adjustHeightForSafeAreaInsets); + XCTAssertTrue(self.presentationController.adjustHeightForSafeAreaInsets); + XCTAssertTrue(self.presentationController.sheetView.adjustHeightForSafeAreaInsets); +} + +// Test that the presentation controller's and sheet view's adjustHeightForSafeAreaInsets is set to +// NO when it is set on the sheet. +- (void)testSettingadjustHeightForSafeAreaInsetsSheetNo { + // When + self.bottomSheet.adjustHeightForSafeAreaInsets = NO; + + // Ensure that the presentation controller is allocated after the bottom sheet because the + // property is set on the presentation controller via the transition controller which keeps + // references to the properties it sets on the presentaiton controller but not the presentation + // conrollter itself. + self.presentationController = self.bottomSheet.mdc_bottomSheetPresentationController; + + // Ensure that the bottom sheet has created all of the necessary internal storage for + // presentation by pretending to start the presentation. + [self.presentationController presentationTransitionWillBegin]; + + // Then + XCTAssertFalse(self.presentationController.adjustHeightForSafeAreaInsets); + XCTAssertFalse(self.presentationController.sheetView.adjustHeightForSafeAreaInsets); +} + +// Test that the presentation controller's and sheet view's adjustHeightForSafeAreaInsets is set to +// YES when it is set on the sheet. +- (void)testSettingadjustHeightForSafeAreaInsetsSheetYes { + // When + self.bottomSheet.adjustHeightForSafeAreaInsets = YES; + + // Ensure that the presentation controller is allocated after the bottom sheet because the + // property is set on the presentation controller via the transition controller which keeps + // references to the properties it sets on the presentaiton controller but not the presentation + // conrollter itself. + self.presentationController = self.bottomSheet.mdc_bottomSheetPresentationController; + + // Ensure that the bottom sheet has created all of the necessary internal storage for + // presentation by pretending to start the presentation. + [self.presentationController presentationTransitionWillBegin]; + + // Then + XCTAssertTrue(self.presentationController.adjustHeightForSafeAreaInsets); + XCTAssertTrue(self.presentationController.sheetView.adjustHeightForSafeAreaInsets); +} + @end diff --git a/components/BottomSheet/tests/unit/MDCBottomSheetPresentationControllerTests.m b/components/BottomSheet/tests/unit/MDCBottomSheetPresentationControllerTests.m index 1720274eb1a..4fea4a447aa 100644 --- a/components/BottomSheet/tests/unit/MDCBottomSheetPresentationControllerTests.m +++ b/components/BottomSheet/tests/unit/MDCBottomSheetPresentationControllerTests.m @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#import "MDCSheetState.h" #import "MaterialBottomSheet.h" #import @@ -72,6 +73,7 @@ - (void)draggableView:(MDCDraggableView *)view draggingEndedWithVelocity:(CGPoin @c setFrame: in case there are side-effects in UIView. */ @interface FakeSheetView : MDCSheetContainerView +@property(nonatomic, assign) UIEdgeInsets customSafeAreaInsets; @end @implementation FakeSheetView { @@ -87,6 +89,10 @@ - (void)setFrame:(CGRect)frame { _frame = frame; } + +- (UIEdgeInsets)safeAreaInsets { + return _customSafeAreaInsets; +} @end @interface MDCBottomSheetPresentationControllerTests : XCTestCase @@ -273,6 +279,72 @@ - (void)testVeryLargePreferredSheetHeightAndSmallContent { XCTAssertEqualWithAccuracy(CGRectGetHeight(sheetView.frame), CGRectGetHeight(smallFrame), 0.001); } +- (void)testDefaultAdjustHeightForSafeAreaInsets { + XCTAssertTrue(self.presentationController.adjustHeightForSafeAreaInsets); +} + +- (void)testAdjustHeightForSafeAreaInsetsIsNo { + // Given + CGFloat preferredSheetHeight = 200; + CGFloat inset = 20; + self.sheetView.customSafeAreaInsets = UIEdgeInsetsMake(inset, inset, inset, inset); + self.presentationController.preferredSheetHeight = preferredSheetHeight; + self.presentationController.adjustHeightForSafeAreaInsets = NO; + + // When + [self.presentationController updatePreferredSheetHeight]; + + // Then + XCTAssertEqualWithAccuracy(self.sheetView.preferredSheetHeight, preferredSheetHeight, 0.001); +} + +- (void)testAdjustHeightForSafeAreaInsetsSetBeforeHeightIsSet { + // Given + CGFloat preferredSheetHeight = 200; + CGFloat inset = 20; + self.sheetView.customSafeAreaInsets = UIEdgeInsetsMake(inset, inset, inset, inset); + self.presentationController.adjustHeightForSafeAreaInsets = NO; + self.presentationController.preferredSheetHeight = preferredSheetHeight; + + // When + [self.presentationController updatePreferredSheetHeight]; + + // Then + XCTAssertEqualWithAccuracy(self.sheetView.preferredSheetHeight, preferredSheetHeight, 0.001); +} + +- (void)testAdjustHeightForSafeAreaInsetsIsYes { + // Given + CGFloat preferredSheetHeight = 200; + CGFloat inset = 20; + self.sheetView.customSafeAreaInsets = UIEdgeInsetsMake(inset, inset, inset, inset); + self.presentationController.preferredSheetHeight = preferredSheetHeight; + self.presentationController.adjustHeightForSafeAreaInsets = YES; + + // When + [self.presentationController updatePreferredSheetHeight]; + + // Then + XCTAssertEqualWithAccuracy(self.sheetView.preferredSheetHeight, preferredSheetHeight + inset, + 0.001); +} + +- (void)testadjustHeightForSafeAreaInsetsChangesToNo { + // Given + CGFloat preferredSheetHeight = 200; + CGFloat inset = 20; + self.sheetView.customSafeAreaInsets = UIEdgeInsetsMake(inset, inset, inset, inset); + self.presentationController.adjustHeightForSafeAreaInsets = YES; + self.presentationController.preferredSheetHeight = preferredSheetHeight; + self.presentationController.adjustHeightForSafeAreaInsets = NO; + + // When + [self.presentationController updatePreferredSheetHeight]; + + // Then + XCTAssertEqualWithAccuracy(self.sheetView.preferredSheetHeight, preferredSheetHeight, 0.001); +} + - (void)testSheetViewFrameMatchesScrollViewFrame { // Given CGFloat scrollViewHeight = 100; From 1b70fd6ad949c143d7225e3719c912fce8181719 Mon Sep 17 00:00:00 2001 From: Andrew Overton Date: Fri, 22 Jan 2021 13:50:57 -0800 Subject: [PATCH 06/11] [ProgressView] Add Objective-C generics to MDCProgressView PiperOrigin-RevId: 353312272 --- components/ProgressView/src/MDCProgressView.h | 2 +- components/ProgressView/src/MDCProgressView.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/ProgressView/src/MDCProgressView.h b/components/ProgressView/src/MDCProgressView.h index ea943c246ac..ef54877c7a3 100644 --- a/components/ProgressView/src/MDCProgressView.h +++ b/components/ProgressView/src/MDCProgressView.h @@ -56,7 +56,7 @@ IB_DESIGNABLE The default is nil. */ -@property(nonatomic, copy, nullable) NSArray *progressTintColors; +@property(nonatomic, copy, nullable) NSArray *progressTintColors; /** The color shown for the portion of the progress view that is not filled. diff --git a/components/ProgressView/src/MDCProgressView.m b/components/ProgressView/src/MDCProgressView.m index 0beb13b1171..1da69dd46e7 100644 --- a/components/ProgressView/src/MDCProgressView.m +++ b/components/ProgressView/src/MDCProgressView.m @@ -140,7 +140,7 @@ - (void)setProgressTintColor:(UIColor *)progressTintColor { } } -- (void)setProgressTintColors:(NSArray *)progressTintColors { +- (void)setProgressTintColors:(NSArray *)progressTintColors { _progressTintColors = [progressTintColors copy]; _progressTintColor = nil; self.progressView.colors = _progressTintColors; From 1b985100ec89ed142981bd8f3d51b247f88e6f0c Mon Sep 17 00:00:00 2001 From: Andrew Overton Date: Mon, 25 Jan 2021 07:12:16 -0800 Subject: [PATCH 07/11] [BottomSheet] Add flag that turns off simulated bouncing when there isn't a tracking scroll view PiperOrigin-RevId: 353639927 --- .../MDCBottomSheetPresentationController.h | 10 +++++ .../MDCBottomSheetPresentationController.m | 4 +- .../src/private/MDCDraggableView.h | 7 +++ .../src/private/MDCDraggableView.m | 43 ++++++++++++------- .../src/private/MDCSheetBehavior.h | 6 ++- .../src/private/MDCSheetBehavior.m | 21 +++++++-- .../src/private/MDCSheetContainerView.h | 3 +- .../src/private/MDCSheetContainerView.m | 21 +++++---- ...DCBottomSheetPresentationControllerTests.m | 9 ++-- 9 files changed, 91 insertions(+), 33 deletions(-) diff --git a/components/BottomSheet/src/MDCBottomSheetPresentationController.h b/components/BottomSheet/src/MDCBottomSheetPresentationController.h index 0bf90bd9039..90a2fecc10e 100644 --- a/components/BottomSheet/src/MDCBottomSheetPresentationController.h +++ b/components/BottomSheet/src/MDCBottomSheetPresentationController.h @@ -35,6 +35,16 @@ */ @property(nonatomic, weak, nullable) UIScrollView *trackingScrollView; +/** + When @c trackingScrollView is @c nil and this property is @ YES, the bottom sheet simulates the @c + UIScrollView bouncing effect. When @c trackingScrollView is @c nil and this property is set to @c + NO, the simulated bouncing effect is turned off. When @c trackingScrollView is NOT @c nil, this + property doesn't do anything. + + Defaults to @c YES. + */ +@property(nonatomic, assign) BOOL simulateScrollViewBounce; + /** When set to false, the bottom sheet controller can't be dismissed by tapping outside of sheet area. */ diff --git a/components/BottomSheet/src/MDCBottomSheetPresentationController.m b/components/BottomSheet/src/MDCBottomSheetPresentationController.m index d6ae0dbf26e..c30e3a4cc52 100644 --- a/components/BottomSheet/src/MDCBottomSheetPresentationController.m +++ b/components/BottomSheet/src/MDCBottomSheetPresentationController.m @@ -74,6 +74,7 @@ - (instancetype)initWithPresentedViewController:(UIViewController *)presentedVie presentingViewController:presentingViewController]; if (self) { _adjustHeightForSafeAreaInsets = YES; + _simulateScrollViewBounce = YES; } return self; } @@ -132,7 +133,8 @@ - (void)presentationTransitionWillBegin { } self.sheetView = [[MDCSheetContainerView alloc] initWithFrame:sheetFrame contentView:self.presentedViewController.view - scrollView:scrollView]; + scrollView:scrollView + simulateScrollViewBounce:self.simulateScrollViewBounce]; self.sheetView.delegate = self; self.sheetView.autoresizingMask = UIViewAutoresizingFlexibleHeight; self.sheetView.dismissOnDraggingDownSheet = self.dismissOnDraggingDownSheet; diff --git a/components/BottomSheet/src/private/MDCDraggableView.h b/components/BottomSheet/src/private/MDCDraggableView.h index db8905b91c8..4dc008e7e0e 100644 --- a/components/BottomSheet/src/private/MDCDraggableView.h +++ b/components/BottomSheet/src/private/MDCDraggableView.h @@ -23,6 +23,13 @@ */ @property(nonatomic, strong, readonly, nullable) UIScrollView *scrollView; +/** + When @c scrollView is @c nil , the draggable view simulates the @c UIScrollView bouncing effect. + When this property is set to @c NO, the simulated bouncing effect is turned off. When @c + scrollView is not @c nil, this property doesn't do anything. + */ +@property(nonatomic, assign) BOOL simulateScrollViewBounce; + /** * Delegate for handling drag events. */ diff --git a/components/BottomSheet/src/private/MDCDraggableView.m b/components/BottomSheet/src/private/MDCDraggableView.m index 6a679cb8e9c..534615d0112 100644 --- a/components/BottomSheet/src/private/MDCDraggableView.m +++ b/components/BottomSheet/src/private/MDCDraggableView.m @@ -15,6 +15,7 @@ #import "MDCDraggableView.h" #import "MDCDraggableViewDelegate.h" +#import "MDCKeyboardWatcher.h" static void CancelGestureRecognizer(UIGestureRecognizer *gesture) { if (gesture.enabled) { @@ -28,6 +29,7 @@ static void CancelGestureRecognizer(UIGestureRecognizer *gesture) { @interface MDCDraggableView () @property(nonatomic) UIPanGestureRecognizer *dragRecognizer; @property(nonatomic, strong) UIScrollView *scrollView; +@property(nonatomic, assign) CGFloat mostRecentMinY; @end @implementation MDCDraggableView @@ -50,30 +52,39 @@ - (instancetype)initWithFrame:(CGRect)frame scrollView:(UIScrollView *)scrollVie #pragma mark - Gesture handling - (void)didPan:(UIPanGestureRecognizer *)recognizer { - CGPoint point = [recognizer translationInView:self.superview]; - - // Ensure that dragging the sheet past the maximum height results in an exponential decay on the - // translation. This gives the same effect as when you overscroll a scrollview. - CGFloat newHeight = CGRectGetMaxY(self.superview.bounds) - CGRectGetMinY(self.frame); - if (newHeight > [self.delegate maximumHeightForDraggableView:self]) { - point.y -= point.y / (CGFloat)1.2; + if (recognizer.state == UIGestureRecognizerStateBegan) { + self.mostRecentMinY = CGRectGetMinY(self.frame); + [self.delegate draggableViewBeganDragging:self]; + return; } - self.center = CGPointMake(self.center.x, self.center.y + point.y); - [recognizer setTranslation:CGPointZero inView:self.superview]; - CGPoint velocity = [recognizer velocityInView:self.superview]; velocity.x = 0; + CGPoint translation = [recognizer translationInView:self.superview]; + CGFloat maxHeight = [self.delegate maximumHeightForDraggableView:self]; + CGFloat minimumStableMinY = CGRectGetHeight(self.superview.bounds) - maxHeight - + [MDCKeyboardWatcher sharedKeyboardWatcher].visibleKeyboardHeight; + CGFloat newMinY = self.mostRecentMinY + translation.y; + + if (newMinY < minimumStableMinY) { + if ((self.scrollView == nil) && !self.simulateScrollViewBounce) { + velocity = CGPointZero; + newMinY = minimumStableMinY; + } else { + // Ensure that dragging the sheet past the maximum height results in an exponential decay on + // the translation. This gives the same effect as when you overscroll a scrollview. + newMinY = minimumStableMinY + (translation.y - (translation.y / 1.2f)); + } + } + CGRect newFrame = CGRectMake(CGRectGetMinX(self.frame), newMinY, CGRectGetWidth(self.frame), + CGRectGetHeight(self.frame)); - if (recognizer.state == UIGestureRecognizerStateBegan) { - [self.delegate draggableViewBeganDragging:self]; + if (recognizer.state == UIGestureRecognizerStateChanged) { + self.frame = newFrame; + [self.delegate draggableView:self didPanToOffset:CGRectGetMinY(self.frame)]; } else if (recognizer.state == UIGestureRecognizerStateEnded) { [self.delegate draggableView:self draggingEndedWithVelocity:velocity]; } - if (recognizer.state == UIGestureRecognizerStateBegan || - recognizer.state == UIGestureRecognizerStateChanged) { - [self.delegate draggableView:self didPanToOffset:CGRectGetMinY(self.frame)]; - } } #pragma mark - UIGestureRecognizerDelegate diff --git a/components/BottomSheet/src/private/MDCSheetBehavior.h b/components/BottomSheet/src/private/MDCSheetBehavior.h index ceaa4b721bc..a6cb731ec5b 100644 --- a/components/BottomSheet/src/private/MDCSheetBehavior.h +++ b/components/BottomSheet/src/private/MDCSheetBehavior.h @@ -29,8 +29,12 @@ /** * Initializes a @c MDCSheetBehavior. * @param item The dynamic item (a view) to apply the sheet behavior to. + * @param simulateScrollViewBounce If the user has specified that they do not want to simulate the + * scrollview bouncing in the absence of a bottom sheet's trackingScrollView we should also tone + * down the bounce effect the UIKit dynamics provide. */ -- (nonnull instancetype)initWithItem:(nonnull id)item NS_DESIGNATED_INITIALIZER; +- (nonnull instancetype)initWithItem:(nonnull id)item + simulateScrollViewBounce:(BOOL)simulateScrollViewBounce NS_DESIGNATED_INITIALIZER; - (nonnull instancetype)init NS_UNAVAILABLE; diff --git a/components/BottomSheet/src/private/MDCSheetBehavior.m b/components/BottomSheet/src/private/MDCSheetBehavior.m index aa5fb28d087..d11274c0929 100644 --- a/components/BottomSheet/src/private/MDCSheetBehavior.m +++ b/components/BottomSheet/src/private/MDCSheetBehavior.m @@ -14,6 +14,15 @@ #import "MDCSheetBehavior.h" +/** + These values were arrived at empirically (through trial and error) to either emphasize or diminish + the bounce effect that UIKit dynamics provides. + */ +static const CGFloat kSimulateScrollViewBounceFrequency = 3.5f; +static const CGFloat kSimulateScrollViewBounceDamping = 0.4f; +static const CGFloat kDisableScrollViewBounceFrequency = 5.5f; +static const CGFloat kDisableScrollViewBounceDamping = 1.0f; + @interface MDCSheetBehavior () @property(nonatomic) UIAttachmentBehavior *attachmentBehavior; @property(nonatomic) UIDynamicItemBehavior *itemBehavior; @@ -22,14 +31,20 @@ @interface MDCSheetBehavior () @implementation MDCSheetBehavior -- (instancetype)initWithItem:(id)item { +- (instancetype)initWithItem:(id)item + simulateScrollViewBounce:(BOOL)simulateScrollViewBounce { self = [super init]; if (self) { _item = item; _attachmentBehavior = [[UIAttachmentBehavior alloc] initWithItem:self.item attachedToAnchor:CGPointZero]; - _attachmentBehavior.frequency = (CGFloat)3.5; - _attachmentBehavior.damping = (CGFloat)0.4; + if (simulateScrollViewBounce) { + _attachmentBehavior.frequency = kSimulateScrollViewBounceFrequency; + _attachmentBehavior.damping = kSimulateScrollViewBounceDamping; + } else { + _attachmentBehavior.frequency = kDisableScrollViewBounceFrequency; + _attachmentBehavior.damping = kDisableScrollViewBounceDamping; + } _attachmentBehavior.length = 0; // Anchor movement along the y-axis. diff --git a/components/BottomSheet/src/private/MDCSheetContainerView.h b/components/BottomSheet/src/private/MDCSheetContainerView.h index 662eec2823f..220466be13e 100644 --- a/components/BottomSheet/src/private/MDCSheetContainerView.h +++ b/components/BottomSheet/src/private/MDCSheetContainerView.h @@ -38,7 +38,8 @@ Whether or not the height of the view should adjust to include extra height for - (nonnull instancetype)initWithFrame:(CGRect)frame contentView:(nonnull UIView *)contentView - scrollView:(nullable UIScrollView *)scrollView NS_DESIGNATED_INITIALIZER; + scrollView:(nullable UIScrollView *)scrollView + simulateScrollViewBounce:(BOOL)simulateScrollViewBounce NS_DESIGNATED_INITIALIZER; - (nonnull instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE; - (nullable instancetype)initWithCoder:(nullable NSCoder *)aDecoder NS_UNAVAILABLE; diff --git a/components/BottomSheet/src/private/MDCSheetContainerView.m b/components/BottomSheet/src/private/MDCSheetContainerView.m index 8a808be9093..21188b043a3 100644 --- a/components/BottomSheet/src/private/MDCSheetContainerView.m +++ b/components/BottomSheet/src/private/MDCSheetContainerView.m @@ -43,6 +43,7 @@ @interface MDCSheetContainerView () @property(nonatomic) BOOL isDragging; @property(nonatomic) CGFloat originalPreferredSheetHeight; @property(nonatomic) CGRect previousAnimatedBounds; +@property(nonatomic) BOOL simulateScrollViewBounce; @end @@ -58,10 +59,12 @@ + (void)initialize { - (instancetype)initWithFrame:(CGRect)frame contentView:(UIView *)contentView - scrollView:(UIScrollView *)scrollView { + scrollView:(UIScrollView *)scrollView + simulateScrollViewBounce:(BOOL)simulateScrollViewBounce { self = [super initWithFrame:frame]; if (self) { - self.willBeDismissed = NO; + _willBeDismissed = NO; + _simulateScrollViewBounce = simulateScrollViewBounce; if (UIAccessibilityIsVoiceOverRunning()) { _sheetState = MDCSheetStateExtended; } else { @@ -70,6 +73,7 @@ - (instancetype)initWithFrame:(CGRect)frame // Don't set the frame yet because we're going to change the anchor point. _sheet = [[MDCDraggableView alloc] initWithFrame:CGRectZero scrollView:scrollView]; + _sheet.simulateScrollViewBounce = _simulateScrollViewBounce; _sheet.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; _sheet.delegate = self; _sheet.backgroundColor = contentView.backgroundColor; @@ -145,7 +149,8 @@ - (void)didMoveToWindow { [super didMoveToWindow]; if (self.window) { if (!self.sheetBehavior) { - self.sheetBehavior = [[MDCSheetBehavior alloc] initWithItem:self.sheet]; + self.sheetBehavior = [[MDCSheetBehavior alloc] initWithItem:self.sheet + simulateScrollViewBounce:self.simulateScrollViewBounce]; } [self animatePaneWithInitialVelocity:CGPointZero]; } else { @@ -419,15 +424,15 @@ - (void)draggableView:(__unused MDCDraggableView *)view MDCSheetState targetState; if (self.preferredSheetHeight == [self maximumSheetHeight]) { // Cannot be extended, only closed. - targetState = ((velocity.y >= 0 && self.dismissOnDraggingDownSheet) ? MDCSheetStateClosed - : MDCSheetStatePreferred); + targetState = ((velocity.y > 0 && self.dismissOnDraggingDownSheet) ? MDCSheetStateClosed + : MDCSheetStatePreferred); } else { CGFloat currentSheetHeight = CGRectGetMaxY(self.bounds) - CGRectGetMinY(self.sheet.frame); if (currentSheetHeight >= self.preferredSheetHeight) { - targetState = (velocity.y >= 0 ? MDCSheetStatePreferred : MDCSheetStateExtended); + targetState = (velocity.y > 0 ? MDCSheetStatePreferred : MDCSheetStateExtended); } else { - targetState = ((velocity.y >= 0 && self.dismissOnDraggingDownSheet) ? MDCSheetStateClosed - : MDCSheetStatePreferred); + targetState = ((velocity.y > 0 && self.dismissOnDraggingDownSheet) ? MDCSheetStateClosed + : MDCSheetStatePreferred); } } self.isDragging = NO; diff --git a/components/BottomSheet/tests/unit/MDCBottomSheetPresentationControllerTests.m b/components/BottomSheet/tests/unit/MDCBottomSheetPresentationControllerTests.m index 4fea4a447aa..f8f8ac16922 100644 --- a/components/BottomSheet/tests/unit/MDCBottomSheetPresentationControllerTests.m +++ b/components/BottomSheet/tests/unit/MDCBottomSheetPresentationControllerTests.m @@ -111,7 +111,8 @@ - (void)setUp { // receives an updated value for `preferredSheetHeight`. self.sheetView = [[FakeSheetView alloc] initWithFrame:CGRectZero contentView:[[UIView alloc] init] - scrollView:[[UIScrollView alloc] init]]; + scrollView:[[UIScrollView alloc] init] + simulateScrollViewBounce:YES]; // Only used as a required `-init` parameters for MDCBottomSheetPresentationController UIViewController *stubPresentingViewController = [[UIViewController alloc] init]; @@ -267,7 +268,8 @@ - (void)testVeryLargePreferredSheetHeightAndSmallContent { FakeSheetView *sheetView = [[FakeSheetView alloc] initWithFrame:smallFrame contentView:[[UIView alloc] initWithFrame:smallFrame] - scrollView:scrollView]; + scrollView:scrollView + simulateScrollViewBounce:YES]; self.presentationController.sheetView = sheetView; self.presentationController.preferredSheetHeight = 5000; @@ -353,7 +355,8 @@ - (void)testSheetViewFrameMatchesScrollViewFrame { MDCSheetContainerView *fakeSheet = [[MDCSheetContainerView alloc] initWithFrame:fakeFrame contentView:[[UIView alloc] initWithFrame:fakeFrame] - scrollView:scrollView]; + scrollView:scrollView + simulateScrollViewBounce:YES]; // When [fakeSheet setNeedsLayout]; From 7a4917f3d213a8c3a9ba3e7f200a4d201fd0b4fe Mon Sep 17 00:00:00 2001 From: Randall Li Date: Tue, 26 Jan 2021 11:20:51 -0500 Subject: [PATCH 08/11] Automatic changelog preparation for release. --- .gitattributes | 28 +++++++++++++++++++++++++--- CHANGELOG.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 3 deletions(-) diff --git a/.gitattributes b/.gitattributes index c13f46c3bdc..f56e2dfb895 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,25 @@ -# Do not merge this version into `stable`. # DO NOT CHANGE THIS FILE -snapshot_test_goldens/**/*.png filter=lfs diff=lfs merge=lfs -text # DO NOT EDIT THE LINE BELOW. -.gitattributes merge=gitattributes +# DO NOT CHANGE THIS FILE +# DO NOT EDIT THE LINE BELOW. +/.gitattributes merge=gitattributes +# DO NOT EDIT THE LINE ABOVE. +# +# You can of course edit this file, but make sure you understand what you are +# doing. This file defines a custom filter driver that prevents snapshot test +# images from being merged into `stable`. Snapshot test images are only +# valuable in `develop` because they are only intended to help developers +# identify changes in the appearance of the library. +# +# Before you change this file, please carefully consider whether such a change +# is actually necessary. When you do change this file, it should almost always +# be done in a dedicated commit directly on the `stable` branch and not part +# of a release. If you see this file being changed as part of a release, +# block the release and work with the releaser to ensure that the change needs +# to be propagated from the `develop` branch to the `stable` branch. In nearly +# all cases, it should not be propagated from `develop` to `stable`. +# +# If you are a releaser and see this file change and you're not sure why, you +# might have accidentally skipped [setting the correct +# driver in your cloned +# repository](https://github.com/material-components/material-components-ios/blob/develop/contributing/releasing.md#configure-the-merge-strategy-for-gitattributes). +# If that's the case, please either revert the accidental change manually or +# restart the release with a fresh clone and the correct driver. diff --git a/CHANGELOG.md b/CHANGELOG.md index 15ae95885ac..ba94bdadf62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,46 @@ +# #develop# + +Replace this text with a summarized description of this release's contents. +## Breaking changes + +Replace this explanations for how to resolve the breaking changes. +## New deprecations + +Replace this text with links to deprecation guides. +## New features + +Replace this text with example code for each new feature. +## API changes + +## Component changes + +### BottomSheet + +* [Add BOOL property for whether or not the height of the bottom sheet should adjust for safe area insets.](https://github.com/material-components/material-components-ios/commit/1fefeaf03268b9126dfaea00907a9bb5362560e5) (Alyssa Weiss) +* [Add flag that turns off simulated bouncing when there isn't a tracking scroll view](https://github.com/material-components/material-components-ios/commit/1b985100ec89ed142981bd8f3d51b247f88e6f0c) (Andrew Overton) + +### Buttons + +* [Add documentation for Enums.](https://github.com/material-components/material-components-ios/commit/c727b890df3c0766706ad8000649f7733cdef997) (Cody Weaver) + +### Chips + +* [Add docs for MDCChipField](https://github.com/material-components/material-components-ios/commit/3f7cc9f51cf9ea9287b3e817bc730eaac31bd87e) (Andrew Overton) + +### Dialogs + +* [Adding customized interface orientations and transition style support to the alert dialog.](https://github.com/material-components/material-components-ios/commit/a9b6ca12b5cba778176b7cb129e866b8669ac8bc) (Nobody) + +### List + +* [Use isKindOfClass to ensure there is support for all MDCShadowLayer's subclasses.](https://github.com/material-components/material-components-ios/commit/d5bba14e9a51405ee2ed868fd630d852c49d0c6e) (Yarden Eitan) + +### ProgressView + +* [Add Objective-C generics to MDCProgressView](https://github.com/material-components/material-components-ios/commit/1b70fd6ad949c143d7225e3719c912fce8181719) (Andrew Overton) + +--- + # 120.0.0 In this major release, we deleted the `elevationOverlayColor` property from MDCSemanticColorScheme, added a `placeholderColor` property to MDCTextControls, added a `shapedBorderColor` property and a `shapedBorderWidth` property to MDCShapedView, and made multiple bug fixes. From 132be3bdebcc4a0e8d5ea2b415281f5a4ef5407b Mon Sep 17 00:00:00 2001 From: Randall Li Date: Wed, 27 Jan 2021 01:56:43 -0500 Subject: [PATCH 09/11] Hand-modified CHANGELOG.md API diff. --- CHANGELOG.md | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba94bdadf62..b98ae3e15ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,16 +1,26 @@ -# #develop# +# 121.0.0 + +In this major release, we added a `scrollViewBounce` property and a `adjustHeightForSafeAreaInsets` property to BottomSheets, added a `shouldAutorotateOverride` property, a `preferredInterfaceOrientationForPresentationOverride` property, a `supportedInterfaceOrientationsOverride` property, and a `modalTransitionStyleOverride` property to MDCAlertController, and converted `progressTintColors` property on MDCProgressView to use light weight generics. -Replace this text with a summarized description of this release's contents. ## Breaking changes -Replace this explanations for how to resolve the breaking changes. -## New deprecations +### ProgressView + +MDCProgressView's property `progressTintColors` started using light weight generics so values pass in need to be typed correctly. -Replace this text with links to deprecation guides. ## New features -Replace this text with example code for each new feature. -## API changes +### BottomSheet + +Bottom sheets have new propertie that turn off the overscroll and safe area insets. + +### Dialogs + + + +### ProgressView + +Converted `progressTintColors` property on MDCProgressView to use light weight generics. ## Component changes From 548913f194d73332780afc9bacb81027da3e5d3e Mon Sep 17 00:00:00 2001 From: Randall Li Date: Wed, 27 Jan 2021 01:57:18 -0500 Subject: [PATCH 10/11] Bumped version number to 121.0.0. --- MaterialComponents.podspec | 2 +- MaterialComponentsEarlGreyTests.podspec | 2 +- MaterialComponentsExamples.podspec | 2 +- MaterialComponentsSnapshotTests.podspec | 2 +- VERSION | 2 +- catalog/MDCCatalog/Info.plist | 4 ++-- catalog/MDCDragons/Info.plist | 4 ++-- catalog/MaterialCatalog/MaterialCatalog.podspec | 2 +- components/LibraryInfo/src/MDCLibraryInfo.m | 2 +- components/LibraryInfo/tests/unit/LibraryInfoTests.m | 2 +- demos/supplemental/RemoteImageServiceForMDCDemos.podspec | 2 +- 11 files changed, 13 insertions(+), 13 deletions(-) diff --git a/MaterialComponents.podspec b/MaterialComponents.podspec index f2a42397d9c..4c25cae0fbc 100644 --- a/MaterialComponents.podspec +++ b/MaterialComponents.podspec @@ -2,7 +2,7 @@ load 'scripts/generated/icons.rb' Pod::Spec.new do |mdc| mdc.name = "MaterialComponents" - mdc.version = "120.0.0" + mdc.version = "121.0.0" 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" diff --git a/MaterialComponentsEarlGreyTests.podspec b/MaterialComponentsEarlGreyTests.podspec index a6378ce239a..228d209f678 100644 --- a/MaterialComponentsEarlGreyTests.podspec +++ b/MaterialComponentsEarlGreyTests.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "MaterialComponentsEarlGreyTests" - s.version = "120.0.0" + s.version = "121.0.0" 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." diff --git a/MaterialComponentsExamples.podspec b/MaterialComponentsExamples.podspec index 671c81eee67..1b4f4dcfe5d 100644 --- a/MaterialComponentsExamples.podspec +++ b/MaterialComponentsExamples.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "MaterialComponentsExamples" - s.version = "120.0.0" + s.version = "121.0.0" 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." diff --git a/MaterialComponentsSnapshotTests.podspec b/MaterialComponentsSnapshotTests.podspec index 36b50d9e130..298de0b76b1 100644 --- a/MaterialComponentsSnapshotTests.podspec +++ b/MaterialComponentsSnapshotTests.podspec @@ -53,7 +53,7 @@ end Pod::Spec.new do |s| s.name = "MaterialComponentsSnapshotTests" - s.version = "120.0.0" + s.version = "121.0.0" 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" diff --git a/VERSION b/VERSION index 57ee5f4db73..58326d9a847 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -120.0.0 +121.0.0 diff --git a/catalog/MDCCatalog/Info.plist b/catalog/MDCCatalog/Info.plist index 54ec6ca455b..9b267e8fa46 100644 --- a/catalog/MDCCatalog/Info.plist +++ b/catalog/MDCCatalog/Info.plist @@ -15,11 +15,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 120.0.0 + 121.0.0 CFBundleSignature ???? CFBundleVersion - 120.0.0 + 121.0.0 LSRequiresIPhoneOS UIAppFonts diff --git a/catalog/MDCDragons/Info.plist b/catalog/MDCDragons/Info.plist index f925fa87ce7..602c55f4cf7 100644 --- a/catalog/MDCDragons/Info.plist +++ b/catalog/MDCDragons/Info.plist @@ -15,9 +15,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - 120.0.0 + 121.0.0 CFBundleVersion - 120.0.0 + 121.0.0 LSRequiresIPhoneOS UILaunchStoryboardName diff --git a/catalog/MaterialCatalog/MaterialCatalog.podspec b/catalog/MaterialCatalog/MaterialCatalog.podspec index dbb74aca153..44de03e3058 100644 --- a/catalog/MaterialCatalog/MaterialCatalog.podspec +++ b/catalog/MaterialCatalog/MaterialCatalog.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "MaterialCatalog" - s.version = "120.0.0" + s.version = "121.0.0" 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" diff --git a/components/LibraryInfo/src/MDCLibraryInfo.m b/components/LibraryInfo/src/MDCLibraryInfo.m index 36b171c7b42..a47df200e8c 100644 --- a/components/LibraryInfo/src/MDCLibraryInfo.m +++ b/components/LibraryInfo/src/MDCLibraryInfo.m @@ -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 = @"120.0.0"; +static NSString* const kMDCLibraryInfoVersionString = @"121.0.0"; @implementation MDCLibraryInfo diff --git a/components/LibraryInfo/tests/unit/LibraryInfoTests.m b/components/LibraryInfo/tests/unit/LibraryInfoTests.m index bc78c0dd91e..fbddfa4e75b 100644 --- a/components/LibraryInfo/tests/unit/LibraryInfoTests.m +++ b/components/LibraryInfo/tests/unit/LibraryInfoTests.m @@ -26,7 +26,7 @@ - (void)testVersionFormat { // Given // This regex pattern does the following: - // Accept: "120.0.0", etc. + // Accept: "121.0.0", 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 diff --git a/demos/supplemental/RemoteImageServiceForMDCDemos.podspec b/demos/supplemental/RemoteImageServiceForMDCDemos.podspec index c9772dcac16..6269424ce18 100644 --- a/demos/supplemental/RemoteImageServiceForMDCDemos.podspec +++ b/demos/supplemental/RemoteImageServiceForMDCDemos.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "RemoteImageServiceForMDCDemos" - s.version = "120.0.0" + s.version = "121.0.0" s.summary = "A helper image class for the MDC demos." s.description = "This spec is made for use in the MDC demos. It gets images via url." s.homepage = "https://github.com/material-components/material-components-ios" From d6d3cbe6b9b94823780438bad8d517bd4c61432e Mon Sep 17 00:00:00 2001 From: Randall Li Date: Wed, 27 Jan 2021 01:59:25 -0500 Subject: [PATCH 11/11] Hand-modified CHANGELOG.md API diff. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b98ae3e15ba..e52ec76eefa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ Bottom sheets have new propertie that turn off the overscroll and safe area inse ### Dialogs - +Added a `shouldAutorotateOverride` property, a `preferredInterfaceOrientationForPresentationOverride` property, a `supportedInterfaceOrientationsOverride` property, and a `modalTransitionStyleOverride` property to MDCAlertController. ### ProgressView