Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose RouteController.routeProgress to Objective-C #1323

Merged
merged 3 commits into from
Apr 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## master

* `RouteController`’s `routeProgress` is now exposed to Objective-C. [#1323](https://github.com/mapbox/mapbox-navigation-ios/pull/1323)
* Exit indications are now drawn accurately with a correct exit bearing. [#1288](https://github.com/mapbox/mapbox-navigation-ios/pull/1288)
* Added a delegate method, `NavigationViewControllerDelegate.navigationViewController(_:roadNameAt:)` which allows you to customize the contents of the road name label displayed towards the bottom of the map view. [#1309](https://github.com/mapbox/mapbox-navigation-ios/pull/1309)

Expand Down
2 changes: 1 addition & 1 deletion MapboxCoreNavigation/RouteController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ open class RouteController: NSObject {
/**
Details about the user’s progress along the current route, leg, and step.
*/
public var routeProgress: RouteProgress {
@objc public var routeProgress: RouteProgress {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides exposing the property to Objective-C, this change also switches the property’s getter and setter to use Objective-C method dispatch. The willSet and didSet should continue to work just like before, but it’s worth double-checking to be sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4f21e5a verifies that the notification in the property’s didSet gets fired.

willSet {
// Save any progress completed up until now
sessionState.totalDistanceCompleted += routeProgress.distanceTraveled
Expand Down
42 changes: 42 additions & 0 deletions MapboxCoreNavigationTests/BridgingTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#import <XCTest/XCTest.h>
#import "MapboxCoreNavigationTests-Swift.h"
@import Mapbox;
@import MapboxCoreNavigation;
@import MapboxDirections;

@interface BridgingTests : XCTestCase

@end

@implementation BridgingTests

- (void)setUp {
[super setUp];
}

- (void)testUpdateRoute {
NSDictionary *response = [MBFixture JSONFromFileNamedWithName:@"routeWithInstructions"];
NSDictionary *routeDict = response[@"routes"][0];
MBWaypoint *wp1 = [[MBWaypoint alloc] initWithCoordinate:CLLocationCoordinate2DMake(37.795042, -122.413165) coordinateAccuracy:0 name:@"wp1"];
MBWaypoint *wp2 = [[MBWaypoint alloc] initWithCoordinate:CLLocationCoordinate2DMake(37.7727, -122.433378) coordinateAccuracy:0 name:@"wp2"];
NSArray<MBWaypoint *> *waypoints = @[wp1, wp2];
MBNavigationRouteOptions *options = [[MBNavigationRouteOptions alloc] initWithWaypoints:waypoints profileIdentifier:MBDirectionsProfileIdentifierAutomobileAvoidingTraffic];
MBRoute *route = [[MBRoute alloc] initWithJson:routeDict waypoints:waypoints routeOptions:options];
route.accessToken = @"garbage";
XCTAssertNotNil(route);
MBEventsManagerSpy *eventsManager = [[MBEventsManagerSpy alloc] init];
MBDirectionsSpy *directions = [[MBDirectionsSpy alloc] initWithAccessToken:@"garbage" host:nil];
MBNavigationLocationManager *locationManager = [[MBNavigationLocationManager alloc] init];
MBRouteController *routeController = [[MBRouteController alloc] initWithRoute:route directions:directions locationManager:locationManager eventsManager:eventsManager];
XCTAssertNotNil(routeController);

XCTestExpectation *expectation = [self expectationForNotification:MBRouteControllerDidRerouteNotification object:nil handler:^BOOL(NSNotification * _Nonnull notification) {
return YES;
}];

routeController.routeProgress = [[MBRouteProgress alloc] initWithRoute:route legIndex:0 spokenInstructionIndex:0];
[self waitForExpectations:@[expectation] timeout:5];
}

@end

7 changes: 4 additions & 3 deletions MapboxCoreNavigationTests/Fixture.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import XCTest
import Foundation

class Fixture {
class func stringFromFileNamed(name: String) -> String {
@objc(MBFixture)
class Fixture: NSObject {
@objc class func stringFromFileNamed(name: String) -> String {
guard let path = Bundle(for: self).path(forResource: name, ofType: "json") ?? Bundle(for: self).path(forResource: name, ofType: "geojson") else {
XCTAssert(false, "Fixture \(name) not found.")
return ""
Expand All @@ -15,7 +16,7 @@ class Fixture {
}
}

class func JSONFromFileNamed(name: String) -> [String: Any] {
@objc class func JSONFromFileNamed(name: String) -> [String: Any] {
guard let path = Bundle(for: self).path(forResource: name, ofType: "json") ?? Bundle(for: self).path(forResource: name, ofType: "geojson") else {
XCTAssert(false, "Fixture \(name) not found.")
return [:]
Expand Down
1 change: 1 addition & 0 deletions MapboxCoreNavigationTests/Support/DirectionsSpy.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation
import MapboxDirections

@objc(MBDirectionsSpy)
class DirectionsSpy: Directions {

var lastCalculateOptionsCompletion: RouteCompletionHandler?
Expand Down
1 change: 1 addition & 0 deletions MapboxCoreNavigationTests/Support/EventsManagerSpy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import MapboxMobileEvents

typealias MockTelemetryEvent = (name: String, attributes: [String: Any])

@objc(MBEventsManagerSpy)
class EventsManagerSpy: MMEEventsManager {

private var enqueuedEvents = [MockTelemetryEvent]()
Expand Down
4 changes: 4 additions & 0 deletions MapboxNavigation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
35B839491E2E3D5D0045A868 /* MBRouteController.m in Sources */ = {isa = PBXBuildFile; fileRef = 35B839481E2E3D5D0045A868 /* MBRouteController.m */; };
35BF8CA21F28EB60003F6125 /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35BF8CA11F28EB60003F6125 /* Array.swift */; };
35BF8CA41F28EBD8003F6125 /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35BF8CA31F28EBD8003F6125 /* String.swift */; };
35C57D6A208DD4A200BDD2A6 /* BridgingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 35C57D69208DD4A200BDD2A6 /* BridgingTests.m */; };
35C6A35B1E5E418D0004CA57 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 35C6A34D1E5E418D0004CA57 /* ViewController.m */; };
35C714AE203B251300F0C2AE /* MapboxSpeech.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C5A9DDBD202E12EE007D52DA /* MapboxSpeech.framework */; };
35C714AF203B251300F0C2AE /* MapboxSpeech.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C5A9DDBD202E12EE007D52DA /* MapboxSpeech.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
Expand Down Expand Up @@ -519,6 +520,7 @@
35B839481E2E3D5D0045A868 /* MBRouteController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MBRouteController.m; sourceTree = "<group>"; };
35BF8CA11F28EB60003F6125 /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = "<group>"; };
35BF8CA31F28EBD8003F6125 /* String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = String.swift; sourceTree = "<group>"; };
35C57D69208DD4A200BDD2A6 /* BridgingTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BridgingTests.m; sourceTree = "<group>"; };
35C6A3461E5E418D0004CA57 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
35C6A3471E5E418D0004CA57 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
35C6A34C1E5E418D0004CA57 /* ViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1222,6 +1224,7 @@
C5BF7371206AB0DF00CDBB6D /* CLHeadingPrivate.h */,
C5BF7370206AB0DE00CDBB6D /* MapboxCoreNavigationTests-Bridging-Header.h */,
C582BA2B2073E77E00647DAA /* StringTests.swift */,
35C57D69208DD4A200BDD2A6 /* BridgingTests.m */,
);
path = MapboxCoreNavigationTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -1951,6 +1954,7 @@
C52AC1261DF0E48600396B9F /* RouteProgressTests.swift in Sources */,
359574AA1F28CCBB00838209 /* LocationTests.swift in Sources */,
C582BA2C2073E77E00647DAA /* StringTests.swift in Sources */,
35C57D6A208DD4A200BDD2A6 /* BridgingTests.m in Sources */,
C52D09D31DEF636C00BE3C5C /* Fixture.swift in Sources */,
16435E03206EE32F00AF48B6 /* DirectionsSpy.swift in Sources */,
C5ABB50E20408D2C00AFA92C /* RouteControllerTests.swift in Sources */,
Expand Down