forked from flutter/flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[google_maps_flutter] Implement polyline patterns in google maps ios (f…
…lutter#5757) This PR Implements patterns in google maps ios polylines. Currently the patterns param is simply ignored on ios, despite the official google maps SDK for ios having instructions on how to achieve repeated patterns: https://developers.google.com/maps/documentation/ios-sdk/shapes#add-a-repeating-color-pattern-to-a-polyline *List which issues are fixed by this PR. You must list at least one issue.* flutter#60083 *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].* Nil
- Loading branch information
Showing
14 changed files
with
213 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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 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
4 changes: 4 additions & 0 deletions
4
packages/google_maps_flutter/google_maps_flutter_ios/CHANGELOG.md
This file contains 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 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 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
81 changes: 81 additions & 0 deletions
81
...oogle_maps_flutter_ios/example/ios14/ios/RunnerTests/GoogleMapsPolylinesControllerTests.m
This file contains 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,81 @@ | ||
// 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/GoogleMapPolylineController_Test.h> | ||
#import "PartiallyMockedMapView.h" | ||
|
||
@interface GoogleMapsPolylinesControllerTests : XCTestCase | ||
@end | ||
|
||
@implementation GoogleMapsPolylinesControllerTests | ||
|
||
/// Returns GoogleMapPolylineController object instantiated with a mocked map instance | ||
/// | ||
/// @return An object of FLTGoogleMapPolylineController | ||
- (FLTGoogleMapPolylineController *)polylineControllerWithMockedMap { | ||
NSDictionary<NSString *, id> *polyline = @{ | ||
@"points" : @[ | ||
@[ @(52.4816), @(-3.1791) ], @[ @(54.043), @(-2.9925) ], @[ @(54.1396), @(-4.2739) ], | ||
@[ @(53.4153), @(-4.0829) ] | ||
], | ||
@"polylineId" : @"polyline_id_0", | ||
}; | ||
|
||
CGRect frame = CGRectMake(0, 0, 100, 100); | ||
GMSCameraPosition *camera = [[GMSCameraPosition alloc] initWithLatitude:0 longitude:0 zoom:0]; | ||
|
||
GMSMapViewOptions *mapViewOptions = [[GMSMapViewOptions alloc] init]; | ||
mapViewOptions.frame = frame; | ||
mapViewOptions.camera = camera; | ||
|
||
PartiallyMockedMapView *mapView = [[PartiallyMockedMapView alloc] initWithOptions:mapViewOptions]; | ||
|
||
GMSMutablePath *path = [FLTPolylinesController pathForPolyline:polyline]; | ||
NSString *identifier = polyline[@"polylineId"]; | ||
|
||
FLTGoogleMapPolylineController *polylineControllerWithMockedMap = | ||
[[FLTGoogleMapPolylineController alloc] initPolylineWithPath:path | ||
identifier:identifier | ||
mapView:mapView]; | ||
|
||
return polylineControllerWithMockedMap; | ||
} | ||
|
||
- (void)testSetPatterns { | ||
NSArray<GMSStrokeStyle *> *styles = @[ | ||
[GMSStrokeStyle solidColor:[UIColor clearColor]], [GMSStrokeStyle solidColor:[UIColor redColor]] | ||
]; | ||
|
||
NSArray<NSNumber *> *lengths = @[ @10, @10 ]; | ||
|
||
FLTGoogleMapPolylineController *polylineController = [self polylineControllerWithMockedMap]; | ||
|
||
XCTAssertNil(polylineController.polyline.spans); | ||
|
||
[polylineController setPattern:styles lengths:lengths]; | ||
|
||
// `GMSStyleSpan` doesn't implement `isEqual` so cannot be compared by value at present. | ||
XCTAssertNotNil(polylineController.polyline.spans); | ||
} | ||
|
||
- (void)testStrokeStylesFromPatterns { | ||
NSArray<NSArray<id> *> *patterns = @[ @[ @"gap", @10 ], @[ @"dash", @10 ] ]; | ||
UIColor *strokeColor = [UIColor redColor]; | ||
|
||
NSArray<GMSStrokeStyle *> *patternStrokeStyle = | ||
[FLTGoogleMapJSONConversions strokeStylesFromPatterns:patterns strokeColor:strokeColor]; | ||
|
||
XCTAssertEqual([patternStrokeStyle count], 2); | ||
|
||
// None of the parameters of `patternStrokeStyle` is observable, so we limit to testing | ||
// the length of this output array. | ||
} | ||
|
||
@end |
This file contains 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 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 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 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 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
24 changes: 24 additions & 0 deletions
24
...oogle_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapPolylineController_Test.h
This file contains 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,24 @@ | ||
// 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 "GoogleMapPolylineController.h" | ||
|
||
/// Internal APIs exposed for unit testing | ||
@interface FLTGoogleMapPolylineController (Test) | ||
|
||
/// Polyline instance the controller is attached to | ||
@property(strong, nonatomic) GMSPolyline *polyline; | ||
|
||
@end | ||
|
||
/// Internal APIs explosed for unit testing | ||
@interface FLTPolylinesController (Test) | ||
|
||
/// Returns the path for polyline based on the points(locations) the polyline has. | ||
/// | ||
/// @param polyline The polyline instance for which path is calculated. | ||
/// @return An instance of GMSMutablePath. | ||
+ (GMSMutablePath *)pathForPolyline:(NSDictionary *)polyline; | ||
|
||
@end |
This file contains 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 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