expo-web-browser 10.0.3 → 10.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -3
- package/README.md +4 -4
- package/android/build.gradle +43 -26
- package/build/ExpoWebBrowser.d.ts +1 -0
- package/build/ExpoWebBrowser.d.ts.map +1 -0
- package/build/ExpoWebBrowser.web.d.ts +1 -0
- package/build/ExpoWebBrowser.web.d.ts.map +1 -0
- package/build/ExpoWebBrowser.web.js +1 -1
- package/build/ExpoWebBrowser.web.js.map +1 -1
- package/build/WebBrowser.d.ts +26 -17
- package/build/WebBrowser.d.ts.map +1 -0
- package/build/WebBrowser.js +31 -23
- package/build/WebBrowser.js.map +1 -1
- package/build/WebBrowser.types.d.ts +92 -16
- package/build/WebBrowser.types.d.ts.map +1 -0
- package/build/WebBrowser.types.js +47 -3
- package/build/WebBrowser.types.js.map +1 -1
- package/expo-module.config.json +6 -0
- package/ios/{EXWebBrowser.podspec → ExpoWebBrowser.podspec} +10 -3
- package/ios/WebAuthSession.swift +59 -0
- package/ios/WebBrowserExceptions.swift +9 -0
- package/ios/WebBrowserModule.swift +53 -0
- package/ios/WebBrowserOptions.swift +86 -0
- package/ios/WebBrowserSession.swift +63 -0
- package/package.json +6 -4
- package/src/ExpoWebBrowser.web.ts +1 -1
- package/src/WebBrowser.ts +33 -21
- package/src/WebBrowser.types.ts +94 -16
- package/ios/EXWebBrowser/EXWebBrowser.h +0 -9
- package/ios/EXWebBrowser/EXWebBrowser.m +0 -280
- package/unimodule.json +0 -4
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
// Copyright 2015-present 650 Industries. All rights reserved.
|
|
2
|
-
|
|
3
|
-
#import <SafariServices/SafariServices.h>
|
|
4
|
-
#import <EXWebBrowser/EXWebBrowser.h>
|
|
5
|
-
|
|
6
|
-
#import <ExpoModulesCore/EXUtilities.h>
|
|
7
|
-
|
|
8
|
-
static NSString* const WebBrowserErrorCode = @"WebBrowser";
|
|
9
|
-
static NSString* const WebBrowserControlsColorKey = @"controlsColor";
|
|
10
|
-
static NSString* const WebBrowserToolbarColorKey = @"toolbarColor";
|
|
11
|
-
|
|
12
|
-
@interface EXWebBrowser () <SFSafariViewControllerDelegate>
|
|
13
|
-
|
|
14
|
-
@property (nonatomic, copy) EXPromiseResolveBlock redirectResolve;
|
|
15
|
-
@property (nonatomic, copy) EXPromiseRejectBlock redirectReject;
|
|
16
|
-
@property (nonatomic, weak) EXModuleRegistry *moduleRegistry;
|
|
17
|
-
|
|
18
|
-
#pragma clang diagnostic push
|
|
19
|
-
#pragma clang diagnostic ignored "-Wpartial-availability"
|
|
20
|
-
@property (nonatomic, strong) SFAuthenticationSession *authSession;
|
|
21
|
-
#pragma clang diagnostic pop
|
|
22
|
-
|
|
23
|
-
@end
|
|
24
|
-
|
|
25
|
-
@implementation EXWebBrowser
|
|
26
|
-
{
|
|
27
|
-
UIStatusBarStyle _initialStatusBarStyle;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
EX_EXPORT_MODULE(ExpoWebBrowser)
|
|
31
|
-
|
|
32
|
-
- (dispatch_queue_t)methodQueue
|
|
33
|
-
{
|
|
34
|
-
return dispatch_get_main_queue();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
EX_EXPORT_METHOD_AS(openAuthSessionAsync,
|
|
38
|
-
openAuthSessionAsync:(NSString *)authURL
|
|
39
|
-
redirectURL:(NSString *)redirectURL
|
|
40
|
-
resolver:(EXPromiseResolveBlock)resolve
|
|
41
|
-
rejecter:(EXPromiseRejectBlock)reject)
|
|
42
|
-
{
|
|
43
|
-
[self initializeWebBrowserWithResolver:resolve andRejecter:reject];
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (@available(iOS 11, *)) {
|
|
47
|
-
NSURL *url = [[NSURL alloc] initWithString: authURL];
|
|
48
|
-
__weak typeof(self) weakSelf = self;
|
|
49
|
-
void (^completionHandler)(NSURL * _Nullable, NSError *_Nullable) = ^(NSURL* _Nullable callbackURL, NSError* _Nullable error) {
|
|
50
|
-
__strong typeof(weakSelf) strongSelf = weakSelf;
|
|
51
|
-
//check if flow didn't already finish
|
|
52
|
-
if (strongSelf && strongSelf->_redirectResolve) {
|
|
53
|
-
if (!error) {
|
|
54
|
-
NSString *url = callbackURL.absoluteString;
|
|
55
|
-
strongSelf->_redirectResolve(@{
|
|
56
|
-
@"type" : @"success",
|
|
57
|
-
@"url" : url,
|
|
58
|
-
});
|
|
59
|
-
} else {
|
|
60
|
-
strongSelf->_redirectResolve(@{
|
|
61
|
-
@"type" : @"cancel",
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
[strongSelf flowDidFinish];
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
_authSession = [[SFAuthenticationSession alloc]
|
|
68
|
-
initWithURL:url
|
|
69
|
-
callbackURLScheme:redirectURL
|
|
70
|
-
completionHandler:completionHandler];
|
|
71
|
-
[_authSession start];
|
|
72
|
-
} else {
|
|
73
|
-
resolve(@{
|
|
74
|
-
@"type" : @"cancel",
|
|
75
|
-
@"message" : @"openAuthSessionAsync requires iOS 11 or greater"
|
|
76
|
-
});
|
|
77
|
-
[self flowDidFinish];
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
EX_EXPORT_METHOD_AS(openBrowserAsync,
|
|
83
|
-
openBrowserAsync:(NSString *)authURL
|
|
84
|
-
withArguments:(NSDictionary *)arguments
|
|
85
|
-
resolver:(EXPromiseResolveBlock)resolve
|
|
86
|
-
rejecter:(EXPromiseRejectBlock)reject)
|
|
87
|
-
{
|
|
88
|
-
if (![self initializeWebBrowserWithResolver:resolve andRejecter:reject]) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
NSURL *url = [[NSURL alloc] initWithString:authURL];
|
|
93
|
-
BOOL readerMode = [arguments[@"readerMode"] boolValue];
|
|
94
|
-
BOOL enableBarCollapsing = [arguments[@"enableBarCollapsing"] boolValue];
|
|
95
|
-
SFSafariViewController *safariVC = nil;
|
|
96
|
-
if (@available(iOS 11, *)) {
|
|
97
|
-
SFSafariViewControllerConfiguration *config = [[SFSafariViewControllerConfiguration alloc] init];
|
|
98
|
-
config.barCollapsingEnabled = enableBarCollapsing;
|
|
99
|
-
config.entersReaderIfAvailable = readerMode;
|
|
100
|
-
safariVC = [[SFSafariViewController alloc] initWithURL:url configuration:config];
|
|
101
|
-
} else {
|
|
102
|
-
safariVC = [[SFSafariViewController alloc] initWithURL:url entersReaderIfAvailable:readerMode];
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
NSString *dismissButtonStyle = [arguments valueForKey:@"dismissButtonStyle"];
|
|
106
|
-
if ([@"done" isEqualToString:dismissButtonStyle]) {
|
|
107
|
-
safariVC.dismissButtonStyle = SFSafariViewControllerDismissButtonStyleDone;
|
|
108
|
-
}
|
|
109
|
-
else if ([@"close" isEqualToString:dismissButtonStyle]) {
|
|
110
|
-
safariVC.dismissButtonStyle = SFSafariViewControllerDismissButtonStyleClose;
|
|
111
|
-
}
|
|
112
|
-
else if ([@"cancel" isEqualToString:dismissButtonStyle]) {
|
|
113
|
-
safariVC.dismissButtonStyle = SFSafariViewControllerDismissButtonStyleCancel;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if([[arguments allKeys] containsObject:WebBrowserToolbarColorKey]) {
|
|
117
|
-
safariVC.preferredBarTintColor = [EXWebBrowser convertHexColorString:arguments[WebBrowserToolbarColorKey]];
|
|
118
|
-
}
|
|
119
|
-
if([[arguments allKeys] containsObject:WebBrowserControlsColorKey]) {
|
|
120
|
-
safariVC.preferredControlTintColor = [EXWebBrowser convertHexColorString:arguments[WebBrowserControlsColorKey]];
|
|
121
|
-
}
|
|
122
|
-
safariVC.delegate = self;
|
|
123
|
-
// By setting the modal presentation style to OverFullScreen, we disable the "Swipe to dismiss"
|
|
124
|
-
// gesture that is causing a bug where sometimes `safariViewControllerDidFinish` is not called.
|
|
125
|
-
// There are bugs filed already about it on OpenRadar.
|
|
126
|
-
[safariVC setModalPresentationStyle: UIModalPresentationOverFullScreen];
|
|
127
|
-
|
|
128
|
-
// This is a hack to present the SafariViewController modally
|
|
129
|
-
UINavigationController *safariHackVC = [[UINavigationController alloc] initWithRootViewController:safariVC];
|
|
130
|
-
[safariHackVC setNavigationBarHidden:true animated:false];
|
|
131
|
-
[safariHackVC setModalPresentationStyle: UIModalPresentationOverFullScreen];
|
|
132
|
-
|
|
133
|
-
UIViewController *currentViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
|
|
134
|
-
while (currentViewController.presentedViewController) {
|
|
135
|
-
currentViewController = currentViewController.presentedViewController;
|
|
136
|
-
}
|
|
137
|
-
[currentViewController presentViewController:safariHackVC animated:true completion:nil];
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
EX_EXPORT_METHOD_AS(dismissBrowser,
|
|
141
|
-
dismissBrowserWithResolver:(EXPromiseResolveBlock)resolve
|
|
142
|
-
rejecter:(EXPromiseRejectBlock)reject)
|
|
143
|
-
{
|
|
144
|
-
__weak typeof(self) weakSelf = self;
|
|
145
|
-
UIViewController *currentViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
|
|
146
|
-
while (currentViewController.presentedViewController) {
|
|
147
|
-
currentViewController = currentViewController.presentedViewController;
|
|
148
|
-
}
|
|
149
|
-
[currentViewController dismissViewControllerAnimated:YES completion:^{
|
|
150
|
-
resolve(nil);
|
|
151
|
-
__strong typeof(self) strongSelf = weakSelf;
|
|
152
|
-
if (strongSelf) {
|
|
153
|
-
if (strongSelf.redirectResolve) {
|
|
154
|
-
strongSelf.redirectResolve(@{
|
|
155
|
-
@"type": @"dismiss",
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
[strongSelf flowDidFinish];
|
|
159
|
-
}
|
|
160
|
-
}];
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
EX_EXPORT_METHOD_AS(dismissAuthSession,
|
|
164
|
-
dismissAuthSessionWithResolver:(EXPromiseResolveBlock)resolve
|
|
165
|
-
rejecter:(EXPromiseRejectBlock)reject)
|
|
166
|
-
{
|
|
167
|
-
if (@available(iOS 11, *)) {
|
|
168
|
-
[_authSession cancel];
|
|
169
|
-
resolve(nil);
|
|
170
|
-
if (_redirectResolve) {
|
|
171
|
-
_redirectResolve(@{
|
|
172
|
-
@"type": @"dismiss"
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
[self flowDidFinish];
|
|
176
|
-
}
|
|
177
|
-
} else {
|
|
178
|
-
[self dismissAuthSessionWithResolver:resolve rejecter:reject];
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
EX_EXPORT_METHOD_AS(warmUpAsync,
|
|
183
|
-
warmUpAsyncWithPackage:(NSString*)browserPackage
|
|
184
|
-
resolver:(EXPromiseResolveBlock)resolve
|
|
185
|
-
rejecter:(EXPromiseRejectBlock)reject)
|
|
186
|
-
{
|
|
187
|
-
// stub for jest-expo-mock-generator
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
EX_EXPORT_METHOD_AS(coolDownAsync,
|
|
191
|
-
coolDownAsyncWithPackage:(NSString*)browserPackage
|
|
192
|
-
resolver:(EXPromiseResolveBlock)resolve
|
|
193
|
-
rejecter:(EXPromiseRejectBlock)reject)
|
|
194
|
-
{
|
|
195
|
-
// stub for jest-expo-mock-generator
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
EX_EXPORT_METHOD_AS(getCustomTabsSupportingBrowsers,
|
|
199
|
-
getCustomTabsSupportingBrowsersWithPackage:(EXPromiseResolveBlock)resolve
|
|
200
|
-
rejecter:(EXPromiseRejectBlock)reject)
|
|
201
|
-
{
|
|
202
|
-
// stub for jest-expo-mock-generator
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
EX_EXPORT_METHOD_AS(mayInitWithUrlAsync,
|
|
206
|
-
warmUpAsyncWithUrl:(NSString*)url
|
|
207
|
-
browserPackage:(NSString*)package
|
|
208
|
-
resolver:(EXPromiseResolveBlock)resolve
|
|
209
|
-
rejecter:(EXPromiseRejectBlock)reject)
|
|
210
|
-
{
|
|
211
|
-
// stub for jest-expo-mock-generator
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Helper that is used in openBrowserAsync and openAuthSessionAsync
|
|
216
|
-
*/
|
|
217
|
-
- (BOOL)initializeWebBrowserWithResolver:(EXPromiseResolveBlock)resolve andRejecter:(EXPromiseRejectBlock)reject {
|
|
218
|
-
if (_redirectResolve) {
|
|
219
|
-
reject(WebBrowserErrorCode, @"Another WebBrowser is already being presented.", nil);
|
|
220
|
-
return NO;
|
|
221
|
-
}
|
|
222
|
-
_redirectReject = reject;
|
|
223
|
-
_redirectResolve = resolve;
|
|
224
|
-
|
|
225
|
-
_initialStatusBarStyle = [UIApplication sharedApplication].statusBarStyle;
|
|
226
|
-
|
|
227
|
-
#pragma clang diagnostic push
|
|
228
|
-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
229
|
-
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault
|
|
230
|
-
animated:YES];
|
|
231
|
-
#pragma clang diagnostic pop
|
|
232
|
-
return YES;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Called when the user dismisses the SFVC without logging in.
|
|
237
|
-
*/
|
|
238
|
-
- (void)safariViewControllerDidFinish:(SFSafariViewController *)controller
|
|
239
|
-
{
|
|
240
|
-
_redirectResolve(@{
|
|
241
|
-
@"type": @"cancel",
|
|
242
|
-
});
|
|
243
|
-
[self flowDidFinish];
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
-(void)flowDidFinish
|
|
247
|
-
{
|
|
248
|
-
#pragma clang diagnostic push
|
|
249
|
-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
250
|
-
[[UIApplication sharedApplication] setStatusBarStyle:_initialStatusBarStyle animated:YES];
|
|
251
|
-
#pragma clang diagnostic pop
|
|
252
|
-
_redirectResolve = nil;
|
|
253
|
-
_redirectReject = nil;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
- (void)setModuleRegistry:(EXModuleRegistry *)moduleRegistry
|
|
257
|
-
{
|
|
258
|
-
_moduleRegistry = moduleRegistry;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
+ (UIColor *)convertHexColorString:(NSString *)stringToConvert {
|
|
262
|
-
NSString *strippedString = [stringToConvert stringByReplacingOccurrencesOfString:@"#" withString:@""];
|
|
263
|
-
NSScanner *scanner = [NSScanner scannerWithString:strippedString];
|
|
264
|
-
unsigned hexNum;
|
|
265
|
-
if (![scanner scanHexInt:&hexNum]) return nil;
|
|
266
|
-
return [EXWebBrowser colorWithRGBHex:hexNum];
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
+ (UIColor *)colorWithRGBHex:(UInt32)hex {
|
|
270
|
-
int r = (hex >> 16) & 0xFF;
|
|
271
|
-
int g = (hex >> 8) & 0xFF;
|
|
272
|
-
int b = (hex) & 0xFF;
|
|
273
|
-
|
|
274
|
-
return [UIColor colorWithRed:r / 255.0f
|
|
275
|
-
green:g / 255.0f
|
|
276
|
-
blue:b / 255.0f
|
|
277
|
-
alpha:1.0f];
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
@end
|
package/unimodule.json
DELETED