summaryrefslogtreecommitdiff
path: root/platform/ios
diff options
context:
space:
mode:
authorFabian Guerra Soto <fabian.guerra@mapbox.com>2017-03-03 20:11:06 -0500
committerGitHub <noreply@github.com>2017-03-03 20:11:06 -0500
commit1f1cc131ea869eae57209bcc6ba74ddb3af14579 (patch)
treeca72da32853c0fe50271c15f442edf8cbcf0c3b3 /platform/ios
parent8f892757b5c644986a68133c96684393df800670 (diff)
downloadqtlocation-mapboxgl-1f1cc131ea869eae57209bcc6ba74ddb3af14579.tar.gz
[ios] Fixed conversion between Duration and NSTimeInerval (#8276)
Diffstat (limited to 'platform/ios')
-rw-r--r--platform/ios/ios.xcodeproj/project.pbxproj4
-rw-r--r--platform/ios/src/MGLMapView.mm24
-rw-r--r--platform/ios/test/MGLNSDateAdditionsTests.mm26
3 files changed, 42 insertions, 12 deletions
diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj
index 14548822c9..41cb092e27 100644
--- a/platform/ios/ios.xcodeproj/project.pbxproj
+++ b/platform/ios/ios.xcodeproj/project.pbxproj
@@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
1753ED421E53CE6F00A9FD90 /* MGLConversion.h in Headers */ = {isa = PBXBuildFile; fileRef = 1753ED411E53CE6F00A9FD90 /* MGLConversion.h */; };
1753ED431E53CE6F00A9FD90 /* MGLConversion.h in Headers */ = {isa = PBXBuildFile; fileRef = 1753ED411E53CE6F00A9FD90 /* MGLConversion.h */; };
+ 1F131E341E6A35EC0055AF5B /* MGLNSDateAdditionsTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F131E331E6A35EC0055AF5B /* MGLNSDateAdditionsTests.mm */; };
30E578171DAA85520050F07E /* UIImage+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 30E578111DAA7D690050F07E /* UIImage+MGLAdditions.h */; };
30E578181DAA85520050F07E /* UIImage+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 30E578111DAA7D690050F07E /* UIImage+MGLAdditions.h */; };
30E578191DAA855E0050F07E /* UIImage+MGLAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 30E578121DAA7D690050F07E /* UIImage+MGLAdditions.mm */; };
@@ -526,6 +527,7 @@
/* Begin PBXFileReference section */
1753ED411E53CE6F00A9FD90 /* MGLConversion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLConversion.h; sourceTree = "<group>"; };
+ 1F131E331E6A35EC0055AF5B /* MGLNSDateAdditionsTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLNSDateAdditionsTests.mm; sourceTree = "<group>"; };
20DABE861DF78148007AC5FF /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Foundation.strings"; sourceTree = "<group>"; };
20DABE881DF78148007AC5FF /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
20DABE8A1DF78149007AC5FF /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Root.strings"; sourceTree = "<group>"; };
@@ -1175,6 +1177,7 @@
DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */,
DA2E885C1CC0382C00F24E7B /* MGLGeometryTests.mm */,
35E208A61D24210F00EC9A46 /* MGLNSDataAdditionsTests.m */,
+ 1F131E331E6A35EC0055AF5B /* MGLNSDateAdditionsTests.mm */,
DAE7DEC11E245455007505A6 /* MGLNSStringAdditionsTests.m */,
DA2E885D1CC0382C00F24E7B /* MGLOfflinePackTests.m */,
DA2E885E1CC0382C00F24E7B /* MGLOfflineRegionTests.m */,
@@ -2070,6 +2073,7 @@
40CFA6511D7875BB008103BD /* MGLShapeSourceTests.mm in Sources */,
DA35A2C51CCA9F8300E826B2 /* MGLClockDirectionFormatterTests.m in Sources */,
35B8E08C1D6C8B5100E768D2 /* MGLPredicateTests.mm in Sources */,
+ 1F131E341E6A35EC0055AF5B /* MGLNSDateAdditionsTests.mm in Sources */,
DD58A4C61D822BD000E1F038 /* MGLExpressionTests.mm in Sources */,
3575798B1D502B0C000B822E /* MGLBackgroundStyleLayerTests.mm in Sources */,
DA2E88621CC0382C00F24E7B /* MGLOfflinePackTests.m in Sources */,
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 7119544158..401055341d 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -1237,7 +1237,7 @@ public:
if (![self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)] ||
[self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
{
- _mbglMap->moveBy({ offset.x, offset.y }, MGLDurationInSecondsFromTimeInterval(self.decelerationRate));
+ _mbglMap->moveBy({ offset.x, offset.y }, MGLDurationFromTimeInterval(self.decelerationRate));
}
}
@@ -1346,7 +1346,7 @@ public:
} else {
if (drift)
{
- _mbglMap->setScale(newScale, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }, MGLDurationInSecondsFromTimeInterval(duration));
+ _mbglMap->setScale(newScale, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }, MGLDurationFromTimeInterval(duration));
}
}
@@ -1418,7 +1418,7 @@ public:
if (![self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)] ||
[self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
{
- _mbglMap->setBearing(newDegrees, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }, MGLDurationInSecondsFromTimeInterval(decelerationRate));
+ _mbglMap->setBearing(newDegrees, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }, MGLDurationFromTimeInterval(decelerationRate));
[self notifyGestureDidEndWithDrift:YES];
@@ -1558,7 +1558,7 @@ public:
[self trackGestureEvent:MGLEventGestureDoubleTap forRecognizer:doubleTap];
mbgl::ScreenCoordinate center(gesturePoint.x, gesturePoint.y);
- _mbglMap->setZoom(newZoom, center, MGLDurationInSecondsFromTimeInterval(MGLAnimationDuration));
+ _mbglMap->setZoom(newZoom, center, MGLDurationFromTimeInterval(MGLAnimationDuration));
__weak MGLMapView *weakSelf = self;
@@ -1596,7 +1596,7 @@ public:
[self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
{
mbgl::ScreenCoordinate center(gesturePoint.x, gesturePoint.y);
- _mbglMap->setZoom(newZoom, center, MGLDurationInSecondsFromTimeInterval(MGLAnimationDuration));
+ _mbglMap->setZoom(newZoom, center, MGLDurationFromTimeInterval(MGLAnimationDuration));
__weak MGLMapView *weakSelf = self;
@@ -2426,7 +2426,7 @@ public:
mbgl::AnimationOptions animationOptions;
if (duration)
{
- animationOptions.duration.emplace(MGLDurationInSecondsFromTimeInterval(duration));
+ animationOptions.duration.emplace(MGLDurationFromTimeInterval(duration));
animationOptions.easing.emplace(MGLUnitBezierForMediaTimingFunction(function));
}
if (completion)
@@ -2481,7 +2481,7 @@ public:
_mbglMap->setZoom(zoomLevel,
MGLEdgeInsetsFromNSEdgeInsets(self.contentInset),
- MGLDurationInSecondsFromTimeInterval(duration));
+ MGLDurationFromTimeInterval(duration));
}
- (void)setMinimumZoomLevel:(double)minimumZoomLevel
@@ -2590,7 +2590,7 @@ public:
mbgl::AnimationOptions animationOptions;
if (duration > 0)
{
- animationOptions.duration.emplace(MGLDurationInSecondsFromTimeInterval(duration));
+ animationOptions.duration.emplace(MGLDurationFromTimeInterval(duration));
animationOptions.easing.emplace(MGLUnitBezierForMediaTimingFunction(function));
}
if (completion)
@@ -2653,13 +2653,13 @@ public:
{
_mbglMap->setBearing(direction,
MGLEdgeInsetsFromNSEdgeInsets(self.contentInset),
- MGLDurationInSecondsFromTimeInterval(duration));
+ MGLDurationFromTimeInterval(duration));
}
else
{
CGPoint centerPoint = self.userLocationAnnotationViewCenter;
_mbglMap->setBearing(direction, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y },
- MGLDurationInSecondsFromTimeInterval(duration));
+ MGLDurationFromTimeInterval(duration));
}
}
@@ -2704,7 +2704,7 @@ public:
mbgl::AnimationOptions animationOptions;
if (duration > 0)
{
- animationOptions.duration.emplace(MGLDurationInSecondsFromTimeInterval(duration));
+ animationOptions.duration.emplace(MGLDurationFromTimeInterval(duration));
animationOptions.easing.emplace(MGLUnitBezierForMediaTimingFunction(function));
}
if (completion)
@@ -2754,7 +2754,7 @@ public:
mbgl::AnimationOptions animationOptions;
if (duration >= 0)
{
- animationOptions.duration = MGLDurationInSecondsFromTimeInterval(duration);
+ animationOptions.duration = MGLDurationFromTimeInterval(duration);
}
if (peakAltitude >= 0)
{
diff --git a/platform/ios/test/MGLNSDateAdditionsTests.mm b/platform/ios/test/MGLNSDateAdditionsTests.mm
new file mode 100644
index 0000000000..474fe763ff
--- /dev/null
+++ b/platform/ios/test/MGLNSDateAdditionsTests.mm
@@ -0,0 +1,26 @@
+#import <XCTest/XCTest.h>
+
+#include <mbgl/util/chrono.hpp>
+#import "../../darwin/src/NSDate+MGLAdditions.h"
+
+using namespace std::chrono_literals;
+
+@interface MGLNSDateAdditionsTests : XCTestCase
+@end
+
+@implementation MGLNSDateAdditionsTests
+
+- (void)testDurationToNSTimeInterval {
+
+ NSTimeInterval timeInterval = 5;
+ mbgl::Duration duration = MGLDurationFromTimeInterval(timeInterval);
+ NSTimeInterval durationTimeInterval = MGLTimeIntervalFromDuration(duration);
+
+ mbgl::Duration expectedDuration = 5s;
+
+ XCTAssertEqual(timeInterval, durationTimeInterval);
+ XCTAssertEqual(timeInterval, MGLTimeIntervalFromDuration(expectedDuration));
+
+}
+
+@end