Skip to content

Commit

Permalink
[BottomAppBar] Fix bug where FAB shadow would "bounce" when the posit…
Browse files Browse the repository at this point in the history
…ion changed.

There are two related fixes involved here:

1. The horizontal shift animations were using the default CABasicAnimation timing function, Linear. These have been adjusted to EaseInEaseOut to match the guidelines.
2. The shadow was doing a wonky "bounce" animation by always animating to an elevation of 1 followed by an animation to the target elevation. This bounce animation has been removed.

Note that, while the bouncing has been removed, the shadow now does not animate at all. This is intentional for two reasons:

1. The shadow is expected to swap z-ordering with the bottom bar.
2. The animation is very subtle.

The result of these two constraints is that if we animate the shadow to the secondary position, then we need to change the z-order at the end of the animation. This would result in the shadow being "clipped" by the bar as the shadow moves from the foreground to the background. This ends up being more visible than the animation itself, and more distracting than the lack of an animation.

We could animate to the primary position, but at this point handling this logic would add complexity for a very subtle effect that doesn't necessarily improve the effect.

PiperOrigin-RevId: 326713093
  • Loading branch information
Jeff Verkoeyen authored and material-automation committed Aug 14, 2020
1 parent b22eef5 commit 453eaa8
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions components/BottomAppBar/src/MDCBottomAppBarView.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@

#import <MDFInternationalization/MDFInternationalization.h>

#import "MaterialMath.h"
#import "MaterialNavigationBar.h"
#import "private/MDCBottomAppBarAttributes.h"
#import "private/MDCBottomAppBarLayer.h"
#import "MaterialButtons.h"
#import "MaterialElevation.h"
#import "MaterialNavigationBar.h"
#import "MaterialShadowElevations.h"
#import "MaterialMath.h"

static NSString *kMDCBottomAppBarViewAnimKeyString = @"AnimKey";
static NSString *kMDCBottomAppBarViewPathString = @"path";
static NSString *kMDCBottomAppBarViewPositionString = @"position";
static const CGFloat kMDCBottomAppBarViewFloatingButtonCenterToNavigationBarTopOffset = 0;
static const CGFloat kMDCBottomAppBarViewFloatingButtonElevationPrimary = 6;
static const CGFloat kMDCBottomAppBarViewFloatingButtonElevationSecondary = 4;
static const int kMDCButtonAnimationDuration = 200;

@interface MDCBottomAppBarCutView : UIView

Expand Down Expand Up @@ -175,6 +177,8 @@ - (void)cutBottomAppBarViewAnimated:(BOOL)animated {
if (animated) {
CABasicAnimation *pathAnimation =
[CABasicAnimation animationWithKeyPath:kMDCBottomAppBarViewPathString];
pathAnimation.timingFunction =
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
pathAnimation.duration = kMDCFloatingButtonExitDuration;
pathAnimation.fromValue = (id)self.bottomBarLayer.presentationLayer.path;
pathAnimation.toValue = (__bridge id _Nullable)(pathWithCut);
Expand All @@ -197,6 +201,8 @@ - (void)healBottomAppBarViewAnimated:(BOOL)animated {
if (animated) {
CABasicAnimation *pathAnimation =
[CABasicAnimation animationWithKeyPath:kMDCBottomAppBarViewPathString];
pathAnimation.timingFunction =
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
pathAnimation.duration = kMDCFloatingButtonEnterDuration;
pathAnimation.fromValue = (id)self.bottomBarLayer.presentationLayer.path;
pathAnimation.toValue = (__bridge id _Nullable)(pathWithoutCut);
Expand All @@ -217,6 +223,8 @@ - (void)moveFloatingButtonCenterAnimated:(BOOL)animated {
if (animated) {
CABasicAnimation *animation =
[CABasicAnimation animationWithKeyPath:kMDCBottomAppBarViewPositionString];
animation.timingFunction =
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.duration = kMDCFloatingButtonExitDuration;
animation.fromValue = [NSValue valueWithCGPoint:self.floatingButton.center];
animation.toValue = [NSValue valueWithCGPoint:endPoint];
Expand Down Expand Up @@ -346,17 +354,11 @@ - (void)setFloatingButtonElevation:(MDCBottomAppBarFloatingButtonElevation)float
elevation = kMDCBottomAppBarViewFloatingButtonElevationSecondary;
subViewIndex = 0;
}
if (animated) {
[_floatingButton setElevation:1 forState:UIControlStateNormal];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, kMDCButtonAnimationDuration * NSEC_PER_MSEC),
dispatch_get_main_queue(), ^{
[self insertSubview:self.floatingButton atIndex:subViewIndex];
[self.floatingButton setElevation:elevation forState:UIControlStateNormal];
});
} else {
[self insertSubview:_floatingButton atIndex:subViewIndex];
[_floatingButton setElevation:elevation forState:UIControlStateNormal];
}
// Immediately move the button to the correct z-ordering so that the shadow clipping effect isn't
// as apparent. If we did this at the end of the animation, then the shadow would appear to
// suddenly clip at the end of the animation.
[self insertSubview:_floatingButton atIndex:subViewIndex];
[_floatingButton setElevation:elevation forState:UIControlStateNormal];
}

- (void)setFloatingButtonPosition:(MDCBottomAppBarFloatingButtonPosition)floatingButtonPosition {
Expand Down

0 comments on commit 453eaa8

Please sign in to comment.