|
9 | 9 |
|
10 | 10 | NS_ASSUME_NONNULL_BEGIN |
11 | 11 |
|
| 12 | +/** |
| 13 | + Used to handle shadow animations of a @c M3CButton. |
| 14 | + */ |
| 15 | +@interface M3CVisualBackgroundView : UIView |
| 16 | +@end |
| 17 | + |
| 18 | +@implementation M3CVisualBackgroundView |
| 19 | + |
| 20 | +#pragma mark - CALayerDelegate |
| 21 | + |
| 22 | +- (nullable id<CAAction>)actionForLayer:(CALayer *)layer forKey:(NSString *)key { |
| 23 | + if (layer == self.layer && M3CIsMDCShadowPathKey(key)) { |
| 24 | + // Provide a custom action for the view's layer's shadow path only. |
| 25 | + return M3CShadowPathActionForLayer(layer); |
| 26 | + } |
| 27 | + return [super actionForLayer:layer forKey:key]; |
| 28 | +} |
| 29 | + |
| 30 | +@end |
| 31 | + |
12 | 32 | /** Used to store the scaling curve and initial size of the @c imageView of a @c M3CButton. */ |
13 | 33 | @interface M3CIconAttributes : NSObject |
14 | 34 |
|
@@ -63,7 +83,7 @@ @interface M3CButton () { |
63 | 83 | where touch targets are not met, this replaces the background while the background remains the |
64 | 84 | touch target size but changes to clear. |
65 | 85 | */ |
66 | | -@property(nonatomic, strong, nonnull) UIView *visualBackground; |
| 86 | +@property(nonatomic, strong, nonnull) M3CVisualBackgroundView *visualBackground; |
67 | 87 |
|
68 | 88 | // Used only when layoutTitleWithConstraints is enabled. |
69 | 89 | @property(nonatomic, strong, nullable) NSLayoutConstraint *titleTopConstraint; |
@@ -120,7 +140,7 @@ - (void)initCommon { |
120 | 140 | _edgeInsetsWithImageForSize = [NSMutableDictionary dictionary]; |
121 | 141 | _edgeInsetsWithTitleForSize = [NSMutableDictionary dictionary]; |
122 | 142 | _customInsetAvailable = NO; |
123 | | - _visualBackground = [[UIView alloc] init]; |
| 143 | + _visualBackground = [[M3CVisualBackgroundView alloc] init]; |
124 | 144 | _visualBackground.exclusiveTouch = NO; |
125 | 145 | _visualBackground.userInteractionEnabled = NO; |
126 | 146 | _visualContentSize = CGSizeZero; |
|
0 commit comments