Skip to content

Commit

Permalink
Fix crash on YandexMapController.moveCamera
Browse files Browse the repository at this point in the history
  • Loading branch information
DCrow committed Jun 30, 2023
1 parent 7b7ffa8 commit c497198
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,6 @@ public Map<String, Double> getPoint(MethodCall call) {
public void moveCamera(MethodCall call, MethodChannel.Result result) {
Map<String, Object> params = ((Map<String, Object>) call.arguments);

if (mapView.getWidth() == 0 || mapView.getHeight() == 0) {
result.success(false);

return;
}

move(
cameraUpdateToPosition((Map<String, Object>) params.get("cameraUpdate")),
((Map<String, Object>) params.get("animation")),
Expand Down
20 changes: 14 additions & 6 deletions ios/Classes/YandexMapController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,6 @@ public class YandexMapController:
public func moveCamera(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) {
let params = call.arguments as! [String: Any]

if (mapView.frame.isEmpty) {
result(false)

return
}

move(
cameraPosition: cameraUpdateToPosition(params["cameraUpdate"] as! [String: Any]),
animationParams: params["animation"] as? [String: Any],
Expand Down Expand Up @@ -384,11 +378,25 @@ public class YandexMapController:
)
}

private func validCameraPosition(_ cameraPosition: YMKCameraPosition) -> Bool {
return !cameraPosition.zoom.isNaN &&
!cameraPosition.tilt.isNaN &&
!cameraPosition.azimuth.isNaN &&
!cameraPosition.target.latitude.isNaN &&
!cameraPosition.target.longitude.isNaN
}

private func move(
cameraPosition: YMKCameraPosition,
animationParams: [String: Any]?,
result: @escaping FlutterResult
) {
if !validCameraPosition(cameraPosition) {
result(false)

return
}

if animationParams == nil {
mapView.mapWindow.map.move(with: cameraPosition)
result(true)
Expand Down

0 comments on commit c497198

Please sign in to comment.