-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[google_maps_flutter] Fix iOS info window regression #8939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
auto-submit
merged 1 commit into
flutter:main
from
stuartmorgan-g:maps-ios-info-window-pigeon-regression
Apr 3, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
packages/google_maps_flutter/google_maps_flutter_ios/CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
225 changes: 225 additions & 0 deletions
225
...r/google_maps_flutter_ios/example/ios14/ios/RunnerTests/GoogleMapsMarkerControllerTests.m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,225 @@ | ||
// 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. | ||
|
||
@import google_maps_flutter_ios; | ||
@import google_maps_flutter_ios.Test; | ||
@import XCTest; | ||
@import GoogleMaps; | ||
|
||
#import <OCMock/OCMock.h> | ||
#import <google_maps_flutter_ios/messages.g.h> | ||
#import "PartiallyMockedMapView.h" | ||
|
||
@interface GoogleMapsMarkerControllerTests : XCTestCase | ||
@end | ||
|
||
@implementation GoogleMapsMarkerControllerTests | ||
|
||
/// Returns a mocked map view for use with marker controllers. | ||
- (GMSMapView *)mockedMapView { | ||
GMSMapViewOptions *mapViewOptions = [[GMSMapViewOptions alloc] init]; | ||
mapViewOptions.frame = CGRectMake(0, 0, 100, 100); | ||
mapViewOptions.camera = [[GMSCameraPosition alloc] initWithLatitude:0 longitude:0 zoom:0]; | ||
return [[PartiallyMockedMapView alloc] initWithOptions:mapViewOptions]; | ||
} | ||
|
||
/// Returns a FLTMarkersController instance instantiated with the given map view. | ||
/// | ||
/// The mapView should outlive the controller, as the controller keeps a weak reference to it. | ||
- (FLTMarkersController *)markersControllerWithMapView:(GMSMapView *)mapView { | ||
NSObject<FlutterPluginRegistrar> *mockRegistrar = | ||
OCMStrictProtocolMock(@protocol(FlutterPluginRegistrar)); | ||
return [[FLTMarkersController alloc] initWithMapView:mapView | ||
callbackHandler:[[FGMMapsCallbackApi alloc] init] | ||
clusterManagersController:nil | ||
registrar:mockRegistrar]; | ||
} | ||
|
||
- (FGMPlatformBitmap *)placeholderBitmap { | ||
return [FGMPlatformBitmap makeWithBitmap:[FGMPlatformBitmapDefaultMarker makeWithHue:@0]]; | ||
} | ||
|
||
- (void)testSetsMarkerNumericProperties { | ||
GMSMapView *mapView = [self mockedMapView]; | ||
FLTMarkersController *controller = [self markersControllerWithMapView:mapView]; | ||
|
||
NSString *markerIdentifier = @"marker"; | ||
double anchorX = 3.14; | ||
double anchorY = 2.718; | ||
double alpha = 0.4; | ||
double rotation = 90.0; | ||
double zIndex = 3.0; | ||
double latitutde = 10.0; | ||
double longitude = 20.0; | ||
[controller addMarkers:@[ [FGMPlatformMarker | ||
makeWithAlpha:alpha | ||
anchor:[FGMPlatformPoint makeWithX:anchorX y:anchorY] | ||
consumeTapEvents:YES | ||
draggable:YES | ||
flat:YES | ||
icon:[self placeholderBitmap] | ||
infoWindow:[FGMPlatformInfoWindow | ||
makeWithTitle:@"info title" | ||
snippet:@"info snippet" | ||
anchor:[FGMPlatformPoint makeWithX:0 y:0]] | ||
position:[FGMPlatformLatLng makeWithLatitude:latitutde | ||
longitude:longitude] | ||
rotation:rotation | ||
visible:YES | ||
zIndex:zIndex | ||
markerId:markerIdentifier | ||
clusterManagerId:nil] ]]; | ||
|
||
FLTGoogleMapMarkerController *markerController = | ||
controller.markerIdentifierToController[markerIdentifier]; | ||
GMSMarker *marker = markerController.marker; | ||
|
||
const double delta = 0.0001; | ||
XCTAssertEqualWithAccuracy(marker.opacity, alpha, delta); | ||
XCTAssertEqualWithAccuracy(marker.rotation, rotation, delta); | ||
XCTAssertEqualWithAccuracy(marker.zIndex, zIndex, delta); | ||
XCTAssertEqualWithAccuracy(marker.groundAnchor.x, anchorX, delta); | ||
XCTAssertEqualWithAccuracy(marker.groundAnchor.y, anchorY, delta); | ||
XCTAssertEqualWithAccuracy(marker.position.latitude, latitutde, delta); | ||
XCTAssertEqualWithAccuracy(marker.position.longitude, longitude, delta); | ||
} | ||
|
||
// Boolean properties are tested individually to ensure they aren't accidentally cross-assigned from | ||
// another property. | ||
- (void)testSetsDraggable { | ||
GMSMapView *mapView = [self mockedMapView]; | ||
FLTMarkersController *controller = [self markersControllerWithMapView:mapView]; | ||
|
||
NSString *markerIdentifier = @"marker"; | ||
[controller addMarkers:@[ [FGMPlatformMarker | ||
makeWithAlpha:1.0 | ||
anchor:[FGMPlatformPoint makeWithX:0 y:0] | ||
consumeTapEvents:NO | ||
draggable:YES | ||
flat:NO | ||
icon:[self placeholderBitmap] | ||
infoWindow:[FGMPlatformInfoWindow | ||
makeWithTitle:@"info title" | ||
snippet:@"info snippet" | ||
anchor:[FGMPlatformPoint makeWithX:0 y:0]] | ||
position:[FGMPlatformLatLng makeWithLatitude:0.0 longitude:0.0] | ||
rotation:0 | ||
visible:NO | ||
zIndex:0 | ||
markerId:markerIdentifier | ||
clusterManagerId:nil] ]]; | ||
|
||
FLTGoogleMapMarkerController *markerController = | ||
controller.markerIdentifierToController[markerIdentifier]; | ||
GMSMarker *marker = markerController.marker; | ||
|
||
XCTAssertTrue(marker.draggable); | ||
} | ||
|
||
// Boolean properties are tested individually to ensure they aren't accidentally cross-assigned from | ||
// another property. | ||
- (void)testSetsFlat { | ||
GMSMapView *mapView = [self mockedMapView]; | ||
FLTMarkersController *controller = [self markersControllerWithMapView:mapView]; | ||
|
||
NSString *markerIdentifier = @"marker"; | ||
[controller addMarkers:@[ [FGMPlatformMarker | ||
makeWithAlpha:1.0 | ||
anchor:[FGMPlatformPoint makeWithX:0 y:0] | ||
consumeTapEvents:NO | ||
draggable:NO | ||
flat:YES | ||
icon:[self placeholderBitmap] | ||
infoWindow:[FGMPlatformInfoWindow | ||
makeWithTitle:@"info title" | ||
snippet:@"info snippet" | ||
anchor:[FGMPlatformPoint makeWithX:0 y:0]] | ||
position:[FGMPlatformLatLng makeWithLatitude:0.0 longitude:0.0] | ||
rotation:0 | ||
visible:NO | ||
zIndex:0 | ||
markerId:markerIdentifier | ||
clusterManagerId:nil] ]]; | ||
|
||
FLTGoogleMapMarkerController *markerController = | ||
controller.markerIdentifierToController[markerIdentifier]; | ||
GMSMarker *marker = markerController.marker; | ||
|
||
XCTAssertTrue(marker.flat); | ||
} | ||
|
||
// Boolean properties are tested individually to ensure they aren't accidentally cross-assigned from | ||
// another property. | ||
- (void)testSetsVisible { | ||
GMSMapView *mapView = [self mockedMapView]; | ||
FLTMarkersController *controller = [self markersControllerWithMapView:mapView]; | ||
|
||
NSString *markerIdentifier = @"marker"; | ||
[controller addMarkers:@[ [FGMPlatformMarker | ||
makeWithAlpha:1.0 | ||
anchor:[FGMPlatformPoint makeWithX:0 y:0] | ||
consumeTapEvents:NO | ||
draggable:NO | ||
flat:NO | ||
icon:[self placeholderBitmap] | ||
infoWindow:[FGMPlatformInfoWindow | ||
makeWithTitle:@"info title" | ||
snippet:@"info snippet" | ||
anchor:[FGMPlatformPoint makeWithX:0 y:0]] | ||
position:[FGMPlatformLatLng makeWithLatitude:0.0 longitude:0.0] | ||
rotation:0 | ||
visible:YES | ||
zIndex:0 | ||
markerId:markerIdentifier | ||
clusterManagerId:nil] ]]; | ||
|
||
FLTGoogleMapMarkerController *markerController = | ||
controller.markerIdentifierToController[markerIdentifier]; | ||
GMSMarker *marker = markerController.marker; | ||
|
||
// Visibility is controlled by being set to a map. | ||
XCTAssertNotNil(marker.map); | ||
} | ||
|
||
- (void)testSetsMarkerInfoWindowProperties { | ||
GMSMapView *mapView = [self mockedMapView]; | ||
FLTMarkersController *controller = [self markersControllerWithMapView:mapView]; | ||
|
||
NSString *markerIdentifier = @"marker"; | ||
NSString *title = @"info title"; | ||
NSString *snippet = @"info snippet"; | ||
double anchorX = 3.14; | ||
double anchorY = 2.718; | ||
[controller | ||
addMarkers:@[ [FGMPlatformMarker | ||
makeWithAlpha:1.0 | ||
anchor:[FGMPlatformPoint makeWithX:0 y:0] | ||
consumeTapEvents:YES | ||
draggable:YES | ||
flat:YES | ||
icon:[self placeholderBitmap] | ||
infoWindow:[FGMPlatformInfoWindow | ||
makeWithTitle:title | ||
snippet:snippet | ||
anchor:[FGMPlatformPoint makeWithX:anchorX | ||
y:anchorY]] | ||
position:[FGMPlatformLatLng makeWithLatitude:0 longitude:0] | ||
rotation:0 | ||
visible:YES | ||
zIndex:0 | ||
markerId:markerIdentifier | ||
clusterManagerId:nil] ]]; | ||
|
||
FLTGoogleMapMarkerController *markerController = | ||
controller.markerIdentifierToController[markerIdentifier]; | ||
GMSMarker *marker = markerController.marker; | ||
|
||
const double delta = 0.0001; | ||
XCTAssertEqualWithAccuracy(marker.infoWindowAnchor.x, anchorX, delta); | ||
XCTAssertEqualWithAccuracy(marker.infoWindowAnchor.y, anchorY, delta); | ||
XCTAssertEqual(marker.title, title); | ||
XCTAssertEqual(marker.snippet, snippet); | ||
} | ||
|
||
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,26 +4,18 @@ | |
|
||
#import "GoogleMapMarkerController.h" | ||
|
||
/// Methods exposed for unit testing. | ||
@interface FLTGoogleMapMarkerController (Test) | ||
|
||
/// Extracts an icon image from the iconData array. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both of these were dead code; they were exposing helpers that no longer exist in this class, and are instead stand-alone functions in a util file that are tested directly. I just missed this cleanup when converting them. |
||
/// | ||
/// @param platformBitmap The Pigeon representation of the icon image. | ||
/// @param registrar A Flutter plugin registrar. | ||
/// @param screenScale Screen scale factor for scaling bitmaps. Must be greater than 0. | ||
/// @return A UIImage object created from the icon data. | ||
/// @note Assert unless screenScale is greater than 0. | ||
- (UIImage *)iconFromBitmap:(FGMPlatformBitmap *)platformBitmap | ||
registrar:(NSObject<FlutterPluginRegistrar> *)registrar | ||
screenScale:(CGFloat)screenScale; | ||
/// The underlying controlled GMSMarker. | ||
@property(strong, nonatomic, readonly) GMSMarker *marker; | ||
|
||
/// Checks if an image can be scaled from an original size to a target size using a scale factor | ||
/// while maintaining the aspect ratio. | ||
/// | ||
/// @param originalSize The original size of the image. | ||
/// @param targetSize The desired target size to scale the image to. | ||
/// @return A BOOL indicating whether the image can be scaled to the target size with scale | ||
/// factor. | ||
+ (BOOL)isScalableWithScaleFactorFromSize:(CGSize)originalSize toSize:(CGSize)targetSize; | ||
@end | ||
|
||
/// Methods exposed for unit testing. | ||
@interface FLTMarkersController (Test) | ||
|
||
/// A mapping from marker identifiers to corresponding marker controllers. | ||
@property(strong, nonatomic, readonly) NSMutableDictionary *markerIdentifierToController; | ||
|
||
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was dead code; I accidentally dropped the call to this method when converting the method above, instead of updating it (and folding it in as I've now done, since it's no longer complex enough to benefit from a separate method). That dropped call was the source of the regression.