Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[google_maps_flutter] Marker APIs are now widget based (iOS Changes)#1240

Merged
iskakaushik merged 6 commits intoflutter:masterfrom
iskakaushik:feature/maps-ios-impl
Feb 27, 2019
Merged

[google_maps_flutter] Marker APIs are now widget based (iOS Changes)#1240
iskakaushik merged 6 commits intoflutter:masterfrom
iskakaushik:feature/maps-ios-impl

Conversation

@iskakaushik
Copy link
Contributor

No description provided.

@iskakaushik iskakaushik requested a review from amirh February 19, 2019 22:44
@bparrishMines bparrishMines changed the title Marker APIs are now widget based (iOS Changes) [google_maps_flutter] Marker APIs are now widget based (iOS Changes) Feb 22, 2019
Copy link
Contributor

@amirh amirh left a comment

Choose a reason for hiding this comment

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

Left a few nits.

Overall looks ok, but I don't speak ObjC well enough 😄 @cyanglaz can you also take a look?


#import "JsonConversions.h"

bool toBool(id json) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't add functions to the global namespace.
Make these class methods of an ObjC class.

}
@end

static void interpretMarkerOptions(id json, id<FLTGoogleMapMarkerOptionsSink> sink,
Copy link
Contributor

Choose a reason for hiding this comment

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

This should start with a capital letter, see: http://google.github.io/styleguide/objcguide.html#function-names

NSArray* iconData = icon;
UIImage* image;
if ([iconData[0] isEqualToString:@"defaultMarker"]) {
CGFloat hue = (iconData.count == 1) ? 0.0f : toDouble(iconData[1]);
Copy link
Contributor

Choose a reason for hiding this comment

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

(not for this PR) it's a little weird that we pass just the hue parameter, would it make sense to pass the exact color?

}
id icon = data[@"icon"];
if (icon) {
NSArray* iconData = icon;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I'd consider extract the iconData parsing to a separate function, this one is becoming a little long.

Copy link
Contributor

Choose a reason for hiding this comment

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

probably same for infoWindow

}
- (void)addMarkers:(id)markersToAdd {
NSArray<id>* markers = markersToAdd;
if (!markers) {
Copy link
Contributor

Choose a reason for hiding this comment

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

A safer check would be:
if (![markersToAdd isKindOfClass:[NSArray class]]), this also covers the cases that it's NSNull (if it was explicitly set to null), or that it is a wrong type.

Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

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

I have added more detailed comments on the other PR you originally created.
One thing is that there are a lot usage of id which I don't think they are necessary. When getting values from NSDictionary like map[@"key"] you can totally assume you would get a NSString, e.g. NSString *value = map[@"key"] and then check the type to be sure by if([value isKindOfClass:[NSString class]]); This way you avoid a lot of id usage and you can get useful compiler warnings if a wrong type is used.
I left an example comment in this PR but you can find more detailed review on the other PR you originally created.

}
return self;
}
- (void)addMarkers:(id)markersToAdd {
Copy link
Contributor

Choose a reason for hiding this comment

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

The type of the parameter can be NSArray if you only want to work with NSArray, use id only when the type of the object is possible to be more than 1.

Suggested change
- (void)addMarkers:(id)markersToAdd {
- (void)addMarkers:(NSArray *)markersToAdd {

Same for other similar places in this PR that use id as type.

BOOL _consumeTapEvents;
}
- (instancetype)initWithPosition:(CLLocationCoordinate2D)position mapView:(GMSMapView*)mapView {
- (instancetype)initWithPositionAndId:(CLLocationCoordinate2D)position
Copy link
Contributor

Choose a reason for hiding this comment

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

Objc usually only have the first parameter name in the method body

Suggested change
- (instancetype)initWithPositionAndId:(CLLocationCoordinate2D)position
- (instancetype)initWithPosition:(CLLocationCoordinate2D)position andMarkerId:....

if (icon) {
NSArray* iconData = icon;
UIImage* image;
if ([iconData[0] isEqualToString:@"defaultMarker"]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

it would crash if iconData is size 0. If you only want to escape this if block, then maybe use .firstObject of NSArray which returns nil when the array is nil or empty; and makes the if statement return NO(false).

Suggested change
if ([iconData[0] isEqualToString:@"defaultMarker"]) {
if ([iconData.firstObject isEqualToString:@"defaultMarker"]) {

NSArray* iconData = icon;
UIImage* image;
if ([iconData[0] isEqualToString:@"defaultMarker"]) {
CGFloat hue = (iconData.count == 1) ? 0.0f : toDouble(iconData[1]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure iconData.count > 1?

} else if ([iconData[0] isEqualToString:@"fromAsset"]) {
if (iconData.count == 2) {
image = [UIImage imageNamed:[registrar lookupKeyForAsset:iconData[1]]];
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this else covers only iconData.count > 2?

return;
}
for (id markerId in markerIds) {
if (!markerId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can markerId be nil? The check seems not necessary.

@cyanglaz
Copy link
Contributor

download
Offline Discussion: We will have another PR for error handling if necessary.

@amirh
Copy link
Contributor

amirh commented Feb 27, 2019

LGTM

@iskakaushik iskakaushik merged commit 1a8d07a into flutter:master Feb 27, 2019
@iskakaushik iskakaushik deleted the feature/maps-ios-impl branch February 27, 2019 15:17
romaluca pushed a commit to romaluca/plugins that referenced this pull request Mar 6, 2019
…lutter#1240)

* Maps Widget Marker IOS impl

* Make JSON Conversions part of a class

* fix formatting issues

* Remove all usages of id

* Fix NSDictionary usage

* Fix compile error
@wterrill
Copy link

If the markers are now widget based, does this mean that they can be accessed by the animation features of flutter? (i.e. AnimatedContainer, AnimatedOpacity)

@JayPerfetto
Copy link

  • 1 for how to make these fade in and out when mounted - I am not having luck using any kind of animations

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants