Skip to content
This repository was archived by the owner on Dec 11, 2025. It is now read-only.

Commit 02899b8

Browse files
codeman7material-automation
authored andcommitted
#Button Fix shadow not animating properly.
PiperOrigin-RevId: 761607270
1 parent 5de1333 commit 02899b8

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

components/M3CButton/src/M3CButton.m

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,26 @@
99

1010
NS_ASSUME_NONNULL_BEGIN
1111

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+
1232
/** Used to store the scaling curve and initial size of the @c imageView of a @c M3CButton. */
1333
@interface M3CIconAttributes : NSObject
1434

@@ -63,7 +83,7 @@ @interface M3CButton () {
6383
where touch targets are not met, this replaces the background while the background remains the
6484
touch target size but changes to clear.
6585
*/
66-
@property(nonatomic, strong, nonnull) UIView *visualBackground;
86+
@property(nonatomic, strong, nonnull) M3CVisualBackgroundView *visualBackground;
6787

6888
// Used only when layoutTitleWithConstraints is enabled.
6989
@property(nonatomic, strong, nullable) NSLayoutConstraint *titleTopConstraint;
@@ -120,7 +140,7 @@ - (void)initCommon {
120140
_edgeInsetsWithImageForSize = [NSMutableDictionary dictionary];
121141
_edgeInsetsWithTitleForSize = [NSMutableDictionary dictionary];
122142
_customInsetAvailable = NO;
123-
_visualBackground = [[UIView alloc] init];
143+
_visualBackground = [[M3CVisualBackgroundView alloc] init];
124144
_visualBackground.exclusiveTouch = NO;
125145
_visualBackground.userInteractionEnabled = NO;
126146
_visualContentSize = CGSizeZero;

0 commit comments

Comments
 (0)