-
Notifications
You must be signed in to change notification settings - Fork 288
Expand file tree
/
Copy pathRNGooglePlacesViewController.m
More file actions
114 lines (95 loc) · 4.1 KB
/
RNGooglePlacesViewController.m
File metadata and controls
114 lines (95 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#import "RNGooglePlacesViewController.h"
#import "NSMutableDictionary+GMSPlace.h"
#import <GooglePlaces/GooglePlaces.h>
#import <React/RCTUtils.h>
#import <React/RCTLog.h>
@interface RNGooglePlacesViewController ()<GMSAutocompleteViewControllerDelegate>
@end
@implementation RNGooglePlacesViewController
{
RNGooglePlacesViewController *_instance;
RCTPromiseResolveBlock _resolve;
RCTPromiseRejectBlock _reject;
}
- (instancetype)init
{
self = [super init];
_instance = self;
return self;
}
- (void)openAutocompleteModal: (GMSAutocompleteFilter *)autocompleteFilter
placeFields: (GMSPlaceField)selectedFields
bounds: (GMSCoordinateBounds *)autocompleteBounds
boundsMode: (GMSAutocompleteBoundsMode)autocompleteBoundsMode
resolver: (RCTPromiseResolveBlock)resolve
rejecter: (RCTPromiseRejectBlock)reject;
{
_resolve = resolve;
_reject = reject;
GMSAutocompleteViewController *viewController = [[GMSAutocompleteViewController alloc] init];
///////////// Updates for the UI fix for Dark Mode /////////////////////////////
if (@available(iOS 13.0, *)) {
if(UIScreen.mainScreen.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark ){
viewController.primaryTextColor = UIColor.whiteColor;
viewController.secondaryTextColor = UIColor.lightGrayColor;
viewController.tableCellSeparatorColor = UIColor.lightGrayColor;
viewController.tableCellBackgroundColor = UIColor.darkGrayColor;
} else {
viewController.primaryTextColor = UIColor.blackColor;
viewController.secondaryTextColor = UIColor.lightGrayColor;
viewController.tableCellSeparatorColor = UIColor.lightGrayColor;
viewController.tableCellBackgroundColor = UIColor.whiteColor;
}
}
/////////////////////////////////////////////////////////////////////////////
viewController.autocompleteFilter = autocompleteFilter;
viewController.autocompleteBounds = autocompleteBounds;
viewController.autocompleteBoundsMode = autocompleteBoundsMode;
viewController.placeFields = selectedFields;
viewController.delegate = self;
UIViewController *topController = [self getTopController];
[topController presentViewController:viewController animated:YES completion:nil];
}
// Handle the user's selection.
- (void)viewController:(GMSAutocompleteViewController *)viewController
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
{
UIViewController *topController = [self getTopController];
[topController dismissViewControllerAnimated:YES completion:nil];
// TODO: handle the error.
NSLog(@"Error: %@", [error description]);
_reject(@"E_AUTOCOMPLETE_ERROR", [error description], nil);
}
// User canceled the operation.
- (void)wasCancelled:(GMSAutocompleteViewController *)viewController
{
UIViewController *topController = [self getTopController];
[topController dismissViewControllerAnimated:YES completion:nil];
_reject(@"E_USER_CANCELED", @"Search cancelled", nil);
}
// Turn the network activity indicator on and off again.
- (void)didRequestAutocompletePredictions:(GMSAutocompleteViewController *)viewController
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
- (void)didUpdateAutocompletePredictions:(GMSAutocompleteViewController *)viewController
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
// User canceled the operation.
- (UIViewController *)getTopController
{
UIViewController *topController = [UIApplication sharedApplication].delegate.window.rootViewController;
while (topController.presentedViewController) { topController = topController.presentedViewController; }
return topController;
}
@end