Skip to content

Commit

Permalink
[BottomSheet] Mask elevation on bottom edge
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 332461973
  • Loading branch information
andrewoverton authored and material-automation committed Sep 18, 2020
1 parent 39af711 commit 588d9d2
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions components/BottomSheet/src/MDCBottomSheetController.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#import "UIViewController+MaterialBottomSheet.h"
#import "MaterialMath.h"

static const CGFloat kElevationSpreadMaskAffordance = 50.0f;

@interface MDCBottomSheetController () <MDCBottomSheetPresentationControllerDelegate>
@property(nonatomic, readonly, strong) MDCShapedView *view;
@end
Expand Down Expand Up @@ -99,6 +101,12 @@ - (void)viewDidAppear:(BOOL)animated {
}
}

- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];

self.view.layer.mask = [self createBottomEdgeElevationMask];
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return self.contentViewController.supportedInterfaceOrientations;
}
Expand Down Expand Up @@ -227,6 +235,19 @@ - (CGFloat)mdc_currentElevation {
return self.elevation;
}

- (CAShapeLayer *)createBottomEdgeElevationMask {
CGFloat boundsWidth = CGRectGetWidth(self.view.bounds);
CGFloat boundsHeight = CGRectGetHeight(self.view.bounds);
CGRect visibleRectOutsideBounds =
CGRectMake(0 - kElevationSpreadMaskAffordance, 0 - kElevationSpreadMaskAffordance,
boundsWidth + (2.0f * kElevationSpreadMaskAffordance),
boundsHeight + kElevationSpreadMaskAffordance);
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
UIBezierPath *visibleAreaPath = [UIBezierPath bezierPathWithRect:visibleRectOutsideBounds];
maskLayer.path = visibleAreaPath.CGPath;
return maskLayer;
}

/* Disable setter. Always use internal transition controller */
- (void)setTransitioningDelegate:
(__unused id<UIViewControllerTransitioningDelegate>)transitioningDelegate {
Expand Down

0 comments on commit 588d9d2

Please sign in to comment.