Skip to content

Commit

Permalink
Fix bug that was causing messy animation when a keyboard is going to …
Browse files Browse the repository at this point in the history
…appear after the bottom sheet dismisses.

PiperOrigin-RevId: 351804762
  • Loading branch information
afweiss authored and material-automation committed Jan 14, 2021
1 parent 2d6db96 commit 4deaee1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#import <WebKit/WebKit.h>

#import "private/MDCSheetContainerView.h"
#import "MDCBottomSheetController.h"
#import "MDCBottomSheetPresentationControllerDelegate.h"
#import "MDCSheetContainerViewDelegate.h"
#import "MaterialMath.h"
Expand Down Expand Up @@ -228,6 +229,7 @@ - (void)dismissPresentedControllerIfNecessary:(UITapGestureRecognizer *)tapRecog
return;
}

self.sheetView.willBeDismissed = YES;
id<MDCBottomSheetPresentationControllerDelegate> strongDelegate = self.delegate;
[self.presentingViewController
dismissViewControllerAnimated:YES
Expand Down
1 change: 1 addition & 0 deletions components/BottomSheet/src/private/MDCSheetContainerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@property(nonatomic, weak, nullable) id<MDCSheetContainerViewDelegate> delegate;
@property(nonatomic, readonly) MDCSheetState sheetState;
@property(nonatomic) CGFloat preferredSheetHeight;
@property(nonatomic) BOOL willBeDismissed;

/**
When set to false, the bottom sheet controller can't be dismissed by dragging the sheet down.
Expand Down
9 changes: 8 additions & 1 deletion components/BottomSheet/src/private/MDCSheetContainerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#import "MDCSheetContainerView.h"

#import "MDCSheetState.h"
#import "MDCDraggableView.h"
#import "MDCDraggableViewDelegate.h"
#import "MDCSheetBehavior.h"
Expand Down Expand Up @@ -60,6 +61,7 @@ - (instancetype)initWithFrame:(CGRect)frame
scrollView:(UIScrollView *)scrollView {
self = [super initWithFrame:frame];
if (self) {
self.willBeDismissed = NO;
if (UIAccessibilityIsVoiceOverRunning()) {
_sheetState = MDCSheetStateExtended;
} else {
Expand Down Expand Up @@ -358,7 +360,12 @@ - (void)sheetBehaviorDidUpdate {

- (void)keyboardStateChangedWithNotification:(__unused NSNotification *)notification {
if (self.window) {
[self animatePaneWithInitialVelocity:CGPointZero];
// Only add animation if the view is not set to be dismissed with the new keyboard. Otherwise,
// the view will first adjust height to fit above the keyboard and then dismiss, which appears
// glitchy on the screen.
if (!self.willBeDismissed) {
[self animatePaneWithInitialVelocity:CGPointZero];
}
}
}

Expand Down

0 comments on commit 4deaee1

Please sign in to comment.