Skip to content

Commit 31944e7

Browse files
committed
Animate bar extension alpha alongside the bar presentation animation for better appearance
1 parent 014a602 commit 31944e7

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

LNPopupController/LNPopupController/Private/LNPopupController.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,8 +1082,10 @@ - (void)presentPopupBarAnimated:(BOOL)animated openPopup:(BOOL)open completion:(
10821082

10831083
[_containerController.view layoutIfNeeded];
10841084

1085+
_containerController._ln_bottomBarExtension_nocreate.alpha = 0.0;
10851086
[UIView animateWithDuration:animated ? 0.5 : 0.0 delay:0.0 usingSpringWithDamping:500 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseInOut animations:^ {
10861087
[_bottomBar _ln_triggerScrollEdgeAppearanceRefreshIfNeeded];
1088+
_containerController._ln_bottomBarExtension_nocreate.alpha = 1.0;
10871089

10881090
CGRect barFrame = self.popupBar.frame;
10891091
barFrame.size.height = _LNPopupBarHeightForBarStyle(_LNPopupResolveBarStyleFromBarStyle(self.popupBar.barStyle), self.popupBar.customBarViewController);
@@ -1190,6 +1192,7 @@ - (void)dismissPopupBarAnimated:(BOOL)animated completion:(void(^)(void))complet
11901192
_LNPopupSupportSetPopupInsetsForViewController(_containerController, YES, UIEdgeInsetsZero);
11911193

11921194
[_bottomBar _ln_triggerScrollEdgeAppearanceRefreshIfNeeded];
1195+
_containerController._ln_bottomBarExtension_nocreate.alpha = 0.0;
11931196
} completion:^(BOOL finished) {
11941197
_popupControllerInternalState = LNPopupPresentationStateBarHidden;
11951198

LNPopupController/LNPopupController/Private/UIViewController+LNPopupSupportPrivate.m

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ - (_LNPopupBarBackgroundView*)_ln_bottomBarExtension_nocreate
531531

532532
- (_LNPopupBarBackgroundView*)_ln_bottomBarExtension
533533
{
534-
if(self.shouldExtendPopupBarUnderSafeArea == NO)
534+
if(self.shouldExtendPopupBarUnderSafeArea == NO || self._ln_popupController_nocreate.popupControllerInternalState == LNPopupPresentationStateBarHidden)
535535
{
536536
[self._ln_bottomBarExtension_nocreate removeFromSuperview];
537537

@@ -542,6 +542,7 @@ - (_LNPopupBarBackgroundView*)_ln_bottomBarExtension
542542
if(rv == nil)
543543
{
544544
rv = [[_LNPopupBarBackgroundView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemChromeMaterial]];
545+
rv.alpha = 0.0;
545546
objc_setAssociatedObject(self, LNPopupBarExtensionView, rv, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
546547
[self._ln_popupController _updateBarExtensionStyleFromPopupBar];
547548
}
@@ -581,21 +582,13 @@ - (void)_ln_popup_viewDidLayoutSubviews
581582
UIView* extensionView = self._ln_bottomBarExtension_nocreate;
582583
dispatch_block_t removeFromSuperview = ^ {
583584
[extensionView removeFromSuperview];
584-
extensionView.alpha = 1.0;
585+
extensionView.alpha = 0.0;
585586
};
586587

587-
if(self.shouldExtendPopupBarUnderSafeArea == NO)
588+
if(self.shouldExtendPopupBarUnderSafeArea == NO || (self._ln_popupController_nocreate.popupControllerInternalState == LNPopupPresentationStateBarHidden && extensionView.superview != nil))
588589
{
589590
removeFromSuperview();
590591
}
591-
else if(self._ln_popupController_nocreate.popupControllerInternalState == LNPopupPresentationStateBarHidden && extensionView.superview != nil)
592-
{
593-
[UIView animateWithDuration:0.15 animations:^{
594-
extensionView.alpha = 0.0;
595-
} completion:^(BOOL finished) {
596-
removeFromSuperview();
597-
}];
598-
}
599592
}
600593

601594
- (BOOL)_ignoringLayoutDuringTransition
@@ -855,6 +848,7 @@ - (void)hBWT:(NSInteger)t iE:(BOOL)e
855848

856849
[self _layoutPopupBarOrderForTransition];
857850

851+
self._ln_bottomBarExtension_nocreate.alpha = 1.0;
858852
[self.selectedViewController.transitionCoordinator animateAlongsideTransition: ^ (id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
859853
self._ln_bottomBarExtension_nocreate.frame = CGRectMake(0, self.view.bounds.size.height - bottomSafeArea, self.view.bounds.size.width, self._ln_bottomBarExtension_nocreate.frame.size.height);
860854
self._ln_popupController_nocreate.popupBar.bottomShadowView.alpha = 0.0;
@@ -923,6 +917,11 @@ - (void)sBWT:(NSInteger)t iE:(BOOL)e
923917
[self _setIgnoringLayoutDuringTransition:NO];
924918

925919
self._ln_popupController_nocreate.popupBar.effectGroupingIdentifier = effectGroupingIdentifier;
920+
921+
if(context.isCancelled == NO)
922+
{
923+
self._ln_bottomBarExtension_nocreate.alpha = 0.0;
924+
}
926925
}];
927926
}
928927
}
@@ -1114,6 +1113,7 @@ - (void)_sTH:(BOOL)hidden e:(UIRectEdge)edge d:(CGFloat)duration;
11141113
if(hidden == YES)
11151114
{
11161115
self._ln_bottomBarExtension.frame = frame;
1116+
self._ln_bottomBarExtension_nocreate.alpha = 1.0;
11171117
}
11181118

11191119
self._ln_popupController_nocreate.popupBar.bottomShadowView.alpha = hidden == NO ? 0.0 : 1.0;
@@ -1129,7 +1129,7 @@ - (void)_sTH:(BOOL)hidden e:(UIRectEdge)edge d:(CGFloat)duration;
11291129
CGRect frame;
11301130
if(hidden)
11311131
{
1132-
self._ln_bottomBarExtension.frame = CGRectMake(0, self.view.bounds.size.height - safeArea, self.view.bounds.size.width, self._ln_bottomBarExtension_nocreate.frame.size.height);
1132+
self._ln_bottomBarExtension_nocreate.frame = CGRectMake(0, self.view.bounds.size.height - safeArea, self.view.bounds.size.width, self._ln_bottomBarExtension_nocreate.frame.size.height);
11331133

11341134
self._ln_popupController_nocreate.popupBar.bottomShadowView.alpha = 0.0;
11351135
}
@@ -1141,7 +1141,7 @@ - (void)_sTH:(BOOL)hidden e:(UIRectEdge)edge d:(CGFloat)duration;
11411141
{
11421142
frame.origin.x = self.view.bounds.size.width;
11431143
}
1144-
self._ln_bottomBarExtension.frame = frame;
1144+
self._ln_bottomBarExtension_nocreate.frame = frame;
11451145

11461146
self._ln_popupController_nocreate.popupBar.bottomShadowView.alpha = 1.0;
11471147
}
@@ -1152,6 +1152,10 @@ - (void)_sTH:(BOOL)hidden e:(UIRectEdge)edge d:(CGFloat)duration;
11521152
{
11531153
self._ln_bottomBarExtension_nocreate.frame = CGRectMake(0, self.view.bounds.size.height - safeArea, self.view.bounds.size.width, safeArea);
11541154
}
1155+
else if(finished)
1156+
{
1157+
self._ln_bottomBarExtension_nocreate.alpha = 0.0;
1158+
}
11551159

11561160
//Position the popup bar and content to the superview of the toolbar for the transition.
11571161
[self._ln_popupController_nocreate _setContentToState:self._ln_popupController_nocreate.popupControllerInternalState];

0 commit comments

Comments
 (0)