[ios] fix memory leak in the PlacePageInfoViewController

Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>
This commit is contained in:
Kiryl Kaveryn 2025-02-11 22:05:58 +04:00 committed by Roman Tsisyk
parent b9d0138cd1
commit 0687642095

View file

@ -131,7 +131,7 @@ class PlacePageInfoViewController: UIViewController {
private var driveThroughView: InfoItemViewController?
private var networkView: InfoItemViewController?
var placePageInfoData: PlacePageInfoData!
weak var placePageInfoData: PlacePageInfoData!
weak var delegate: PlacePageInfoViewControllerDelegate?
var coordinatesFormatId: Int {
get { UserDefaults.standard.integer(forKey: Constants.coordFormatIdKey) }
@ -366,33 +366,22 @@ class PlacePageInfoViewController: UIViewController {
if formatId >= coordFormats.count {
formatId = 0
}
func setCoordinatesSelected(formatId: Int) {
coordinatesFormatId = formatId
let coordinates: String = coordFormats[formatId]
coordinatesView?.infoLabel.text = coordinates
}
func copyCoordinatesToPasteboard() {
let coordinates: String = coordFormats[coordinatesFormatId]
self.delegate?.didCopy(coordinates)
}
coordinatesView = createInfoItem(coordFormats[formatId],
icon: UIImage(named: "ic_placepage_coordinate"),
accessoryImage: UIImage(named: "ic_placepage_change"),
tapHandler: { [unowned self] in
tapHandler: { [weak self] in
guard let self else { return }
let formatId = (self.coordinatesFormatId + 1) % coordFormats.count
setCoordinatesSelected(formatId: formatId)
self.setCoordinatesSelected(formatId: formatId)
},
longPressHandler: {
copyCoordinatesToPasteboard()
longPressHandler: { [weak self] in
self?.copyCoordinatesToPasteboard()
})
if #available(iOS 14.0, *) {
let menu = UIMenu(children: coordFormats.enumerated().map { (index, format) in
UIAction(title: format, handler: { _ in
setCoordinatesSelected(formatId: index)
copyCoordinatesToPasteboard()
UIAction(title: format, handler: { [weak self] _ in
self?.setCoordinatesSelected(formatId: index)
self?.copyCoordinatesToPasteboard()
})
})
coordinatesView?.accessoryButton.menu = menu
@ -400,6 +389,19 @@ class PlacePageInfoViewController: UIViewController {
}
}
private func setCoordinatesSelected(formatId: Int) {
guard let coordFormats = placePageInfoData.coordFormats as? Array<String> else { return }
coordinatesFormatId = formatId
let coordinates: String = coordFormats[formatId]
coordinatesView?.infoLabel.text = coordinates
}
private func copyCoordinatesToPasteboard() {
guard let coordFormats = placePageInfoData.coordFormats as? Array<String> else { return }
let coordinates: String = coordFormats[coordinatesFormatId]
delegate?.didCopy(coordinates)
}
private func setupOpenWithAppView() {
guard let delegate, delegate.shouldShowOpenInApp else { return }
openWithAppView = createInfoItem(L("open_in_app"),