Skip to content

[google_maps_flutter] Started dispatching platform messages from platform thread #6069

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
merged 10 commits into from
Mar 14, 2024
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.5.1

* Makes the tile overlay callback invoke the platform channel on the platform thread.

## 2.5.0

* Adds support for `MapConfiguration.style`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
0DD7B6C32B744EEF00E857FD /* FLTTileProviderControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DD7B6C22B744EEF00E857FD /* FLTTileProviderControllerTests.m */; };
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
4510D964F3B1259FEDD3ABA6 /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7755F8F4BABC3D6A0BD4048B /* libPods-Runner.a */; };
Expand Down Expand Up @@ -54,6 +55,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
0DD7B6C22B744EEF00E857FD /* FLTTileProviderControllerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FLTTileProviderControllerTests.m; sourceTree = "<group>"; };
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -201,6 +203,7 @@
982F2A6A27BADE17003C81F4 /* PartiallyMockedMapView.h */,
982F2A6B27BADE17003C81F4 /* PartiallyMockedMapView.m */,
F7151F14265D7ED70028CB91 /* Info.plist */,
0DD7B6C22B744EEF00E857FD /* FLTTileProviderControllerTests.m */,
);
path = RunnerTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -460,6 +463,7 @@
F7151F13265D7ED70028CB91 /* GoogleMapsTests.m in Sources */,
6851F3562835BC180032B7C8 /* FLTGoogleMapJSONConversionsConversionTests.m in Sources */,
982F2A6C27BADE17003C81F4 /* PartiallyMockedMapView.m in Sources */,
0DD7B6C32B744EEF00E857FD /* FLTTileProviderControllerTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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 XCTest;
@import GoogleMaps;
@import google_maps_flutter_ios;

#import <OCMock/OCMock.h>

@interface FLTTileProviderControllerTests : XCTestCase
@end

@implementation FLTTileProviderControllerTests

- (void)testCallChannelOnPlatformThread {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: include function name being tested testRequestTileMustCallChannelOnPlatformThread

id channel = OCMClassMock(FlutterMethodChannel.class);
FLTTileProviderController *controller = [[FLTTileProviderController alloc] init:channel
withTileOverlayIdentifier:@"foo"];
XCTAssertNotNil(controller);
XCTestExpectation *expectation = [self expectationWithDescription:@"invokeMethod"];
OCMStub([channel invokeMethod:[OCMArg any] arguments:[OCMArg any] result:[OCMArg any]])
.andDo(^(NSInvocation *invocation) {
XCTAssertTrue([[NSThread currentThread] isMainThread]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: XCTAssertTrue([[NSThread currentThread] isMainThread], @"Method channel must be called on main thread")

[expectation fulfill];
});
id receiver = OCMProtocolMock(@protocol(GMSTileReceiver));
[controller requestTileForX:0 y:0 zoom:0 receiver:receiver];
Copy link
Contributor

@hellohuanlin hellohuanlin Feb 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can just inline this receiver?

[self waitForExpectations:@[ expectation ] timeout:10.0];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -122,37 +122,38 @@ - (void)requestTileForX:(NSUInteger)x
y:(NSUInteger)y
zoom:(NSUInteger)zoom
receiver:(id<GMSTileReceiver>)receiver {
[self.methodChannel
invokeMethod:@"tileOverlay#getTile"
arguments:@{
@"tileOverlayId" : self.tileOverlayIdentifier,
@"x" : @(x),
@"y" : @(y),
@"zoom" : @(zoom)
}
result:^(id _Nullable result) {
UIImage *tileImage;
if ([result isKindOfClass:[NSDictionary class]]) {
FlutterStandardTypedData *typedData = (FlutterStandardTypedData *)result[@"data"];
if (typedData == nil) {
tileImage = kGMSTileLayerNoTile;
} else {
tileImage = [UIImage imageWithData:typedData.data];
}
} else {
if ([result isKindOfClass:[FlutterError class]]) {
FlutterError *error = (FlutterError *)result;
NSLog(@"Can't get tile: errorCode = %@, errorMessage = %@, details = %@",
[error code], [error message], [error details]);
}
if ([result isKindOfClass:[FlutterMethodNotImplemented class]]) {
NSLog(@"Can't get tile: notImplemented");
}
tileImage = kGMSTileLayerNoTile;
}

[receiver receiveTileWithX:x y:y zoom:zoom image:tileImage];
}];
dispatch_async(dispatch_get_main_queue(), ^{
[self.methodChannel invokeMethod:@"tileOverlay#getTile"
arguments:@{
@"tileOverlayId" : self.tileOverlayIdentifier,
@"x" : @(x),
@"y" : @(y),
@"zoom" : @(zoom)
}
result:^(id _Nullable result) {
UIImage *tileImage;
if ([result isKindOfClass:[NSDictionary class]]) {
FlutterStandardTypedData *typedData = (FlutterStandardTypedData *)result[@"data"];
if (typedData == nil) {
tileImage = kGMSTileLayerNoTile;
} else {
tileImage = [UIImage imageWithData:typedData.data];
}
} else {
if ([result isKindOfClass:[FlutterError class]]) {
FlutterError *error = (FlutterError *)result;
NSLog(@"Can't get tile: errorCode = %@, errorMessage = %@, details = %@",
[error code], [error message], [error details]);
}
if ([result isKindOfClass:[FlutterMethodNotImplemented class]]) {
NSLog(@"Can't get tile: notImplemented");
}
tileImage = kGMSTileLayerNoTile;
}

[receiver receiveTileWithX:x y:y zoom:zoom image:tileImage];
}];
});
}

@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: google_maps_flutter_ios
description: iOS implementation of the google_maps_flutter plugin.
repository: https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter_ios
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
version: 2.5.0
version: 2.5.1

environment:
sdk: ^3.2.3
Expand Down