Skip to content

Commit

Permalink
Fix iOS crash on incorrect focusRect
Browse files Browse the repository at this point in the history
  • Loading branch information
DCrow committed Apr 25, 2022
1 parent e5a9211 commit d6f04f7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
9 changes: 6 additions & 3 deletions example/lib/examples/map_controls_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,13 @@ class _MapControlsExampleState extends State<_MapControlsExample> {
children: <Widget>[
ControlButton(
onPressed: () async {
final cameraPosition = await controller.getCameraPosition();
final screenPoint = await controller.getScreenPoint(cameraPosition.target);

setState(() {
screenRect = const ScreenRect(
bottomRight: ScreenPoint(x: 600, y: 600),
topLeft: ScreenPoint(x: 200, y: 200)
screenRect = ScreenRect(
topLeft: ScreenPoint(x: 0, y: 0),
bottomRight: screenPoint!
);
});
},
Expand Down
9 changes: 9 additions & 0 deletions ios/Classes/YandexMapController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,15 @@ public class YandexMapController:
bottomRight: Utils.screenPointFromJson(params!["bottomRight"] as! [String: NSNumber])
)

if (
screenRect.topLeft.y < 0 ||
screenRect.topLeft.x < 0 ||
screenRect.bottomRight.y > Float(mapView.mapWindow.height()) ||
screenRect.bottomRight.x > Float(mapView.mapWindow.width())
) {
return
}

mapView.mapWindow.focusRect = screenRect
mapView.mapWindow.pointOfView = YMKPointOfView.adaptToFocusRectHorizontally
}
Expand Down

0 comments on commit d6f04f7

Please sign in to comment.