Skip to content

Commit ca1e114

Browse files
aleksprogerevil159
authored andcommitted
Indoor selector iOS UI (#7853)
- UI for indoor floor selection on iOS integrated with OrnamentsManager - Changed more gesture recognizers to only intercepts gestures when Map is the top-most view as some of them already modify in that way to allow proper gesture handling in SwiftUI, but also added it for scroll related gesturez as the map was intercepting gesturs that should be hadnled bu the UI control - Add possibility to stack view inside of the same OrnamentsPosition https://github.com/user-attachments/assets/fba353e5-89dc-438d-bda9-a60b4c048eec cc @mapbox/maps-ios --------- Co-authored-by: Roman Laitarenko <[email protected]> GitOrigin-RevId: d288bd995cf283f27eb6300c7ac958ab58cf7df0
1 parent f0e3ecc commit ca1e114

18 files changed

+636
-60
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
.DS_Store
22
/build
33
.build
4+
.create-xcframework
5+
artifacts
46
/Packages
57
xcuserdata
68
node_modules

Sources/Examples/All Examples/Lab/IndoorExample.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ final class IndoorExample: UIViewController, ExampleProtocol {
66
private var mapView: MapView!
77
// Set indoor style. Do not commit staging style URIs.
88
private var styleURI: String?
9+
private var cancellables = Set<AnyCancelable>()
910

1011
override func viewDidLoad() {
1112
super.viewDidLoad()
@@ -23,10 +24,10 @@ final class IndoorExample: UIViewController, ExampleProtocol {
2324
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
2425
mapView.ornaments.options.scaleBar.visibility = .visible
2526
// EXPERIMENTAL: Not intended for usage in current stata. Subject to change or deletion.
26-
// mapView.mapboxMap.indoor.selectFloor(selectedFloorId: "b937e2aa3423453ab0552d9f")
27-
// mapView.mapboxMap.indoor.onIndoorUpdate { indoorState in
28-
// print(indoorState)
29-
// }
27+
mapView.mapboxMap.indoor.selectFloor(selectedFloorId: "b937e2aa3423453ab0552d9f")
28+
mapView.mapboxMap.indoor.onIndoorUpdated.sink { indoorState in
29+
print(indoorState)
30+
}.store(in: &cancellables)
3031

3132
view.addSubview(mapView)
3233
}

Sources/MapboxMaps/Foundation/CoreAliases.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ typealias CoreFeaturesetDescriptor = MapboxCoreMaps_Private.FeaturesetDescriptor
4949
typealias CoreColorTheme = MapboxCoreMaps_Private.ColorTheme
5050
typealias CoreAsyncOperationResultCallback = MapboxCoreMaps_Private.AsyncOperationResultCallback
5151
typealias UIEdgeInsetsCodable = MapboxCoreMaps.UIEdgeInsetsCodable
52+
typealias CoreIndoorManager = MapboxCoreMaps_Private.__IndoorManager

Sources/MapboxMaps/Foundation/MapView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,8 @@ open class MapView: UIView, SizeTrackingLayerDelegate {
496496
logoView: LogoView(logoSize: .regular()),
497497
scaleBarView: MapboxScaleBarOrnamentView(),
498498
compassView: MapboxCompassOrnamentView(),
499-
attributionButton: InfoButtonOrnament())
499+
attributionButton: InfoButtonOrnament(),
500+
indoorSelectorView: IndoorSelectorView(model: IndoorSelectorModel(indoorManager: mapboxMap.indoor)))
500501

501502
// Initialize/Configure location source and location manager
502503
location = LocationManager(

Sources/MapboxMaps/Foundation/MapboxMap.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ public final class MapboxMap: StyleManager {
213213
@_spi(Internal)
214214
public lazy var map: MapboxCoreMaps.Map = .Marshaller.toSwift(__map)
215215

216-
// @_spi(Experimental)
217-
// public lazy var indoor: IndoorManager = .Marshaller.toSwift(__map.getIndoorManager())
216+
@_spi(Experimental)
217+
public lazy var indoor: IndoorManager = .Marshaller.toSwift(__map.getIndoorManager())
218218

219219
deinit {
220220
__map.destroyRenderer()

Sources/MapboxMaps/Gestures/GestureHandlers/DoubleTapToZoomInGestureHandler.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ internal final class DoubleTapToZoomInGestureHandler: GestureHandler, FocusableG
1616
self.mapboxMap = mapboxMap
1717
self.cameraAnimationsManager = cameraAnimationsManager
1818
super.init(gestureRecognizer: gestureRecognizer)
19+
gestureRecognizer.delegate = self
1920
gestureRecognizer.addTarget(self, action: #selector(handleGesture(_:)))
2021
}
2122

@@ -38,3 +39,14 @@ internal final class DoubleTapToZoomInGestureHandler: GestureHandler, FocusableG
3839
}
3940
}
4041
}
42+
43+
extension DoubleTapToZoomInGestureHandler: UIGestureRecognizerDelegate {
44+
func gestureRecognizer(
45+
_ gestureRecognizer: UIGestureRecognizer,
46+
shouldReceive touch: UITouch
47+
) -> Bool {
48+
/// Only handle touches that targeting the map, but any of its subviews (including view annotations and ornaments)
49+
assert(self.gestureRecognizer == gestureRecognizer)
50+
return gestureRecognizer.attachedToSameView(as: touch)
51+
}
52+
}

Sources/MapboxMaps/Gestures/GestureHandlers/PanGestureHandler.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,15 @@ extension PanGestureHandler: UIGestureRecognizerDelegate {
187187
return false
188188
}
189189
}
190+
191+
func gestureRecognizer(
192+
_ gestureRecognizer: UIGestureRecognizer,
193+
shouldReceive touch: UITouch
194+
) -> Bool {
195+
/// Only handle touches that targeting the map, but any of its subviews (including view annotations and ornaments).
196+
assert(self.gestureRecognizer == gestureRecognizer)
197+
return gestureRecognizer.attachedToSameView(as: touch)
198+
}
190199
}
191200

192201
private extension CGPoint {

Sources/MapboxMaps/Gestures/GestureHandlers/PinchGestureHandler.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ extension PinchGestureHandler: UIGestureRecognizerDelegate {
9393
return self.gestureRecognizer === gestureRecognizer && zoomEnabled
9494
}
9595

96+
func gestureRecognizer(
97+
_ gestureRecognizer: UIGestureRecognizer,
98+
shouldReceive touch: UITouch
99+
) -> Bool {
100+
/// Only handle touches that targeting the map, but any of its subviews (including view annotations and ornaments)
101+
assert(self.gestureRecognizer == gestureRecognizer)
102+
return gestureRecognizer.attachedToSameView(as: touch)
103+
}
104+
96105
func gestureRecognizer(
97106
_ gestureRecognizer: UIGestureRecognizer,
98107
shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer

Sources/MapboxMaps/Gestures/GestureHandlers/QuickZoomGestureHandler.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ internal final class QuickZoomGestureHandler: GestureHandler, FocusableGestureHa
1414
gestureRecognizer.minimumPressDuration = 0
1515
self.mapboxMap = mapboxMap
1616
super.init(gestureRecognizer: gestureRecognizer)
17+
gestureRecognizer.delegate = self
1718
gestureRecognizer.addTarget(self, action: #selector(handleGesture(_:)))
1819
}
1920

@@ -48,3 +49,14 @@ internal final class QuickZoomGestureHandler: GestureHandler, FocusableGestureHa
4849
}
4950
}
5051
}
52+
53+
extension QuickZoomGestureHandler: UIGestureRecognizerDelegate {
54+
func gestureRecognizer(
55+
_ gestureRecognizer: UIGestureRecognizer,
56+
shouldReceive touch: UITouch
57+
) -> Bool {
58+
/// Only handle touches that targeting the map, but any of its subviews (including view annotations and ornaments)
59+
assert(self.gestureRecognizer == gestureRecognizer)
60+
return gestureRecognizer.attachedToSameView(as: touch)
61+
}
62+
}

Sources/MapboxMaps/Gestures/GestureHandlers/RotateGestureHandler.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,13 @@ extension RotateGestureHandler: UIGestureRecognizerDelegate {
100100
return otherGestureRecognizer is UIPinchGestureRecognizer &&
101101
simultaneousRotateAndPinchZoomEnabled
102102
}
103+
104+
func gestureRecognizer(
105+
_ gestureRecognizer: UIGestureRecognizer,
106+
shouldReceive touch: UITouch
107+
) -> Bool {
108+
/// Only handle touches that targeting the map, but any of its subviews (including view annotations and ornaments)
109+
assert(self.gestureRecognizer == gestureRecognizer)
110+
return gestureRecognizer.attachedToSameView(as: touch)
111+
}
103112
}

0 commit comments

Comments
 (0)