mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 13:03:36 +00:00
[ios] Fix place page memory leaks
Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>
This commit is contained in:
committed by
Konstantin Pastbin
parent
1b04524d68
commit
6cccd32166
@@ -26,8 +26,8 @@ fileprivate struct DescriptionsViewModel {
|
||||
|
||||
final class ElevationProfilePresenter: NSObject {
|
||||
private weak var view: ElevationProfileViewProtocol?
|
||||
private var trackData: PlacePageTrackData
|
||||
private let delegate: ElevationProfileViewControllerDelegate?
|
||||
private weak var trackData: PlacePageTrackData?
|
||||
private weak var delegate: ElevationProfileViewControllerDelegate?
|
||||
private let bookmarkManager: BookmarksManager = .shared()
|
||||
|
||||
private let cellSpacing: CGFloat = 8
|
||||
@@ -85,7 +85,8 @@ extension ElevationProfilePresenter: ElevationProfilePresenterProtocol {
|
||||
view?.isChartViewHidden = false
|
||||
|
||||
let kMinPointsToDraw = 2
|
||||
guard let profileData = trackData.elevationProfileData,
|
||||
guard let trackData = trackData,
|
||||
let profileData = trackData.elevationProfileData,
|
||||
let chartData,
|
||||
chartData.points.count >= kMinPointsToDraw else {
|
||||
view?.userInteractionEnabled = false
|
||||
|
||||
@@ -1270,7 +1270,7 @@
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="72"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="spW-XI-KSY" customClass="PlacePageHeaderView" customModule="CoMaps" customModuleProvider="target">
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="spW-XI-KSY">
|
||||
<rect key="frame" x="0.0" y="62" width="375" height="10"/>
|
||||
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
|
||||
<constraints>
|
||||
@@ -1280,7 +1280,7 @@
|
||||
<userDefinedRuntimeAttribute type="string" keyPath="styleName" value="PPNavigationShadowView"/>
|
||||
</userDefinedRuntimeAttributes>
|
||||
</view>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="fqh-H3-eji" customClass="PlacePageHeaderView" customModule="CoMaps" customModuleProvider="target">
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="fqh-H3-eji">
|
||||
<rect key="frame" x="0.0" y="20" width="375" height="52"/>
|
||||
<subviews>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Gdy-g5-gbM">
|
||||
@@ -1405,13 +1405,13 @@
|
||||
<image name="ic_arrow_gray_down" width="28" height="28"/>
|
||||
<image name="ic_placepage_open_hours" width="28" height="28"/>
|
||||
<systemColor name="separatorColor">
|
||||
<color red="0.23529411759999999" green="0.23529411759999999" blue="0.26274509800000001" alpha="0.28999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<color red="0.23529411764705882" green="0.23529411764705882" blue="0.2627450980392157" alpha="0.28999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
</systemColor>
|
||||
<systemColor name="systemBackgroundColor">
|
||||
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
</systemColor>
|
||||
<systemColor name="systemRedColor">
|
||||
<color red="1" green="0.23137254900000001" blue="0.18823529410000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<color red="1" green="0.23137254901960785" blue="0.18823529411764706" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
</systemColor>
|
||||
</resources>
|
||||
</document>
|
||||
|
||||
@@ -1,81 +1,81 @@
|
||||
class PlacePageCommonLayout: NSObject, IPlacePageLayout {
|
||||
|
||||
|
||||
private let distanceFormatter = DistanceFormatter.self
|
||||
private let altitudeFormatter = AltitudeFormatter.self
|
||||
|
||||
private var placePageData: PlacePageData
|
||||
private var interactor: PlacePageInteractor
|
||||
private let storyboard: UIStoryboard
|
||||
private var lastLocation: CLLocation?
|
||||
|
||||
weak var presenter: PlacePagePresenterProtocol?
|
||||
|
||||
fileprivate var lastLocation: CLLocation?
|
||||
|
||||
lazy var headerViewControllers: [UIViewController] = {
|
||||
var headerViewControllers: [UIViewController] {
|
||||
[headerViewController, previewViewController]
|
||||
}()
|
||||
}
|
||||
|
||||
lazy var bodyViewControllers: [UIViewController] = {
|
||||
return configureViewControllers()
|
||||
configureViewControllers()
|
||||
}()
|
||||
|
||||
var actionBar: ActionBarViewController? {
|
||||
return actionBarViewController
|
||||
actionBarViewController
|
||||
}
|
||||
|
||||
var navigationBar: UIViewController? {
|
||||
return placePageNavigationViewController
|
||||
placePageNavigationViewController
|
||||
}
|
||||
|
||||
|
||||
lazy var headerViewController: PlacePageHeaderViewController = {
|
||||
PlacePageHeaderBuilder.build(data: placePageData, delegate: interactor, headerType: .flexible)
|
||||
}()
|
||||
|
||||
lazy var previewViewController: PlacePagePreviewViewController = {
|
||||
private lazy var previewViewController: PlacePagePreviewViewController = {
|
||||
let vc = storyboard.instantiateViewController(ofType: PlacePagePreviewViewController.self)
|
||||
vc.placePagePreviewData = placePageData.previewData
|
||||
return vc
|
||||
} ()
|
||||
}()
|
||||
|
||||
lazy var wikiDescriptionViewController: WikiDescriptionViewController = {
|
||||
private lazy var wikiDescriptionViewController: WikiDescriptionViewController = {
|
||||
let vc = storyboard.instantiateViewController(ofType: WikiDescriptionViewController.self)
|
||||
vc.view.isHidden = true
|
||||
vc.delegate = interactor
|
||||
return vc
|
||||
} ()
|
||||
}()
|
||||
|
||||
lazy var editBookmarkViewController: PlacePageEditBookmarkOrTrackViewController = {
|
||||
private lazy var editBookmarkViewController: PlacePageEditBookmarkOrTrackViewController = {
|
||||
let vc = storyboard.instantiateViewController(ofType: PlacePageEditBookmarkOrTrackViewController.self)
|
||||
vc.view.isHidden = true
|
||||
vc.delegate = interactor
|
||||
return vc
|
||||
} ()
|
||||
}()
|
||||
|
||||
lazy var infoViewController: PlacePageInfoViewController = {
|
||||
private lazy var infoViewController: PlacePageInfoViewController = {
|
||||
let vc = storyboard.instantiateViewController(ofType: PlacePageInfoViewController.self)
|
||||
vc.placePageInfoData = placePageData.infoData
|
||||
vc.delegate = interactor
|
||||
return vc
|
||||
} ()
|
||||
}()
|
||||
|
||||
lazy var buttonsViewController: PlacePageButtonsViewController = {
|
||||
private lazy var buttonsViewController: PlacePageButtonsViewController = {
|
||||
let vc = storyboard.instantiateViewController(ofType: PlacePageButtonsViewController.self)
|
||||
vc.buttonsData = placePageData.buttonsData!
|
||||
vc.delegate = interactor
|
||||
return vc
|
||||
} ()
|
||||
}()
|
||||
|
||||
lazy var actionBarViewController: ActionBarViewController = {
|
||||
private lazy var actionBarViewController: ActionBarViewController = {
|
||||
let vc = storyboard.instantiateViewController(ofType: ActionBarViewController.self)
|
||||
vc.placePageData = placePageData
|
||||
vc.canAddStop = MWMRouter.canAddIntermediatePoint()
|
||||
vc.isRoutePlanning = MWMNavigationDashboardManager.shared().state != .hidden
|
||||
vc.delegate = interactor
|
||||
return vc
|
||||
} ()
|
||||
}()
|
||||
|
||||
lazy var placePageNavigationViewController: PlacePageHeaderViewController = {
|
||||
private lazy var placePageNavigationViewController: PlacePageHeaderViewController = {
|
||||
return PlacePageHeaderBuilder.build(data: placePageData, delegate: interactor, headerType: .fixed)
|
||||
} ()
|
||||
}()
|
||||
|
||||
init(interactor: PlacePageInteractor, storyboard: UIStoryboard, data: PlacePageData) {
|
||||
self.interactor = interactor
|
||||
@@ -163,7 +163,6 @@ class PlacePageCommonLayout: NSObject, IPlacePageLayout {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - PlacePageData async callbacks for loaders
|
||||
|
||||
extension PlacePageCommonLayout {
|
||||
|
||||
@@ -17,25 +17,25 @@ class PlacePageTrackLayout: IPlacePageLayout {
|
||||
placePageNavigationViewController
|
||||
}
|
||||
|
||||
lazy var headerViewControllers: [UIViewController] = {
|
||||
var headerViewControllers: [UIViewController] {
|
||||
[headerViewController, previewViewController]
|
||||
}()
|
||||
}
|
||||
|
||||
lazy var headerViewController: PlacePageHeaderViewController = {
|
||||
PlacePageHeaderBuilder.build(data: placePageData, delegate: interactor, headerType: .flexible)
|
||||
}()
|
||||
|
||||
lazy var previewViewController: PlacePagePreviewViewController = {
|
||||
private lazy var previewViewController: PlacePagePreviewViewController = {
|
||||
let vc = storyboard.instantiateViewController(ofType: PlacePagePreviewViewController.self)
|
||||
vc.placePagePreviewData = placePageData.previewData
|
||||
return vc
|
||||
}()
|
||||
|
||||
lazy var placePageNavigationViewController: PlacePageHeaderViewController = {
|
||||
private lazy var placePageNavigationViewController: PlacePageHeaderViewController = {
|
||||
return PlacePageHeaderBuilder.build(data: placePageData, delegate: interactor, headerType: .fixed)
|
||||
}()
|
||||
|
||||
lazy var editTrackViewController: PlacePageEditBookmarkOrTrackViewController = {
|
||||
private lazy var editTrackViewController: PlacePageEditBookmarkOrTrackViewController = {
|
||||
let vc = storyboard.instantiateViewController(ofType: PlacePageEditBookmarkOrTrackViewController.self)
|
||||
vc.view.isHidden = true
|
||||
vc.delegate = interactor
|
||||
@@ -49,7 +49,7 @@ class PlacePageTrackLayout: IPlacePageLayout {
|
||||
return ElevationProfileBuilder.build(trackData: trackData, delegate: interactor)
|
||||
}()
|
||||
|
||||
lazy var actionBarViewController: ActionBarViewController = {
|
||||
private lazy var actionBarViewController: ActionBarViewController = {
|
||||
let vc = storyboard.instantiateViewController(ofType: ActionBarViewController.self)
|
||||
vc.placePageData = placePageData
|
||||
vc.canAddStop = MWMRouter.canAddIntermediatePoint()
|
||||
|
||||
@@ -5,7 +5,7 @@ final class PlacePageTrackRecordingLayout: IPlacePageLayout {
|
||||
weak var presenter: PlacePagePresenterProtocol?
|
||||
|
||||
lazy var bodyViewControllers: [UIViewController] = {
|
||||
return configureViewControllers()
|
||||
configureViewControllers()
|
||||
}()
|
||||
|
||||
var actionBar: ActionBarViewController? {
|
||||
@@ -16,19 +16,19 @@ final class PlacePageTrackRecordingLayout: IPlacePageLayout {
|
||||
placePageNavigationViewController
|
||||
}
|
||||
|
||||
lazy var headerViewControllers: [UIViewController] = {
|
||||
var headerViewControllers: [UIViewController] {
|
||||
[headerViewController]
|
||||
}()
|
||||
}
|
||||
|
||||
lazy var headerViewController: PlacePageHeaderViewController = {
|
||||
return PlacePageHeaderBuilder.build(data: placePageData, delegate: interactor, headerType: .flexible)
|
||||
PlacePageHeaderBuilder.build(data: placePageData, delegate: interactor, headerType: .flexible)
|
||||
}()
|
||||
|
||||
lazy var placePageNavigationViewController: PlacePageHeaderViewController = {
|
||||
return PlacePageHeaderBuilder.build(data: placePageData, delegate: interactor, headerType: .fixed)
|
||||
private lazy var placePageNavigationViewController: PlacePageHeaderViewController = {
|
||||
PlacePageHeaderBuilder.build(data: placePageData, delegate: interactor, headerType: .fixed)
|
||||
}()
|
||||
|
||||
lazy var elevationProfileViewController: ElevationProfileViewController? = {
|
||||
private lazy var elevationProfileViewController: ElevationProfileViewController? = {
|
||||
guard let trackData = placePageData.trackData else {
|
||||
return nil
|
||||
}
|
||||
@@ -36,7 +36,7 @@ final class PlacePageTrackRecordingLayout: IPlacePageLayout {
|
||||
delegate: interactor)
|
||||
}()
|
||||
|
||||
lazy var actionBarViewController: ActionBarViewController = {
|
||||
private lazy var actionBarViewController: ActionBarViewController = {
|
||||
let vc = storyboard.instantiateViewController(ofType: ActionBarViewController.self)
|
||||
vc.placePageData = placePageData
|
||||
vc.canAddStop = MWMRouter.canAddIntermediatePoint()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
protocol PlacePageViewProtocol: AnyObject {
|
||||
var interactor: PlacePageInteractorProtocol! { get set }
|
||||
var interactor: PlacePageInteractorProtocol? { get set }
|
||||
|
||||
func setLayout(_ layout: IPlacePageLayout)
|
||||
func closeAnimated(completion: (() -> Void)?)
|
||||
@@ -35,7 +35,7 @@ final class PlacePageScrollView: UIScrollView {
|
||||
stackView.distribution = .fill
|
||||
return stackView
|
||||
}()
|
||||
var interactor: PlacePageInteractorProtocol!
|
||||
var interactor: PlacePageInteractorProtocol?
|
||||
var beginDragging = false
|
||||
var rootViewController: MapViewController {
|
||||
MapViewController.shared()!
|
||||
@@ -220,8 +220,13 @@ final class PlacePageScrollView: UIScrollView {
|
||||
}
|
||||
|
||||
private func cleanupLayout() {
|
||||
layout?.actionBar?.view.removeFromSuperview()
|
||||
layout?.navigationBar?.view.removeFromSuperview()
|
||||
guard let layout else { return }
|
||||
let childViewControllers = [layout.actionBar, layout.navigationBar] + layout.headerViewControllers + layout.bodyViewControllers
|
||||
childViewControllers.forEach {
|
||||
$0?.willMove(toParent: nil)
|
||||
$0?.view.removeFromSuperview()
|
||||
$0?.removeFromParent()
|
||||
}
|
||||
headerStackView.arrangedSubviews.forEach { $0.removeFromSuperview() }
|
||||
stackView.arrangedSubviews.forEach { $0.removeFromSuperview() }
|
||||
}
|
||||
@@ -293,7 +298,7 @@ final class PlacePageScrollView: UIScrollView {
|
||||
|
||||
private func updateTopBound(_ bound: CGFloat, duration: TimeInterval) {
|
||||
alternativeSizeClass(iPhone: {
|
||||
interactor.updateTopBound(bound, duration: duration)
|
||||
interactor?.updateTopBound(bound, duration: duration)
|
||||
}, iPad: {})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user