diff options
author | Kangho Hur <kangho.hur@samsung.com> | 2017-03-24 14:29:22 +0900 |
---|---|---|
committer | Kangho Hur <kangho.hur@samsung.com> | 2017-03-24 14:47:36 +0900 |
commit | 161a8e0f544b44f848d4c68ac9637d3a8b3f2520 (patch) | |
tree | 9a61043f0e27ef4f9855fcc1fc70693b12f10f4f /Xamarin.Forms.Maps.iOS | |
parent | 20daaa5702a27d1a9c7cf9dfacfdfa254ac0e5e3 (diff) | |
download | xamarin-forms-161a8e0f544b44f848d4c68ac9637d3a8b3f2520.tar.gz xamarin-forms-161a8e0f544b44f848d4c68ac9637d3a8b3f2520.tar.bz2 xamarin-forms-161a8e0f544b44f848d4c68ac9637d3a8b3f2520.zip |
Clean sync with 2.3.4-2
Change-Id: I6a7423d2690a1c30f46e0c128d9504a2464f8f0b
Diffstat (limited to 'Xamarin.Forms.Maps.iOS')
-rw-r--r-- | Xamarin.Forms.Maps.iOS/FormsMaps.cs | 18 | ||||
-rw-r--r-- | Xamarin.Forms.Maps.iOS/GeocoderBackend.cs | 35 | ||||
-rw-r--r-- | Xamarin.Forms.Maps.iOS/MapPool.cs | 4 | ||||
-rw-r--r-- | Xamarin.Forms.Maps.iOS/MapRenderer.cs | 88 |
4 files changed, 26 insertions, 119 deletions
diff --git a/Xamarin.Forms.Maps.iOS/FormsMaps.cs b/Xamarin.Forms.Maps.iOS/FormsMaps.cs index 0f5df423..19c0701e 100644 --- a/Xamarin.Forms.Maps.iOS/FormsMaps.cs +++ b/Xamarin.Forms.Maps.iOS/FormsMaps.cs @@ -1,18 +1,12 @@ -#if __MOBILE__ using UIKit; using Xamarin.Forms.Maps.iOS; -#else -using Xamarin.Forms.Maps.MacOS; -#endif namespace Xamarin { public static class FormsMaps { static bool s_isInitialized; -#if __MOBILE__ static bool? s_isiOs8OrNewer; - static bool? s_isiOs9OrNewer; static bool? s_isiOs10OrNewer; internal static bool IsiOs8OrNewer @@ -25,16 +19,6 @@ namespace Xamarin } } - internal static bool IsiOs9OrNewer - { - get - { - if (!s_isiOs9OrNewer.HasValue) - s_isiOs9OrNewer = UIDevice.CurrentDevice.CheckSystemVersion(9, 0); - return s_isiOs9OrNewer.Value; - } - } - internal static bool IsiOs10OrNewer { get @@ -44,7 +28,7 @@ namespace Xamarin return s_isiOs10OrNewer.Value; } } -#endif + public static void Init() { if (s_isInitialized) diff --git a/Xamarin.Forms.Maps.iOS/GeocoderBackend.cs b/Xamarin.Forms.Maps.iOS/GeocoderBackend.cs index e5d1b25c..08ffbbec 100644 --- a/Xamarin.Forms.Maps.iOS/GeocoderBackend.cs +++ b/Xamarin.Forms.Maps.iOS/GeocoderBackend.cs @@ -1,22 +1,10 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Contacts; -using CoreLocation; - -#if __MOBILE__ using AddressBookUI; -using CCLGeocoder = CoreLocation.CLGeocoder; -#else -using Xamarin.Forms.Maps.MacOS.Extra; -using CCLGeocoder = Xamarin.Forms.Maps.MacOS.Extra.CLGeocoder; -#endif +using CoreLocation; -#if __MOBILE__ namespace Xamarin.Forms.Maps.iOS -#else -namespace Xamarin.Forms.Maps.MacOS -#endif { internal class GeocoderBackend { @@ -29,36 +17,21 @@ namespace Xamarin.Forms.Maps.MacOS static Task<IEnumerable<string>> GetAddressesForPositionAsync(Position position) { var location = new CLLocation(position.Latitude, position.Longitude); - var geocoder = new CCLGeocoder(); + var geocoder = new CLGeocoder(); var source = new TaskCompletionSource<IEnumerable<string>>(); geocoder.ReverseGeocodeLocation(location, (placemarks, error) => { if (placemarks == null) placemarks = new CLPlacemark[0]; - List<string> addresses = new List<string>(); -#if __MOBILE__ - addresses = placemarks.Select(p => ABAddressFormatting.ToString(p.AddressDictionary, false)).ToList(); -#else - foreach (var item in placemarks) - { - var address = new CNMutablePostalAddress(); - address.Street = item.AddressDictionary["Street"] == null ? "" : item.AddressDictionary["Street"].ToString(); - address.State = item.AddressDictionary["State"] == null ? "" : item.AddressDictionary["State"].ToString(); - address.City = item.AddressDictionary["City"] == null ? "" : item.AddressDictionary["City"].ToString(); - address.Country = item.AddressDictionary["Country"] == null ? "" : item.AddressDictionary["Country"].ToString(); - address.PostalCode = item.AddressDictionary["ZIP"] == null ? "" : item.AddressDictionary["ZIP"].ToString(); - addresses.Add(CNPostalAddressFormatter.GetStringFrom(address, CNPostalAddressFormatterStyle.MailingAddress)); - } -#endif + IEnumerable<string> addresses = placemarks.Select(p => ABAddressFormatting.ToString(p.AddressDictionary, false)); source.SetResult(addresses); - }); return source.Task; } static Task<IEnumerable<Position>> GetPositionsForAddressAsync(string address) { - var geocoder = new CCLGeocoder(); + var geocoder = new CLGeocoder(); var source = new TaskCompletionSource<IEnumerable<Position>>(); geocoder.GeocodeAddress(address, (placemarks, error) => { diff --git a/Xamarin.Forms.Maps.iOS/MapPool.cs b/Xamarin.Forms.Maps.iOS/MapPool.cs index 1b3823c7..dc8a9c47 100644 --- a/Xamarin.Forms.Maps.iOS/MapPool.cs +++ b/Xamarin.Forms.Maps.iOS/MapPool.cs @@ -1,11 +1,7 @@ using System.Collections.Concurrent; using MapKit; -#if __MOBILE__ namespace Xamarin.Forms.Maps.iOS -#else -namespace Xamarin.Forms.Maps.MacOS -#endif { // A static pool of MKMapView instances we can reuse internal class MapPool diff --git a/Xamarin.Forms.Maps.iOS/MapRenderer.cs b/Xamarin.Forms.Maps.iOS/MapRenderer.cs index 44d95aa6..cc9f2533 100644 --- a/Xamarin.Forms.Maps.iOS/MapRenderer.cs +++ b/Xamarin.Forms.Maps.iOS/MapRenderer.cs @@ -5,27 +5,21 @@ using System.Collections.ObjectModel; using System.Collections.Specialized; using System.ComponentModel; using CoreLocation; +using Foundation; using MapKit; using ObjCRuntime; -using RectangleF = CoreGraphics.CGRect; -using Foundation; - -#if __MOBILE__ using UIKit; using Xamarin.Forms.Platform.iOS; +using RectangleF = CoreGraphics.CGRect; + namespace Xamarin.Forms.Maps.iOS -#else -using AppKit; -using Xamarin.Forms.Platform.MacOS; -namespace Xamarin.Forms.Maps.MacOS -#endif { internal class MapDelegate : MKMapViewDelegate { // keep references alive, removing this will cause a segfault readonly List<object> List = new List<object>(); Map _map; - object _lastTouchedView; + UIView _lastTouchedView; bool _disposed; internal MapDelegate(Map map) @@ -55,10 +49,9 @@ namespace Xamarin.Forms.Maps.MacOS return mapPin; } -#if __MOBILE__ + void AttachGestureToPin(MKPinAnnotationView mapPin, IMKAnnotation annotation) { - UIGestureRecognizer[] recognizers = mapPin.GestureRecognizers; if (recognizers != null) @@ -78,33 +71,9 @@ namespace Xamarin.Forms.Maps.MacOS List.Add(action); List.Add(recognizer); mapPin.AddGestureRecognizer(recognizer); - } -#else - void AttachGestureToPin(MKPinAnnotationView mapPin, IMKAnnotation annotation) - { - NSGestureRecognizer[] recognizers = mapPin.GestureRecognizers; - - if (recognizers != null) - { - foreach (NSGestureRecognizer r in recognizers) - { - mapPin.RemoveGestureRecognizer(r); - } - } - - Action<NSClickGestureRecognizer> action = g => OnClick(annotation, g); - var recognizer = new NSClickGestureRecognizer(action); - List.Add(action); - List.Add(recognizer); - mapPin.AddGestureRecognizer(recognizer); - } -#endif -#if __MOBILE__ + void OnClick(object annotationObject, UITapGestureRecognizer recognizer) -#else - void OnClick(object annotationObject, NSClickGestureRecognizer recognizer) -#endif { // https://bugzilla.xamarin.com/show_bug.cgi?id=26416 NSObject annotation = Runtime.GetNSObject(((IMKAnnotation)annotationObject).Handle); @@ -157,9 +126,9 @@ namespace Xamarin.Forms.Maps.MacOS public class MapRenderer : ViewRenderer { - CLLocationManager _locationManager; + CLLocationManager _locationManager; bool _shouldUpdateRegion; - bool _disposed; + bool _disposed; const string MoveMessageName = "MapMoveToRegion"; @@ -168,15 +137,14 @@ namespace Xamarin.Forms.Maps.MacOS return Control.GetSizeRequest(widthConstraint, heightConstraint); } - // iOS 9/10 have some issues with releasing memory from map views; each one we create allocates + // iOS 10 has some issues with releasing memory from map views; each one we create allocates // a bunch of memory we can never get back. Until that's fixed, we'll just reuse MKMapViews // as much as possible to prevent creating new ones and losing more memory // For the time being, we don't want ViewRenderer handling disposal of the MKMapView - // if we're on iOS 9 or 10; during Dispose we'll be putting the MKMapView in a pool instead -#if __MOBILE__ - protected override bool ManageNativeControlLifetime => !FormsMaps.IsiOs9OrNewer; -#endif + // if we're on iOS 10; during Dispose we'll be putting the MKMapView in a pool instead + protected override bool ManageNativeControlLifetime => !FormsMaps.IsiOs10OrNewer; + protected override void Dispose(bool disposing) { if (_disposed) @@ -201,15 +169,15 @@ namespace Xamarin.Forms.Maps.MacOS mkMapView.Delegate.Dispose(); mkMapView.Delegate = null; mkMapView.RemoveFromSuperview(); -#if __MOBILE__ - if (FormsMaps.IsiOs9OrNewer) + + if (FormsMaps.IsiOs10OrNewer) { // This renderer is done with the MKMapView; we can put it in the pool // for other rendererers to use in the future MapPool.Add(mkMapView); } -#endif - // For iOS versions < 9, the MKMapView will be disposed in ViewRenderer's Dispose method + + // For iOS versions < 10, the MKMapView will be disposed in ViewRenderer's Dispose method if (_locationManager != null) { @@ -239,16 +207,16 @@ namespace Xamarin.Forms.Maps.MacOS if (Control == null) { MKMapView mapView = null; -#if __MOBILE__ - if (FormsMaps.IsiOs9OrNewer) + + if (FormsMaps.IsiOs10OrNewer) { // See if we've got an MKMapView available in the pool; if so, use it mapView = MapPool.Get(); } -#endif + if (mapView == null) { - // If this is iOS 8 or lower, or if there weren't any MKMapViews in the pool, + // If this is iOS 9 or lower, or if there weren't any MKMapViews in the pool, // create a new one mapView = new MKMapView(RectangleF.Empty); } @@ -292,22 +260,9 @@ namespace Xamarin.Forms.Maps.MacOS _shouldUpdateRegion = true; } -#if __MOBILE__ public override void LayoutSubviews() { base.LayoutSubviews(); - UpdateRegion(); - } -#else - public override void Layout() - { - base.Layout(); - UpdateRegion(); - } -#endif - - void UpdateRegion() - { if (_shouldUpdateRegion) { MoveToRegion(((Map)Element).LastMoveToRegion, false); @@ -388,13 +343,12 @@ namespace Xamarin.Forms.Maps.MacOS void UpdateIsShowingUser() { -#if __MOBILE__ if (FormsMaps.IsiOs8OrNewer && ((Map)Element).IsShowingUser) { _locationManager = new CLLocationManager(); _locationManager.RequestWhenInUseAuthorization(); } -#endif + ((MKMapView)Control).ShowsUserLocation = ((Map)Element).IsShowingUser; } |