diff --git a/iphone/Maps/UI/PlacePage/Components/ActionBarViewController.swift b/iphone/Maps/UI/PlacePage/Components/ActionBarViewController.swift index 2eac45ede6..b389fee641 100644 --- a/iphone/Maps/UI/PlacePage/Components/ActionBarViewController.swift +++ b/iphone/Maps/UI/PlacePage/Components/ActionBarViewController.swift @@ -40,19 +40,12 @@ class ActionBarViewController: UIViewController { } for buttonType in visibleButtons { - var selected = false - var disabled = false - if buttonType == .bookmark { - if let bookmarkData = placePageData.bookmarkData { - selected = true - disabled = !bookmarkData.isEditable - } - } + let (selected, enabled) = buttonState(buttonType) let button = ActionBarButton(delegate: self, buttonType: buttonType, partnerIndex: placePageData.partnerIndex, isSelected: selected, - isDisabled: disabled) + isEnabled: enabled) stackView.addArrangedSubview(button) if buttonType == .download { downloadButton = button @@ -167,12 +160,15 @@ class ActionBarViewController: UIViewController { message: placePageData.previewData.subtitle, preferredStyle: .actionSheet) for button in additionalButtons { - actionSheet.addAction(UIAlertAction(title: titleForButton(button, placePageData.partnerIndex, false), - style: .default, - handler: { [weak self] _ in - guard let self = self else { return } - self.delegate?.actionBar(self, didPressButton: button) - })) + let (selected, enabled) = buttonState(button) + let action = UIAlertAction(title: titleForButton(button, placePageData.partnerIndex, selected), + style: .default, + handler: { [weak self] _ in + guard let self = self else { return } + self.delegate?.actionBar(self, didPressButton: button) + }) + action.isEnabled = enabled + actionSheet.addAction(action) } actionSheet.addAction(UIAlertAction(title: L("cancel"), style: .cancel)) if let popover = actionSheet.popoverPresentationController, let sourceView = stackView.arrangedSubviews.last { @@ -181,6 +177,16 @@ class ActionBarViewController: UIViewController { } present(actionSheet, animated: true) } + + private func buttonState(_ buttonType: ActionBarButtonType) -> (Bool /* selected */, Bool /* enabled */) { + var selected = false + var enabled = true + if buttonType == .bookmark, let bookmarkData = placePageData.bookmarkData { + selected = true + enabled = bookmarkData.isEditable + } + return (selected, enabled) + } } extension ActionBarViewController: ActionBarButtonDelegate { diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.h b/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.h index ca298b8277..d2373f89cc 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.h +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.h @@ -48,7 +48,7 @@ NS_SWIFT_NAME(ActionBarButton) buttonType:(MWMActionBarButtonType)type partnerIndex:(NSInteger)partnerIndex isSelected:(BOOL)isSelected - isDisabled:(BOOL)isDisabled; + isEnabled:(BOOL)isEnabled; @end diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.m b/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.m index 9d7f700b0e..93ae5b9953 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.m +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.m @@ -84,7 +84,7 @@ static UIColor *backgroundColorForPartner(NSInteger partnerIndex) { @implementation MWMActionBarButton -- (void)configButton:(BOOL)isSelected disabled:(BOOL)isDisabled { +- (void)configButton:(BOOL)isSelected enabled:(BOOL)isEnabled { self.label.text = titleForButton(self.type, self.partnerIndex, isSelected); self.extraBackground.hidden = YES; switch (self.type) { @@ -169,19 +169,19 @@ static UIColor *backgroundColorForPartner(NSInteger partnerIndex) { [self.button setImage:[UIImage imageNamed:@"ic_avoid_ferry"] forState:UIControlStateNormal]; break; } - self.button.enabled = !isDisabled; + self.button.enabled = isEnabled; } + (MWMActionBarButton *)buttonWithDelegate:(id)delegate buttonType:(MWMActionBarButtonType)type partnerIndex:(NSInteger)partnerIndex isSelected:(BOOL)isSelected - isDisabled:(BOOL)isDisabled { + isEnabled:(BOOL)isEnabled { MWMActionBarButton *button = [NSBundle.mainBundle loadNibNamed:[self className] owner:nil options:nil].firstObject; button.delegate = delegate; button.type = type; button.partnerIndex = partnerIndex; - [button configButton:isSelected disabled:isDisabled]; + [button configButton:isSelected enabled:isEnabled]; return button; } diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/Layouts/PlacePageCommonLayout.swift b/iphone/Maps/UI/PlacePage/PlacePageLayout/Layouts/PlacePageCommonLayout.swift index f07cad16a5..cc46ff949d 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/Layouts/PlacePageCommonLayout.swift +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/Layouts/PlacePageCommonLayout.swift @@ -372,6 +372,7 @@ extension PlacePageCommonLayout { } else { hidden = true } + self.presenter?.layoutIfNeeded() UIView.animate(withDuration: kDefaultAnimationDuration) { [unowned self] in self.bookmarkViewController.view.isHidden = hidden self.presenter?.layoutIfNeeded()