From 4082a783dc1bc1e879027a92eaab47ee47079bc2 Mon Sep 17 00:00:00 2001 From: Kiryl Kaveryn Date: Thu, 5 Dec 2024 15:05:44 +0400 Subject: [PATCH] [ios] add track deletion confirmation alert Also the issue for the PP VC in `traitCollectionDidChange` was fixed. It is needed to prevent PP reloading when the alert is presented over the screen. It happens because the new trait updates can be passed to the `traitCollectionDidChange` method on the every layout update and it cause the steps and layout recalculations. The PP should be reloaded only when the vertical size class is changed. Signed-off-by: Kiryl Kaveryn --- .../UI/PlacePage/PlacePageInteractor.swift | 26 +++++++++++++++++-- .../PlacePage/PlacePageViewController.swift | 2 +- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/iphone/Maps/UI/PlacePage/PlacePageInteractor.swift b/iphone/Maps/UI/PlacePage/PlacePageInteractor.swift index 27e3da7e77..b33306642d 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageInteractor.swift +++ b/iphone/Maps/UI/PlacePage/PlacePageInteractor.swift @@ -238,12 +238,34 @@ extension PlacePageInteractor: ActionBarViewControllerDelegate { fatalError("More button should've been handled in ActionBarViewContoller") case .track: guard placePageData.trackData != nil else { return } - MWMPlacePageManagerHelper.removeTrack(placePageData) - presenter?.closeAnimated() + // TODO: This is temporary solution. Remove the dialog and use the MWMPlacePageManagerHelper.removeTrack + // directly here when the track recovery mechanism will be implemented. + showTrackDeletionConfirmationDialog() @unknown default: fatalError() } } + + private func showTrackDeletionConfirmationDialog() { + let alert = UIAlertController(title: nil, message: L("placepage_delete_track_confirmation_alert_message"), preferredStyle: .actionSheet) + let deleteAction = UIAlertAction(title: L("delete"), style: .destructive) { [weak self] _ in + guard let self = self else { return } + guard self.placePageData.trackData != nil else { + fatalError("The track data should not be nil during the track deletion") + } + MWMPlacePageManagerHelper.removeTrack(self.placePageData) + self.presenter?.closeAnimated() + } + let cancelAction = UIAlertAction(title: L("cancel"), style: .cancel) + alert.addAction(deleteAction) + alert.addAction(cancelAction) + guard let viewController else { return } + iPadSpecific { + alert.popoverPresentationController?.sourceView = viewController.view + alert.popoverPresentationController?.sourceRect = viewController.view.frame + } + viewController.present(alert, animated: true) + } } // MARK: - ElevationProfileViewControllerDelegate diff --git a/iphone/Maps/UI/PlacePage/PlacePageViewController.swift b/iphone/Maps/UI/PlacePage/PlacePageViewController.swift index d5b3d2a85a..d4da6c0c27 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageViewController.swift +++ b/iphone/Maps/UI/PlacePage/PlacePageViewController.swift @@ -82,7 +82,7 @@ final class PlacePageScrollView: UIScrollView { override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { super.traitCollectionDidChange(previousTraitCollection) // Update layout when the device was rotated but skip when the appearance was changed. - if self.previousTraitCollection != nil, previousTraitCollection?.userInterfaceStyle == traitCollection.userInterfaceStyle { + if self.previousTraitCollection != nil, previousTraitCollection?.userInterfaceStyle == traitCollection.userInterfaceStyle, previousTraitCollection?.verticalSizeClass != traitCollection.verticalSizeClass { DispatchQueue.main.async { self.updateSteps() self.showLastStop()