[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 <kirylkaveryn@gmail.com>
This commit is contained in:
Kiryl Kaveryn 2024-12-05 15:05:44 +04:00 committed by Roman Tsisyk
parent 41979b1104
commit 4082a783dc
2 changed files with 25 additions and 3 deletions

View file

@ -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

View file

@ -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()