Skip to content
Open
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
18 changes: 9 additions & 9 deletions ios/RNMBX/RNMBXCamera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -595,14 +595,14 @@ open class RNMBXCamera : RNMBXMapAndMapViewComponentBase {
return super.removeFromMap(map, mapView: mapView, reason: reason)
}

@objc public func moveBy(x: Double, y: Double, animationMode: NSNumber?, animationDuration: NSNumber?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
@objc public func moveBy(x: Double, y: Double, animationMode: Double, animationDuration: Double, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
withMapView { mapView in
let contentFrame = mapView.bounds.inset(by: mapView.safeAreaInsets)
let centerPoint = CGPoint(x: contentFrame.midX, y: contentFrame.midY)
let endCameraPoint = CGPoint(x: centerPoint.x + x, y: centerPoint.y + y)
let cameraOptions = mapView.mapboxMap.dragCameraOptions(from: centerPoint, to: endCameraPoint)

let duration = (animationDuration?.doubleValue ?? 0.0) / 1000
let duration = animationDuration / 1000

if (duration == 0.0) {
mapView.mapboxMap.setCamera(to: cameraOptions)
Expand All @@ -611,7 +611,7 @@ open class RNMBXCamera : RNMBXMapAndMapViewComponentBase {
}

var curve: UIView.AnimationCurve = .linear
if let m = animationMode?.intValue, let m = CameraMode(rawValue: m) {
if let m = CameraMode(rawValue: Int(animationMode)) {
curve = m == CameraMode.ease ? .easeInOut : .linear
}

Expand All @@ -622,18 +622,18 @@ open class RNMBXCamera : RNMBXMapAndMapViewComponentBase {
@objc public func scaleBy(
x: Double,
y: Double,
scaleFactor: NSNumber,
animationMode: NSNumber?,
animationDuration: NSNumber?,
scaleFactor: Double,
animationMode: Double,
animationDuration: Double,
resolve: @escaping RCTPromiseResolveBlock,
reject: @escaping RCTPromiseRejectBlock
) {
withMapView { mapView in
let currentZoom = mapView.cameraState.zoom
let newZoom = currentZoom + log2(scaleFactor.doubleValue)
let newZoom = currentZoom + log2(scaleFactor)
let anchor = CGPoint(x: x, y: y)
let cameraOptions = CameraOptions(anchor: anchor, zoom: newZoom)
let duration = (animationDuration?.doubleValue ?? 0.0) / 1000
let duration = animationDuration / 1000

if (duration == 0.0) {
mapView.mapboxMap.setCamera(to: cameraOptions)
Expand All @@ -642,7 +642,7 @@ open class RNMBXCamera : RNMBXMapAndMapViewComponentBase {
}

var curve: UIView.AnimationCurve = .linear
if let m = animationMode?.intValue, let m = CameraMode(rawValue: m) {
if let m = CameraMode(rawValue: Int(animationMode)) {
curve = m == CameraMode.ease ? .easeInOut : .linear
}

Expand Down
10 changes: 5 additions & 5 deletions ios/RNMBX/RNMBXCameraModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ - (void)withCamera:(nonnull NSNumber*)viewRef block:(void (^)(RNMBXCamera *))blo
RCT_EXPORT_METHOD(moveBy:(nonnull NSNumber *)viewRef
x:(double)x
y:(double)y
animationMode:(nonnull NSNumber *)animationMode
animationDuration:(nonnull NSNumber *)animationDuration
animationMode:(double)animationMode
animationDuration:(double)animationDuration
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
[self withCamera:viewRef block:^(RNMBXCamera *camera) {
Expand All @@ -65,9 +65,9 @@ - (void)withCamera:(nonnull NSNumber*)viewRef block:(void (^)(RNMBXCamera *))blo
RCT_EXPORT_METHOD(scaleBy:(nonnull NSNumber *)viewRef
x:(double)x
y:(double)y
animationMode:(nonnull NSNumber *)animationMode
animationDuration:(nonnull NSNumber *)animationDuration
scaleFactor:(nonnull NSNumber *)scaleFactor
animationMode:(double)animationMode
animationDuration:(double)animationDuration
scaleFactor:(double)scaleFactor
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
[self withCamera:viewRef block:^(RNMBXCamera *camera) {
Expand Down
Loading