Skip to content

Commit

Permalink
Merge pull request #4 from gympass/EXUX-108
Browse files Browse the repository at this point in the history
Update Google Place SDK
  • Loading branch information
eduardobreno committed Mar 9, 2023
2 parents e8825e3 + afdf8f4 commit 407d54d
Show file tree
Hide file tree
Showing 10 changed files with 472 additions and 416 deletions.
279 changes: 160 additions & 119 deletions README.md

Large diffs are not rendered by default.

274 changes: 148 additions & 126 deletions READMEV2.md

Large diffs are not rendered by default.

208 changes: 108 additions & 100 deletions index.d.ts

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions ios/NSMutableDictionary+GMSPlace.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ + (instancetype)dictionaryWithGMSPlace:(GMSPlace*)place
placeData[@"rating"] = [NSNumber numberWithDouble:place.rating];
}

if (place.viewport) {
if (place.viewportInfo) {
NSMutableDictionary *viewportMap = [[NSMutableDictionary alloc] init];
viewportMap[@"latitudeNE"] = [NSNumber numberWithDouble:place.viewport.northEast.latitude];
viewportMap[@"longitudeNE"] = [NSNumber numberWithDouble:place.viewport.northEast.longitude];
viewportMap[@"latitudeSW"] = [NSNumber numberWithDouble:place.viewport.southWest.latitude];
viewportMap[@"longitudeSW"] = [NSNumber numberWithDouble:place.viewport.southWest.longitude];
viewportMap[@"latitudeNE"] = [NSNumber numberWithDouble:place.viewportInfo.northEast.latitude];
viewportMap[@"longitudeNE"] = [NSNumber numberWithDouble:place.viewportInfo.northEast.longitude];
viewportMap[@"latitudeSW"] = [NSNumber numberWithDouble:place.viewportInfo.southWest.latitude];
viewportMap[@"longitudeSW"] = [NSNumber numberWithDouble:place.viewportInfo.southWest.longitude];

placeData[@"viewport"] = viewportMap;
}
Expand Down
4 changes: 2 additions & 2 deletions ios/RNGooglePlaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
#import <React/RCTBridge.h>
#import <React/RCTEventDispatcher.h>

#import <GoogleMapsBase/GoogleMapsBase.h>
#import <GooglePlaces/GooglePlaces.h>

@interface RNGooglePlaces : NSObject <RCTBridgeModule>

- (GMSPlacesAutocompleteTypeFilter) getFilterType:(NSString *)type;
- (GMSPlaceField) getSelectedFields:(NSArray *)fields isCurrentOrFetchPlace:(Boolean)currentOrFetch;
- (GMSCoordinateBounds *) getBounds: (NSDictionary *)biasOptions andRestrictOptions: (NSDictionary *)restrictOptions;
- (GMSCoordinateBounds *) getBounds: (NSDictionary *)biasOptions andRestrictOptions: (NSDictionary *)restrictOptions filter: (GMSAutocompleteFilter *)autocompleteFilter;

@end

56 changes: 22 additions & 34 deletions ios/RNGooglePlaces.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
#import <React/RCTLog.h>
#import <React/RCTConvert.h>

#import <GoogleMapsBase/GoogleMapsBase.h>
#import <GooglePlaces/GooglePlaces.h>

@interface RNGooglePlaces() <CLLocationManagerDelegate>

@property (strong, nonatomic) CLLocationManager *locationManager;
@property GMSAutocompleteBoundsMode boundsMode;
@property GMSAutocompleteSessionToken *sessionToken;

@end
Expand Down Expand Up @@ -41,10 +41,8 @@ - (instancetype)init
_instance = self;
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;

self.boundsMode = kGMSAutocompleteBoundsModeBias;
}

return self;
}

Expand Down Expand Up @@ -84,9 +82,9 @@ - (void)cancelAutocompleteSession
NSDictionary *locationRestriction = [RCTConvert NSDictionary:options[@"locationRestriction"]];


GMSCoordinateBounds *autocompleteBounds = [self getBounds:locationBias andRestrictOptions:locationRestriction];
GMSCoordinateBounds *autocompleteBounds = [self getBounds:locationBias andRestrictOptions:locationRestriction filter:autocompleteFilter];

[acController openAutocompleteModal: autocompleteFilter placeFields: selectedFields bounds: autocompleteBounds boundsMode: self.boundsMode resolver: resolve rejecter: reject];
[acController openAutocompleteModal: autocompleteFilter placeFields: selectedFields bounds: autocompleteBounds resolver: resolve rejecter: reject];
}
@catch (NSException * e) {
reject(@"E_OPEN_FAILED", @"Could not open modal", [self errorFromException:e]);
Expand All @@ -102,15 +100,13 @@ - (void)cancelAutocompleteSession
GMSAutocompleteFilter *autocompleteFilter = [[GMSAutocompleteFilter alloc] init];
autocompleteFilter.type = [self getFilterType:[RCTConvert NSString:options[@"type"]]];
autocompleteFilter.country = [options[@"country"] length] == 0? nil : options[@"country"];

NSDictionary *locationBias = [RCTConvert NSDictionary:options[@"locationBias"]];
NSDictionary *locationRestriction = [RCTConvert NSDictionary:options[@"locationRestriction"]];
GMSCoordinateBounds *autocompleteBounds = [self getBounds:locationBias andRestrictOptions:locationRestriction];

GMSCoordinateBounds *autocompleteBounds = [self getBounds:locationBias andRestrictOptions:locationRestriction filter:autocompleteFilter];

[[GMSPlacesClient sharedClient] findAutocompletePredictionsFromQuery:query
bounds:autocompleteBounds
boundsMode:self.boundsMode
filter:autocompleteFilter
sessionToken:self.sessionToken
callback:^(NSArray<GMSAutocompletePrediction *> * _Nullable results, NSError *error) {
Expand All @@ -122,20 +118,20 @@ - (void)cancelAutocompleteSession
if (results != nil) {
for (GMSAutocompletePrediction* result in results) {
NSMutableDictionary *placeData = [[NSMutableDictionary alloc] init];

placeData[@"fullText"] = result.attributedFullText.string;
placeData[@"primaryText"] = result.attributedPrimaryText.string;
placeData[@"secondaryText"] = result.attributedSecondaryText.string;
placeData[@"placeID"] = result.placeID;
placeData[@"types"] = result.types;

[autoCompleteSuggestionsList addObject:placeData];
}

resolve(autoCompleteSuggestionsList);

}

}];
}

Expand All @@ -152,7 +148,7 @@ - (void)cancelAutocompleteSession
reject(@"E_PLACE_DETAILS_ERROR", [error localizedDescription], nil);
return;
}

if (place != nil) {
resolve([NSMutableDictionary dictionaryWithGMSPlace:place]);
} else {
Expand All @@ -166,7 +162,7 @@ - (void)cancelAutocompleteSession
rejecter: (RCTPromiseRejectBlock)reject)
{
[self.locationManager requestAlwaysAuthorization];


GMSPlaceField selectedFields = [self getSelectedFields:fields isCurrentOrFetchPlace:true];

Expand Down Expand Up @@ -200,7 +196,7 @@ - (NSError *) errorFromException: (NSException *) exception
@"callStackSymbols": exception.callStackSymbols,
@"userInfo": exception.userInfo
};

return [[NSError alloc] initWithDomain: @"RNGooglePlaces"
code: 0
userInfo: exceptionInfo];
Expand Down Expand Up @@ -242,7 +238,7 @@ - (GMSPlaceField) getSelectedFields:(NSArray *)fields isCurrentOrFetchPlace:(Boo
@"addressComponents" : @(GMSPlaceFieldAddressComponents),
@"photos" : @(GMSPlaceFieldPhotos),
};

if ([fields count] == 0 && !currentOrFetch) {
return GMSPlaceFieldAll;
}
Expand Down Expand Up @@ -280,11 +276,12 @@ - (GMSPlaceField) getSelectedFields:(NSArray *)fields isCurrentOrFetchPlace:(Boo
}
return placeFields;
}

return GMSPlaceFieldAll;
}

- (GMSCoordinateBounds *) getBounds: (NSDictionary *)biasOptions andRestrictOptions: (NSDictionary *)restrictOptions

- (void) getBounds: (NSDictionary *)biasOptions andRestrictOptions: (NSDictionary *)restrictOptions filter: (GMSAutocompleteFilter *)autocompleteFilter
{
double biasLatitudeSW = [[RCTConvert NSNumber:biasOptions[@"latitudeSW"]] doubleValue];
double biasLongitudeSW = [[RCTConvert NSNumber:biasOptions[@"longitudeSW"]] doubleValue];
Expand All @@ -299,26 +296,17 @@ - (GMSCoordinateBounds *) getBounds: (NSDictionary *)biasOptions andRestrictOpti
if (biasLatitudeSW != 0 && biasLongitudeSW != 0 && biasLatitudeNE != 0 && biasLongitudeNE != 0) {
CLLocationCoordinate2D neBoundsCorner = CLLocationCoordinate2DMake(biasLatitudeNE, biasLongitudeNE);
CLLocationCoordinate2D swBoundsCorner = CLLocationCoordinate2DMake(biasLatitudeSW, biasLongitudeSW);
GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:neBoundsCorner
coordinate:swBoundsCorner];

return bounds;
}
autocompleteFilter.locationBias = GMSPlaceRectangularLocationOption(neBoundsCorner, swBoundsCorner);
}

if (restrictLatitudeSW != 0 && restrictLongitudeSW != 0 && restrictLatitudeNE != 0 && restrictLongitudeNE != 0) {
CLLocationCoordinate2D neBoundsCorner = CLLocationCoordinate2DMake(restrictLatitudeNE, restrictLongitudeNE);
CLLocationCoordinate2D swBoundsCorner = CLLocationCoordinate2DMake(restrictLatitudeSW, restrictLongitudeSW);
GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:neBoundsCorner
coordinate:swBoundsCorner];

self.boundsMode = kGMSAutocompleteBoundsModeRestrict;

return bounds;

autocompleteFilter.locationRestriction = GMSPlaceRectangularLocationOption(neBoundsCorner, swBoundsCorner);
}

return nil;
}


@end

5 changes: 1 addition & 4 deletions ios/RNGooglePlacesViewController.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import <UIKit/UIKit.h>
#import <GoogleMapsBase/GoogleMapsBase.h>
#import <GooglePlaces/GooglePlaces.h>

#import <React/RCTBridge.h>
Expand All @@ -8,13 +9,9 @@
@property(nonatomic, strong) RNGooglePlacesViewController *instance;

- (instancetype) init;

- (void)openAutocompleteModal: (GMSAutocompleteFilter *)autocompleteFilter
placeFields: (GMSPlaceField)selectedFields
bounds: (GMSCoordinateBounds *)autocompleteBounds
boundsMode: (GMSAutocompleteBoundsMode)autocompleteBoundsMode
resolver: (RCTPromiseResolveBlock)resolve
rejecter: (RCTPromiseRejectBlock)reject;


@end
28 changes: 13 additions & 15 deletions ios/RNGooglePlacesViewController.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import "RNGooglePlacesViewController.h"
#import "NSMutableDictionary+GMSPlace.h"

#import <GoogleMapsBase/GoogleMapsBase.h>
#import <GooglePlaces/GooglePlaces.h>
#import <React/RCTUtils.h>
#import <React/RCTLog.h>
Expand All @@ -16,7 +17,7 @@ @implementation RNGooglePlacesViewController
RCTPromiseRejectBlock _reject;
}

- (instancetype)init
- (instancetype)init
{
self = [super init];
_instance = self;
Expand All @@ -26,38 +27,35 @@ - (instancetype)init

- (void)openAutocompleteModal: (GMSAutocompleteFilter *)autocompleteFilter
placeFields: (GMSPlaceField)selectedFields
bounds: (GMSCoordinateBounds *)autocompleteBounds
boundsMode: (GMSAutocompleteBoundsMode)autocompleteBoundsMode
bounds: (GMSCoordinateBounds *)autocompleteBounds
resolver: (RCTPromiseResolveBlock)resolve
rejecter: (RCTPromiseRejectBlock)reject;
{
_resolve = resolve;
_reject = reject;

GMSAutocompleteViewController *viewController = [[GMSAutocompleteViewController alloc] init];
viewController.autocompleteFilter = autocompleteFilter;
viewController.autocompleteBounds = autocompleteBounds;
viewController.autocompleteBoundsMode = autocompleteBoundsMode;
viewController.placeFields = selectedFields;
viewController.delegate = self;
viewController.delegate = self;
UIViewController *topController = [self getTopController];
[topController presentViewController:viewController animated:YES completion:nil];
[topController presentViewController:viewController animated:YES completion:nil];
}

// Handle the user's selection.
- (void)viewController:(GMSAutocompleteViewController *)viewController
didAutocompleteWithPlace:(GMSPlace *)place
didAutocompleteWithPlace:(GMSPlace *)place
{
UIViewController *topController = [self getTopController];
[topController dismissViewControllerAnimated:YES completion:nil];

if (_resolve) {
_resolve([NSMutableDictionary dictionaryWithGMSPlace:place]);
}
}

- (void)viewController:(GMSAutocompleteViewController *)viewController
didFailAutocompleteWithError:(NSError *)error
didFailAutocompleteWithError:(NSError *)error
{
UIViewController *topController = [self getTopController];
[topController dismissViewControllerAnimated:YES completion:nil];
Expand All @@ -69,7 +67,7 @@ - (void)viewController:(GMSAutocompleteViewController *)viewController
}

// User canceled the operation.
- (void)wasCancelled:(GMSAutocompleteViewController *)viewController
- (void)wasCancelled:(GMSAutocompleteViewController *)viewController
{
UIViewController *topController = [self getTopController];
[topController dismissViewControllerAnimated:YES completion:nil];
Expand All @@ -78,12 +76,12 @@ - (void)wasCancelled:(GMSAutocompleteViewController *)viewController
}

// Turn the network activity indicator on and off again.
- (void)didRequestAutocompletePredictions:(GMSAutocompleteViewController *)viewController
- (void)didRequestAutocompletePredictions:(GMSAutocompleteViewController *)viewController
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}

- (void)didUpdateAutocompletePredictions:(GMSAutocompleteViewController *)viewController
- (void)didUpdateAutocompletePredictions:(GMSAutocompleteViewController *)viewController
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
Expand All @@ -96,4 +94,4 @@ - (UIViewController *)getTopController
return topController;
}

@end
@end
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
"description": "iOS/Android Google Places Widgets (Autocomplete Modals) and API Services for React Native Apps",
"main": "index.js",
"author": "Tolu Olowu (Arttitude 360) <[email protected]>",
"version": "3.1.5",
"version": "3.1.6",
"scripts": {},
"repository": {
"type": "git",
"url": "https://github.com/tolu360/react-native-google-places"
"url": "https://github.com/gympass/react-native-google-places"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/tolu360/react-native-google-places/issues"
"url": "https://github.com/gympass/react-native-google-places/issues"
},
"types": "index.d.ts",
"homepage": "https://github.com/tolu360/react-native-google-places#readme",
"homepage": "https://github.com/gympass/react-native-google-places#readme",
"keywords": [
"react",
"react-native",
Expand All @@ -23,6 +23,9 @@
"places",
"google-places",
"Google Places API",
"Google places darkmode",
"Google darkmode",
"darkmode autocomplete",
"autocomplete",
"ios",
"android"
Expand All @@ -32,4 +35,4 @@
"react-native": ">=0.40.0"
},
"devDependencies": {}
}
}
11 changes: 5 additions & 6 deletions react-native-google-places.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ Pod::Spec.new do |s|
s.summary = package['description']
s.description = package['description']
s.license = package['license']
s.author = package['author']
s.homepage = 'https://github.com/tolu360/react-native-google-places'
s.source = { :git => 'https://github.com/tolu360/react-native-google-places.git', :tag => s.version }
s.homepage = 'https://github.com/gympass/react-native-google-places'
s.source = { :git => 'https://github.com/gympass/react-native-google-places.git', :tag => s.version }

s.platform = :ios, '9.0'
s.platform = :ios, '12.0'

s.preserve_paths = 'README.md', 'package.json', 'index.js'
s.source_files = 'ios/*.{h,m}'

s.compiler_flags = '-DHAVE_GOOGLE_MAPS=1', '-fno-modules'

s.dependency 'React'
s.dependency 'GooglePlaces', '~> 3.2.0'
s.dependency 'GoogleMaps', '~> 3.2.0'
s.dependency 'GooglePlaces', '~> 6.1.1'
s.dependency 'GoogleMaps', '~> 6.1.1'
end

0 comments on commit 407d54d

Please sign in to comment.