Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.8.2

* Converts inspector interface platform calls to Pigeon.

## 2.8.1

* Improves Objective-C type handling.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
NS_ASSUME_NONNULL_BEGIN

@interface FLTGoogleMapTileOverlayController : NSObject
/// The layer managed by this controller instance.
@property(readonly, nonatomic) GMSTileLayer *layer;

- (instancetype)initWithTileLayer:(GMSTileLayer *)tileLayer
mapView:(GMSMapView *)mapView
options:(NSDictionary *)optionsData;
- (void)removeTileOverlay;
- (void)clearTileCache;
- (NSDictionary *)getTileOverlayInfo;
@end

@interface FLTTileProviderController : GMSTileLayer
Expand All @@ -30,7 +32,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)changeTileOverlays:(NSArray *)tileOverlaysToChange;
- (void)removeTileOverlayWithIdentifiers:(NSArray *)identifiers;
- (void)clearTileCacheWithIdentifier:(NSString *)identifier;
- (nullable NSDictionary *)tileOverlayInfoWithIdentifier:(NSString *)identifier;
- (nullable FLTGoogleMapTileOverlayController *)tileOverlayWithIdentifier:(NSString *)identifier;
@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,6 @@ - (void)clearTileCache {
[self.layer clearTileCache];
}

- (NSDictionary *)getTileOverlayInfo {
NSMutableDictionary *info = [[NSMutableDictionary alloc] init];
BOOL visible = self.layer.map != nil;
info[@"visible"] = @(visible);
info[@"fadeIn"] = @(self.layer.fadeIn);
float transparency = 1.0 - self.layer.opacity;
info[@"transparency"] = @(transparency);
info[@"zIndex"] = @(self.layer.zIndex);
return info;
}

- (void)setFadeIn:(BOOL)fadeIn {
self.layer.fadeIn = fadeIn;
}
Expand Down Expand Up @@ -182,7 +171,8 @@ - (void)requestTileForX:(NSUInteger)x

@interface FLTTileOverlaysController ()

@property(strong, nonatomic) NSMutableDictionary *tileOverlayIdentifierToController;
@property(strong, nonatomic) NSMutableDictionary<NSString *, FLTGoogleMapTileOverlayController *>
*tileOverlayIdentifierToController;
@property(strong, nonatomic) FlutterMethodChannel *methodChannel;
@property(weak, nonatomic) GMSMapView *mapView;

Expand Down Expand Up @@ -248,11 +238,8 @@ - (void)clearTileCacheWithIdentifier:(NSString *)identifier {
[controller clearTileCache];
}

- (nullable NSDictionary *)tileOverlayInfoWithIdentifier:(NSString *)identifier {
if (self.tileOverlayIdentifierToController[identifier] == nil) {
return nil;
}
return [self.tileOverlayIdentifierToController[identifier] getTileOverlayInfo];
- (nullable FLTGoogleMapTileOverlayController *)tileOverlayWithIdentifier:(NSString *)identifier {
return self.tileOverlayIdentifierToController[identifier];
}

+ (NSString *)identifierForTileOverlay:(NSDictionary *)tileOverlay {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#import "GoogleMapMarkerController.h"
#import "GoogleMapPolygonController.h"
#import "GoogleMapPolylineController.h"
#import "messages.g.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#import "GoogleMapController.h"
#import "FLTGoogleMapJSONConversions.h"
#import "FLTGoogleMapTileOverlayController.h"
#import "messages.g.h"

#pragma mark - Conversion of JSON-like values sent via platform channels. Forward declarations.

Expand Down Expand Up @@ -56,6 +57,33 @@ - (instancetype)initWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar

@end

#pragma mark -

/// Implementation of the Pigeon maps inspector API.
///
/// This is a separate object from the maps controller because the Pigeon API registration keeps a
/// strong reference to the implementor, but as the FlutterPlatformView, the lifetime of the
/// FLTGoogleMapController instance is what needs to trigger Pigeon unregistration, so can't be
/// the target of the registration.
@interface FGMMapInspector : NSObject <FGMMapsInspectorApi>
- (instancetype)initWithMapController:(nonnull FLTGoogleMapController *)controller
messenger:(NSObject<FlutterBinaryMessenger> *)messenger
pigeonSuffix:(NSString *)suffix;
@end

/// Private declarations.
// This is separate in case the above is made public in the future (e.g., for unit testing).
@interface FGMMapInspector ()
/// The map controller this inspector corresponds to.
@property(nonatomic, weak) FLTGoogleMapController *controller;
/// The messenger this instance was registered with by Pigeon.
@property(nonatomic, copy) NSObject<FlutterBinaryMessenger> *messenger;
/// The suffix this instance was registered under with Pigeon.
@property(nonatomic, copy) NSString *pigeonSuffix;
@end

#pragma mark -

@interface FLTGoogleMapController ()

@property(nonatomic, strong) GMSMapView *mapView;
Expand All @@ -72,6 +100,8 @@ @interface FLTGoogleMapController ()
// creation time and there's no mechanism to return non-fatal error details during platform view
// initialization.
@property(nonatomic, copy) NSString *styleError;
// The inspector API implementation, separate to avoid lifetime extension.
@property(nonatomic, strong) FGMMapInspector *inspector;

@end

Expand Down Expand Up @@ -114,9 +144,7 @@ - (instancetype)initWithMapView:(GMSMapView *_Nonnull)mapView
binaryMessenger:registrar.messenger];
__weak __typeof__(self) weakSelf = self;
[_channel setMethodCallHandler:^(FlutterMethodCall *call, FlutterResult result) {
if (weakSelf) {
[weakSelf onMethodCall:call result:result];
}
[weakSelf onMethodCall:call result:result];
}];
_mapView.delegate = weakSelf;
_mapView.paddingAdjustmentBehavior = kGMSMapViewPaddingAdjustmentBehaviorNever;
Expand Down Expand Up @@ -158,10 +186,22 @@ - (instancetype)initWithMapView:(GMSMapView *_Nonnull)mapView
}

[_mapView addObserver:self forKeyPath:@"frame" options:0 context:nil];

NSString *suffix = [NSString stringWithFormat:@"%lld", viewId];
_inspector = [[FGMMapInspector alloc] initWithMapController:self
messenger:registrar.messenger
pigeonSuffix:suffix];
SetUpFGMMapsInspectorApiWithSuffix(registrar.messenger, _inspector, suffix);
}
return self;
}

- (void)dealloc {
// Unregister the API implementations so that they can be released; the registration created an
// owning reference.
SetUpFGMMapsInspectorApiWithSuffix(_inspector.messenger, nil, _inspector.pigeonSuffix);
}

- (UIView *)view {
return self.mapView;
}
Expand Down Expand Up @@ -356,41 +396,8 @@ - (void)onMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
id rawTileOverlayId = call.arguments[@"tileOverlayId"];
[self.tileOverlaysController clearTileCacheWithIdentifier:rawTileOverlayId];
result(nil);
} else if ([call.method isEqualToString:@"map#isCompassEnabled"]) {
NSNumber *isCompassEnabled = @(self.mapView.settings.compassButton);
result(isCompassEnabled);
} else if ([call.method isEqualToString:@"map#isMapToolbarEnabled"]) {
NSNumber *isMapToolbarEnabled = @NO;
result(isMapToolbarEnabled);
} else if ([call.method isEqualToString:@"map#getMinMaxZoomLevels"]) {
NSArray *zoomLevels = @[ @(self.mapView.minZoom), @(self.mapView.maxZoom) ];
result(zoomLevels);
} else if ([call.method isEqualToString:@"map#getZoomLevel"]) {
result(@(self.mapView.camera.zoom));
} else if ([call.method isEqualToString:@"map#isZoomGesturesEnabled"]) {
NSNumber *isZoomGesturesEnabled = @(self.mapView.settings.zoomGestures);
result(isZoomGesturesEnabled);
} else if ([call.method isEqualToString:@"map#isZoomControlsEnabled"]) {
NSNumber *isZoomControlsEnabled = @NO;
result(isZoomControlsEnabled);
} else if ([call.method isEqualToString:@"map#isTiltGesturesEnabled"]) {
NSNumber *isTiltGesturesEnabled = @(self.mapView.settings.tiltGestures);
result(isTiltGesturesEnabled);
} else if ([call.method isEqualToString:@"map#isRotateGesturesEnabled"]) {
NSNumber *isRotateGesturesEnabled = @(self.mapView.settings.rotateGestures);
result(isRotateGesturesEnabled);
} else if ([call.method isEqualToString:@"map#isScrollGesturesEnabled"]) {
NSNumber *isScrollGesturesEnabled = @(self.mapView.settings.scrollGestures);
result(isScrollGesturesEnabled);
} else if ([call.method isEqualToString:@"map#isMyLocationButtonEnabled"]) {
NSNumber *isMyLocationButtonEnabled = @(self.mapView.settings.myLocationButton);
result(isMyLocationButtonEnabled);
} else if ([call.method isEqualToString:@"map#isTrafficEnabled"]) {
NSNumber *isTrafficEnabled = @(self.mapView.trafficEnabled);
result(isTrafficEnabled);
} else if ([call.method isEqualToString:@"map#isBuildingsEnabled"]) {
NSNumber *isBuildingsEnabled = @(self.mapView.buildingsEnabled);
result(isBuildingsEnabled);
} else if ([call.method isEqualToString:@"map#setStyle"]) {
id mapStyle = [call arguments];
self.styleError = [self setMapStyle:(mapStyle == [NSNull null] ? nil : mapStyle)];
Expand All @@ -401,9 +408,6 @@ - (void)onMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
}
} else if ([call.method isEqualToString:@"map#getStyleError"]) {
result(self.styleError);
} else if ([call.method isEqualToString:@"map#getTileOverlayInfo"]) {
NSString *rawTileOverlayId = call.arguments[@"tileOverlayId"];
result([self.tileOverlaysController tileOverlayInfoWithIdentifier:rawTileOverlayId]);
} else {
result(FlutterMethodNotImplemented);
}
Expand Down Expand Up @@ -659,3 +663,81 @@ - (void)interpretMapOptions:(NSDictionary *)data {
}

@end

#pragma mark -

@implementation FGMMapInspector

- (instancetype)initWithMapController:(nonnull FLTGoogleMapController *)controller
messenger:(NSObject<FlutterBinaryMessenger> *)messenger
pigeonSuffix:(NSString *)suffix {
self = [super init];
if (self) {
_controller = controller;
_messenger = messenger;
_pigeonSuffix = suffix;
}
return self;
}

- (nullable NSNumber *)areBuildingsEnabledWithError:
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
return @(self.controller.mapView.buildingsEnabled);
}

- (nullable NSNumber *)areRotateGesturesEnabledWithError:
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
return @(self.controller.mapView.settings.rotateGestures);
}

- (nullable NSNumber *)areScrollGesturesEnabledWithError:
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
return @(self.controller.mapView.settings.scrollGestures);
}

- (nullable NSNumber *)areTiltGesturesEnabledWithError:
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
return @(self.controller.mapView.settings.tiltGestures);
}

- (nullable NSNumber *)areZoomGesturesEnabledWithError:
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
return @(self.controller.mapView.settings.zoomGestures);
}

- (nullable FGMPlatformTileLayer *)
getInfoForTileOverlayWithIdentifier:(nonnull NSString *)tileOverlayId
error:(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
GMSTileLayer *layer =
[self.controller.tileOverlaysController tileOverlayWithIdentifier:tileOverlayId].layer;
if (!layer) {
return nil;
}
return [FGMPlatformTileLayer makeWithVisible:(layer.map != nil)
fadeIn:layer.fadeIn
opacity:layer.opacity
zIndex:layer.zIndex];
}

- (nullable NSNumber *)isCompassEnabledWithError:
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
return @(self.controller.mapView.settings.compassButton);
}

- (nullable NSNumber *)isMyLocationButtonEnabledWithError:
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
return @(self.controller.mapView.settings.myLocationButton);
}

- (nullable NSNumber *)isTrafficEnabledWithError:
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
return @(self.controller.mapView.trafficEnabled);
}

- (nullable FGMPlatformZoomRange *)zoomRange:
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
return [FGMPlatformZoomRange makeWithMin:self.controller.mapView.minZoom
max:self.controller.mapView.maxZoom];
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v20.0.1), do not edit directly.
// See also: https://pub.dev/packages/pigeon

#import <Foundation/Foundation.h>

@protocol FlutterBinaryMessenger;
@protocol FlutterMessageCodec;
@class FlutterError;
@class FlutterStandardTypedData;

NS_ASSUME_NONNULL_BEGIN

@class FGMPlatformTileLayer;
@class FGMPlatformZoomRange;

/// Pigeon equivalent of GMSTileLayer properties.
@interface FGMPlatformTileLayer : NSObject
/// `init` unavailable to enforce nonnull fields, see the `make` class method.
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)makeWithVisible:(BOOL)visible
fadeIn:(BOOL)fadeIn
opacity:(double)opacity
zIndex:(NSInteger)zIndex;
@property(nonatomic, assign) BOOL visible;
@property(nonatomic, assign) BOOL fadeIn;
@property(nonatomic, assign) double opacity;
@property(nonatomic, assign) NSInteger zIndex;
@end

/// Possible outcomes of launching a URL.
@interface FGMPlatformZoomRange : NSObject
/// `init` unavailable to enforce nonnull fields, see the `make` class method.
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)makeWithMin:(double)min max:(double)max;
@property(nonatomic, assign) double min;
@property(nonatomic, assign) double max;
@end

/// The codec used by all APIs.
NSObject<FlutterMessageCodec> *FGMGetMessagesCodec(void);

/// Inspector API only intended for use in integration tests.
@protocol FGMMapsInspectorApi
/// @return `nil` only when `error != nil`.
- (nullable NSNumber *)areBuildingsEnabledWithError:(FlutterError *_Nullable *_Nonnull)error;
/// @return `nil` only when `error != nil`.
- (nullable NSNumber *)areRotateGesturesEnabledWithError:(FlutterError *_Nullable *_Nonnull)error;
/// @return `nil` only when `error != nil`.
- (nullable NSNumber *)areScrollGesturesEnabledWithError:(FlutterError *_Nullable *_Nonnull)error;
/// @return `nil` only when `error != nil`.
- (nullable NSNumber *)areTiltGesturesEnabledWithError:(FlutterError *_Nullable *_Nonnull)error;
/// @return `nil` only when `error != nil`.
- (nullable NSNumber *)areZoomGesturesEnabledWithError:(FlutterError *_Nullable *_Nonnull)error;
/// @return `nil` only when `error != nil`.
- (nullable NSNumber *)isCompassEnabledWithError:(FlutterError *_Nullable *_Nonnull)error;
/// @return `nil` only when `error != nil`.
- (nullable NSNumber *)isMyLocationButtonEnabledWithError:(FlutterError *_Nullable *_Nonnull)error;
/// @return `nil` only when `error != nil`.
- (nullable NSNumber *)isTrafficEnabledWithError:(FlutterError *_Nullable *_Nonnull)error;
- (nullable FGMPlatformTileLayer *)
getInfoForTileOverlayWithIdentifier:(NSString *)tileOverlayId
error:(FlutterError *_Nullable *_Nonnull)error;
/// @return `nil` only when `error != nil`.
- (nullable FGMPlatformZoomRange *)zoomRange:(FlutterError *_Nullable *_Nonnull)error;
@end

extern void SetUpFGMMapsInspectorApi(id<FlutterBinaryMessenger> binaryMessenger,
NSObject<FGMMapsInspectorApi> *_Nullable api);

extern void SetUpFGMMapsInspectorApiWithSuffix(id<FlutterBinaryMessenger> binaryMessenger,
NSObject<FGMMapsInspectorApi> *_Nullable api,
NSString *messageChannelSuffix);

NS_ASSUME_NONNULL_END
Loading