Skip to content

Commit d48fbc5

Browse files
authored
Expose MapboxMap APIs on iOS (#390)
* Update Maps SDK version to v11.2.0-beta.1 * Add version number to examples app pubspec to silence a warning * Add changelog entry * Expose MapboxMap APIs on iOS
1 parent 49904bc commit d48fbc5

File tree

4 files changed

+109
-53
lines changed

4 files changed

+109
-53
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* Add an example representing a traffic route with color based on traffic volumes using LineLayer and Expression.
44
* [Android] Fix MapOptions incorrect index access at map creation, leading to map not being created(blank view).
5+
* [iOS] `MapboxMap`: `isGestureInProgress()`, `isUserAnimationInProgress()`, `setConstrainMode()`, `setNorthOrientation()`, `setViewportMode()` and `reduceMemoryUse()` are now available on iOS.
56
* Bump platform Maps SDK dependencies to 11.2.0-beta.1.
67

78
### 1.0.0-beta.2

example/integration_test/map_interface_test.dart

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ void main() {
5757
expect(size.width, tester.binding.renderView.size.width);
5858
expect(size.height, tester.binding.renderView.size.height);
5959
});
60+
}
6061

61-
testWidgets('reduceMemoryUse', (WidgetTester tester) async {
62-
final mapFuture = app.main();
63-
await tester.pumpAndSettle();
64-
final mapboxMap = await mapFuture;
62+
testWidgets('reduceMemoryUse', (WidgetTester tester) async {
63+
final mapFuture = app.main();
64+
await tester.pumpAndSettle();
65+
final mapboxMap = await mapFuture;
6566

66-
await mapboxMap.reduceMemoryUse();
67-
});
68-
}
67+
await mapboxMap.reduceMemoryUse();
68+
});
6969

7070
testWidgets('triggerRepaint', (WidgetTester tester) async {
7171
final mapFuture = app.main();
@@ -88,59 +88,47 @@ void main() {
8888
await tester.pumpAndSettle();
8989
final mapboxMap = await mapFuture;
9090
var options = await mapboxMap.getMapOptions();
91-
if (Platform.isAndroid) {
92-
expect(options.orientation, NorthOrientation.UPWARDS);
93-
expect(options.constrainMode, ConstrainMode.HEIGHT_ONLY);
94-
expect(options.contextMode, isNull);
95-
expect(options.viewportMode, ViewportMode.DEFAULT);
96-
}
91+
expect(options.orientation, NorthOrientation.UPWARDS);
92+
expect(options.constrainMode, ConstrainMode.HEIGHT_ONLY);
93+
expect(options.contextMode, isNull);
94+
expect(options.viewportMode, ViewportMode.DEFAULT);
95+
9796
expect(options.crossSourceCollisions, true);
9897
expect(options.pixelRatio, tester.binding.window.devicePixelRatio);
9998
expect(options.glyphsRasterizationOptions, isNull);
10099
expect(options.size!.width, isNotNull);
101100
expect(options.size!.height, isNotNull);
102-
if (Platform.isAndroid) {
103-
await mapboxMap.setConstrainMode(ConstrainMode.WIDTH_AND_HEIGHT);
104-
await mapboxMap.setNorthOrientation(NorthOrientation.DOWNWARDS);
105-
await mapboxMap.setViewportMode(ViewportMode.FLIPPED_Y);
106-
107-
options = await mapboxMap.getMapOptions();
108-
expect(options.orientation, NorthOrientation.DOWNWARDS);
109-
expect(options.constrainMode, ConstrainMode.WIDTH_AND_HEIGHT);
110-
expect(options.viewportMode, ViewportMode.FLIPPED_Y);
111-
}
101+
102+
await mapboxMap.setConstrainMode(ConstrainMode.WIDTH_AND_HEIGHT);
103+
await mapboxMap.setNorthOrientation(NorthOrientation.DOWNWARDS);
104+
await mapboxMap.setViewportMode(ViewportMode.FLIPPED_Y);
105+
106+
options = await mapboxMap.getMapOptions();
107+
expect(options.orientation, NorthOrientation.DOWNWARDS);
108+
expect(options.constrainMode, ConstrainMode.WIDTH_AND_HEIGHT);
109+
expect(options.viewportMode, ViewportMode.FLIPPED_Y);
112110
});
113111

114112
testWidgets('isGestureInProgress', (WidgetTester tester) async {
115113
final mapFuture = app.main();
116114
await tester.pumpAndSettle();
117115
final mapboxMap = await mapFuture;
118-
if (Platform.isAndroid) {
119-
var isGestureInProgress = await mapboxMap.isGestureInProgress();
120-
expect(isGestureInProgress, false);
121-
}
116+
117+
expect(await mapboxMap.isGestureInProgress(), false);
118+
122119
await mapboxMap.setGestureInProgress(true);
123-
if (Platform.isAndroid) {
124-
var isGestureInProgress = await mapboxMap.isGestureInProgress();
125-
expect(isGestureInProgress, true);
126-
}
120+
expect(await mapboxMap.isGestureInProgress(), true);
127121
});
128122

129123
testWidgets('isUserAnimationInProgress', (WidgetTester tester) async {
130124
final mapFuture = app.main();
131125
await tester.pumpAndSettle();
132126
final mapboxMap = await mapFuture;
133-
if (Platform.isAndroid) {
134-
var isUserAnimationInProgress =
135-
await mapboxMap.isUserAnimationInProgress();
136-
expect(isUserAnimationInProgress, false);
137-
}
127+
128+
expect(await mapboxMap.isUserAnimationInProgress(), false);
129+
138130
await mapboxMap.setUserAnimationInProgress(true);
139-
if (Platform.isAndroid) {
140-
var isUserAnimationInProgress =
141-
await mapboxMap.isUserAnimationInProgress();
142-
expect(isUserAnimationInProgress, true);
143-
}
131+
expect(await mapboxMap.isUserAnimationInProgress(), true);
144132
});
145133

146134
testWidgets('debugOptions', (WidgetTester tester) async {

ios/Classes/Extensions.swift

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,42 @@ import MapboxMaps
33
import MapboxCoreMaps_Private
44

55
let COORDINATES = "coordinates"
6+
67
// FLT to Mapbox
8+
9+
extension FLTViewportMode {
10+
func toViewportMode() -> ViewportMode {
11+
switch self {
12+
case .DEFAULT: return .default
13+
case .FLIPPED_Y: return .flippedY
14+
@unknown default: return .default
15+
}
16+
}
17+
}
18+
19+
extension FLTConstrainMode {
20+
func toConstrainMode() -> ConstrainMode {
21+
switch self {
22+
case .NONE: return .none
23+
case .HEIGHT_ONLY: return .heightOnly
24+
case .WIDTH_AND_HEIGHT: return .widthAndHeight
25+
@unknown default: return .none
26+
}
27+
}
28+
}
29+
30+
extension FLTNorthOrientation {
31+
func toNorthOrientation() -> NorthOrientation {
32+
switch self {
33+
case .UPWARDS: return .upwards
34+
case .RIGHTWARDS: return .rightwards
35+
case .DOWNWARDS: return .downwards
36+
case .LEFTWARDS: return .leftwards
37+
@unknown default: return .upwards
38+
}
39+
}
40+
}
41+
742
extension FLTTileCacheBudgetInMegabytes {
843
func toTileCacheBudgetInMegabytes() -> TileCacheBudgetInMegabytes {
944
return .init(size: UInt64(size))
@@ -129,6 +164,40 @@ extension FLTMbxEdgeInsets {
129164
}
130165

131166
// Mapbox to FLT
167+
168+
extension ConstrainMode {
169+
func toFLTConstrainMode() -> FLTConstrainMode {
170+
switch self {
171+
case .heightOnly: return .HEIGHT_ONLY
172+
case .widthAndHeight: return .WIDTH_AND_HEIGHT
173+
case .none: return .NONE
174+
@unknown default: return .NONE
175+
}
176+
}
177+
}
178+
179+
extension ViewportMode {
180+
func toFLTViewportMode() -> FLTViewportMode {
181+
switch self {
182+
case .default: return .DEFAULT
183+
case .flippedY: return .FLIPPED_Y
184+
@unknown default: return .DEFAULT
185+
}
186+
}
187+
}
188+
189+
extension NorthOrientation {
190+
func toFLTNorthOrientation() -> FLTNorthOrientation {
191+
switch self {
192+
case .upwards: return .UPWARDS
193+
case .leftwards: return .LEFTWARDS
194+
case .rightwards: return .RIGHTWARDS
195+
case .downwards: return .DOWNWARDS
196+
@unknown default: return .UPWARDS
197+
}
198+
}
199+
}
200+
132201
extension Feature {
133202
func toMap() -> [String: Any] {
134203
let jsonData = try! JSONEncoder().encode(geoJSONObject)
@@ -187,10 +256,10 @@ extension GlyphsRasterizationOptions {
187256
extension MapOptions {
188257
func toFLTMapOptions() -> FLTMapOptions {
189258
return FLTMapOptions.make(
190-
withContextMode: .init(value: .SHARED),
191-
constrainMode: .init(value: .NONE),
192-
viewportMode: .init(value: .DEFAULT),
193-
orientation: .init(value: .UPWARDS),
259+
withContextMode: nil,
260+
constrainMode: .init(value: __constrainMode.map { ConstrainMode(rawValue: $0.intValue) }??.toFLTConstrainMode() ?? .NONE),
261+
viewportMode: .init(value: __viewportMode.map { ViewportMode(rawValue: $0.intValue) }??.toFLTViewportMode() ?? .DEFAULT),
262+
orientation: .init(value: __orientation.map { NorthOrientation(rawValue: $0.intValue) }??.toFLTNorthOrientation() ?? .UPWARDS),
194263
crossSourceCollisions: NSNumber(value: self.crossSourceCollisions),
195264
size: self.size?.toFLTSize(),
196265
pixelRatio: Double(pixelRatio),

ios/Classes/MapInterfaceController.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ class MapInterfaceController: NSObject, FLT_MapInterface {
7878
}
7979

8080
func isGestureInProgressWithError(_ error: AutoreleasingUnsafeMutablePointer<FlutterError?>) -> NSNumber? {
81-
error.pointee = FlutterError(code: MapInterfaceController.errorCode, message: "Not available.", details: nil)
82-
return false
81+
return NSNumber(value: mapboxMap.isGestureInProgress)
8382
}
8483

8584
func setUserAnimationInProgressInProgress(_ inProgress: Bool, error: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
@@ -91,8 +90,7 @@ class MapInterfaceController: NSObject, FLT_MapInterface {
9190
}
9291

9392
func isUserAnimationInProgressWithError(_ error: AutoreleasingUnsafeMutablePointer<FlutterError?>) -> NSNumber? {
94-
error.pointee = FlutterError(code: MapInterfaceController.errorCode, message: "Not available.", details: nil)
95-
return false
93+
return NSNumber(value: mapboxMap.isAnimationInProgress)
9694
}
9795

9896
func setPrefetchZoomDeltaDelta(_ delta: Int, error: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
@@ -104,15 +102,15 @@ class MapInterfaceController: NSObject, FLT_MapInterface {
104102
}
105103

106104
func setNorthOrientationOrientation(_ orientation: FLTNorthOrientation, error: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
107-
error.pointee = FlutterError(code: MapInterfaceController.errorCode, message: "Not available.", details: nil)
105+
mapboxMap.setNorthOrientation(orientation.toNorthOrientation())
108106
}
109107

110108
func setConstrainModeMode(_ mode: FLTConstrainMode, error: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
111-
error.pointee = FlutterError(code: MapInterfaceController.errorCode, message: "Not available.", details: nil)
109+
mapboxMap.setConstrainMode(mode.toConstrainMode())
112110
}
113111

114112
func setViewportModeMode(_ mode: FLTViewportMode, error: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
115-
error.pointee = FlutterError(code: MapInterfaceController.errorCode, message: "Not available.", details: nil)
113+
mapboxMap.setViewportMode(mode.toViewportMode())
116114
}
117115

118116
func getMapOptionsWithError(_ error: AutoreleasingUnsafeMutablePointer<FlutterError?>) -> FLTMapOptions? {
@@ -270,7 +268,7 @@ class MapInterfaceController: NSObject, FLT_MapInterface {
270268
}
271269

272270
func reduceMemoryUseWithError(_ error: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
273-
error.pointee = FlutterError(code: MapInterfaceController.errorCode, message: "Not available.", details: nil)
271+
mapboxMap.reduceMemoryUse()
274272
}
275273

276274
func getElevationCoordinate(_ coordinate: [String: Any], error: AutoreleasingUnsafeMutablePointer<FlutterError?>) -> NSNumber? {

0 commit comments

Comments
 (0)