Skip to content

Commit

Permalink
Merge branch 'pr/41'
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisThein committed Jan 25, 2024
2 parents 34c5e7d + d0e8f4c commit 34f8624
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Changelog
## 1.2.1
* Fix Fatal error: Attempted to read an unowned reference but the object was already deallocated

## 1.3.0

* Animate marker position changes instead of removing and re-adding
* Fix Fatal error: Attempted to read an unowned reference but the object was already deallocated
* Fixed an issue where onCameraMove was not invoked by double-tapping
* Added insetsLayoutMarginsFromSafeArea

## 1.2.0

* Added a `markerAnnotationWithHue()` and `pinAnnotationWithHue()` method to allow custom marker/pin colors
Expand Down
2 changes: 2 additions & 0 deletions example/lib/scrolling_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ScrollingMapBody extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SafeArea(
bottom: false,
child: ListView(
children: <Widget>[
Card(
Expand Down Expand Up @@ -99,6 +100,7 @@ class ScrollingMapBody extends StatelessWidget {
() => ScaleGestureRecognizer(),
),
].toSet(),
insetsLayoutMarginsFromSafeArea: false,
),
),
),
Expand Down
8 changes: 7 additions & 1 deletion ios/Classes/MapView/AppleMapController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Foundation
import MapKit

public class AppleMapController: NSObject, FlutterPlatformView {
var contentView: UIView
var mapView: FlutterMapView
var registrar: FlutterPluginRegistrar
var channel: FlutterMethodChannel
Expand All @@ -25,6 +26,11 @@ public class AppleMapController: NSObject, FlutterPlatformView {
self.mapView = FlutterMapView(channel: channel, options: options)
self.registrar = registrar

// To stop the odd movement of the Apple logo.
self.contentView = UIScrollView()
self.contentView.addSubview(mapView)
mapView.autoresizingMask = [.flexibleHeight, .flexibleWidth]

self.initialCameraPosition = args["initialCameraPosition"]! as! Dictionary<String, Any>

super.init()
Expand All @@ -49,7 +55,7 @@ public class AppleMapController: NSObject, FlutterPlatformView {
}

public func view() -> UIView {
return mapView
return contentView
}

private func setMethodCallHandlers() {
Expand Down
7 changes: 7 additions & 0 deletions ios/Classes/MapView/FlutterMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ class FlutterMapView: MKMapView, UIGestureRecognizerDelegate {
self.maxZoomLevel = _maxZoom
}
}

if let insetsSafeArea: Bool = options["insetsLayoutMarginsFromSafeArea"] as? Bool {
if #available(iOS 11.0, *) {
self.insetsLayoutMarginsFromSafeArea = insetsSafeArea
}
}

}

func setUserLocation() {
Expand Down
11 changes: 11 additions & 0 deletions lib/src/apple_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class AppleMap extends StatefulWidget {
this.onTap,
this.onLongPress,
this.snapshotOptions,
this.insetsLayoutMarginsFromSafeArea = true,
}) : super(key: key);

final MapCreatedCallback? onMapCreated;
Expand Down Expand Up @@ -165,6 +166,10 @@ class AppleMap extends StatefulWidget {

final SnapshotOptions? snapshotOptions;

/// A Boolean value indicating whether the view's layout margins are updated
/// automatically to reflect the safe area.
final bool insetsLayoutMarginsFromSafeArea;

@override
State createState() => _AppleMapState();
}
Expand Down Expand Up @@ -336,6 +341,7 @@ class _AppleMapOptions {
this.myLocationEnabled,
this.myLocationButtonEnabled,
this.padding,
this.insetsLayoutMarginsFromSafeArea,
});

static _AppleMapOptions fromWidget(AppleMap map) {
Expand All @@ -352,6 +358,7 @@ class _AppleMapOptions {
myLocationEnabled: map.myLocationEnabled,
myLocationButtonEnabled: map.myLocationButtonEnabled,
padding: map.padding,
insetsLayoutMarginsFromSafeArea: map.insetsLayoutMarginsFromSafeArea,
);
}

Expand Down Expand Up @@ -379,6 +386,8 @@ class _AppleMapOptions {

final EdgeInsets? padding;

final bool? insetsLayoutMarginsFromSafeArea;

Map<String, dynamic> toMap() {
final Map<String, dynamic> optionsMap = <String, dynamic>{};

Expand All @@ -400,6 +409,8 @@ class _AppleMapOptions {
addIfNonNull('myLocationEnabled', myLocationEnabled);
addIfNonNull('myLocationButtonEnabled', myLocationButtonEnabled);
addIfNonNull('padding', _serializePadding(padding));
addIfNonNull(
'insetsLayoutMarginsFromSafeArea', insetsLayoutMarginsFromSafeArea);
return optionsMap;
}

Expand Down

0 comments on commit 34f8624

Please sign in to comment.