Skip to content

Commit bd23477

Browse files
committed
Allow mapLoadingIndicator reuse for searching (#10)
Includes renaming and structural changes to get customizable layout margins.
1 parent 13ebdba commit bd23477

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

Pod/Assets/MapViewController.xib

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
<objects>
1111
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="HLFMapViewController">
1212
<connections>
13-
<outlet property="mapLoadingIndicator" destination="bFc-3I-HFj" id="sMc-oj-9X1"/>
13+
<outlet property="mapIndicator" destination="bFc-3I-HFj" id="jLy-Sh-HqJ"/>
1414
<outlet property="mapView" destination="G8V-3k-Wdt" id="Pbp-yq-GB5"/>
1515
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
16+
<outletCollection property="mapIndicatorLoadingConstraints" destination="Uvs-bg-zhB" collectionClass="NSMutableArray" id="65V-0D-RqI"/>
17+
<outletCollection property="mapIndicatorLoadingConstraints" destination="Wcc-GI-BGc" collectionClass="NSMutableArray" id="bZg-Dm-TM7"/>
1618
</connections>
1719
</placeholder>
1820
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
@@ -26,18 +28,30 @@
2628
<outlet property="delegate" destination="-1" id="4j0-hg-bdI"/>
2729
</connections>
2830
</mapView>
29-
<activityIndicatorView opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" hidesWhenStopped="YES" animating="YES" style="whiteLarge" translatesAutoresizingMaskIntoConstraints="NO" id="bFc-3I-HFj">
30-
<rect key="frame" x="169.5" y="315.5" width="37" height="37"/>
31-
</activityIndicatorView>
31+
<view opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="hCJ-Hd-eKb">
32+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
33+
<subviews>
34+
<activityIndicatorView opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" hidesWhenStopped="YES" animating="YES" style="whiteLarge" translatesAutoresizingMaskIntoConstraints="NO" id="bFc-3I-HFj">
35+
<rect key="frame" x="169" y="315" width="37" height="37"/>
36+
</activityIndicatorView>
37+
</subviews>
38+
<constraints>
39+
<constraint firstItem="bFc-3I-HFj" firstAttribute="centerY" secondItem="hCJ-Hd-eKb" secondAttribute="centerY" id="Uvs-bg-zhB"/>
40+
<constraint firstItem="bFc-3I-HFj" firstAttribute="centerX" secondItem="hCJ-Hd-eKb" secondAttribute="centerX" id="Wcc-GI-BGc"/>
41+
</constraints>
42+
<edgeInsets key="layoutMargins" top="15" left="15" bottom="15" right="15"/>
43+
</view>
3244
</subviews>
3345
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
3446
<constraints>
47+
<constraint firstAttribute="bottom" secondItem="hCJ-Hd-eKb" secondAttribute="bottom" id="2UX-Bg-q95"/>
3548
<constraint firstAttribute="bottom" secondItem="G8V-3k-Wdt" secondAttribute="bottom" id="2li-I6-lwV"/>
49+
<constraint firstItem="hCJ-Hd-eKb" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="5Lu-yQ-tsF"/>
50+
<constraint firstItem="hCJ-Hd-eKb" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" id="DQ2-Ij-jNe"/>
51+
<constraint firstAttribute="trailing" secondItem="hCJ-Hd-eKb" secondAttribute="trailing" id="HLk-RL-IFa"/>
3652
<constraint firstItem="G8V-3k-Wdt" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="Yfl-bA-srW"/>
3753
<constraint firstAttribute="trailing" secondItem="G8V-3k-Wdt" secondAttribute="trailing" id="aIN-cg-n6x"/>
38-
<constraint firstItem="bFc-3I-HFj" firstAttribute="centerY" secondItem="i5M-Pr-FkT" secondAttribute="centerY" id="eh2-WS-8M2"/>
3954
<constraint firstItem="G8V-3k-Wdt" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" id="mrn-7J-SUz"/>
40-
<constraint firstItem="bFc-3I-HFj" firstAttribute="centerX" secondItem="i5M-Pr-FkT" secondAttribute="centerX" id="xL3-Sj-dNo"/>
4155
</constraints>
4256
</view>
4357
</objects>

Pod/Classes/MapViewController.swift

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ open class MapViewController: UIViewController {
3636
/** Not required, but this view controller is pretty useless without a delegate. */
3737
open weak var delegate: MapViewControllerDelegate?
3838

39-
@IBOutlet open weak var mapLoadingIndicator: UIActivityIndicatorView!
39+
@available(*, deprecated, renamed: "mapIndicator")
40+
open var mapLoadingIndicator: UIActivityIndicatorView! {
41+
get { return mapIndicator }
42+
set { mapIndicator = newValue }
43+
}
44+
@IBOutlet open var mapIndicator: UIActivityIndicatorView!
4045
@IBOutlet open var mapView: MKMapView!
4146

4247
open fileprivate(set) var locationManager: CLLocationManager!
@@ -56,7 +61,7 @@ open class MapViewController: UIViewController {
5661

5762
initLocationManager()
5863
initSearchController()
59-
mapLoadingIndicator.color = view.tintColor
64+
mapIndicator.color = view.tintColor
6065

6166
// TODO: Handle location loading timeout.
6267
}
@@ -81,6 +86,17 @@ open class MapViewController: UIViewController {
8186

8287
// MARK: Implementation
8388

89+
@IBOutlet fileprivate var mapIndicatorLoadingConstraints: [NSLayoutConstraint]!
90+
fileprivate lazy var mapIndicatorSearchingConstraints: [NSLayoutConstraint] = {
91+
let container = self.mapIndicator.superview!
92+
return [
93+
self.mapIndicator.topAnchor.constraint(
94+
equalTo: self.topLayoutGuide.bottomAnchor, constant: container.layoutMargins.top),
95+
self.mapIndicator.trailingAnchor.constraint(
96+
equalTo: container.layoutMarginsGuide.trailingAnchor),
97+
]
98+
}()
99+
84100
fileprivate var hasSearch: Bool {
85101
return !preparedSearchQuery.isEmpty
86102
}
@@ -234,7 +250,9 @@ open class MapViewController: UIViewController {
234250
fileprivate func revealMapView(completion: (() -> Void)? = nil) {
235251
guard mapView.isHidden else { return }
236252

237-
mapLoadingIndicator.stopAnimating()
253+
mapIndicator.stopAnimating()
254+
NSLayoutConstraint.deactivate(mapIndicatorLoadingConstraints)
255+
NSLayoutConstraint.activate(mapIndicatorSearchingConstraints)
238256

239257
mapView.alpha = 0
240258
mapView.isHidden = false

0 commit comments

Comments
 (0)