No Description

RNCWKWebView.m 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #import "RNCWKWebView.h"
  8. #import <React/RCTConvert.h>
  9. #import <React/RCTAutoInsetsProtocol.h>
  10. #import "RNCWKProcessPoolManager.h"
  11. #import <UIKit/UIKit.h>
  12. #import "objc/runtime.h"
  13. static NSString *const MessageHanderName = @"ReactNative";
  14. // runtime trick to remove WKWebView keyboard default toolbar
  15. // see: http://stackoverflow.com/questions/19033292/ios-7-uiwebview-keyboard-issue/19042279#19042279
  16. @interface _SwizzleHelperWK : NSObject @end
  17. @implementation _SwizzleHelperWK
  18. -(id)inputAccessoryView
  19. {
  20. return nil;
  21. }
  22. @end
  23. @interface RNCWKWebView () <WKUIDelegate, WKNavigationDelegate, WKScriptMessageHandler, UIScrollViewDelegate, RCTAutoInsetsProtocol>
  24. @property (nonatomic, copy) RCTDirectEventBlock onLoadingStart;
  25. @property (nonatomic, copy) RCTDirectEventBlock onLoadingFinish;
  26. @property (nonatomic, copy) RCTDirectEventBlock onLoadingError;
  27. @property (nonatomic, copy) RCTDirectEventBlock onLoadingProgress;
  28. @property (nonatomic, copy) RCTDirectEventBlock onShouldStartLoadWithRequest;
  29. @property (nonatomic, copy) RCTDirectEventBlock onMessage;
  30. @property (nonatomic, copy) WKWebView *webView;
  31. @end
  32. @implementation RNCWKWebView
  33. {
  34. UIColor * _savedBackgroundColor;
  35. BOOL _savedHideKeyboardAccessoryView;
  36. }
  37. - (void)dealloc{}
  38. /**
  39. * See https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/DisplayWebContent/Tasks/WebKitAvail.html.
  40. */
  41. + (BOOL)dynamicallyLoadWebKitIfAvailable
  42. {
  43. static BOOL _webkitAvailable=NO;
  44. static dispatch_once_t onceToken;
  45. dispatch_once(&onceToken, ^{
  46. NSBundle *webKitBundle = [NSBundle bundleWithPath:@"/System/Library/Frameworks/WebKit.framework"];
  47. if (webKitBundle) {
  48. _webkitAvailable = [webKitBundle load];
  49. }
  50. });
  51. return _webkitAvailable;
  52. }
  53. - (instancetype)initWithFrame:(CGRect)frame
  54. {
  55. if ((self = [super initWithFrame:frame])) {
  56. super.backgroundColor = [UIColor clearColor];
  57. _bounces = YES;
  58. _scrollEnabled = YES;
  59. _automaticallyAdjustContentInsets = YES;
  60. _contentInset = UIEdgeInsetsZero;
  61. }
  62. return self;
  63. }
  64. - (void)didMoveToWindow
  65. {
  66. if (self.window != nil && _webView == nil) {
  67. if (![[self class] dynamicallyLoadWebKitIfAvailable]) {
  68. return;
  69. };
  70. WKWebViewConfiguration *wkWebViewConfig = [WKWebViewConfiguration new];
  71. if (_incognito) {
  72. wkWebViewConfig.websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore];
  73. }
  74. if(self.useSharedProcessPool) {
  75. wkWebViewConfig.processPool = [[RNCWKProcessPoolManager sharedManager] sharedProcessPool];
  76. }
  77. wkWebViewConfig.userContentController = [WKUserContentController new];
  78. [wkWebViewConfig.userContentController addScriptMessageHandler: self name: MessageHanderName];
  79. wkWebViewConfig.allowsInlineMediaPlayback = _allowsInlineMediaPlayback;
  80. #if WEBKIT_IOS_10_APIS_AVAILABLE
  81. wkWebViewConfig.mediaTypesRequiringUserActionForPlayback = _mediaPlaybackRequiresUserAction
  82. ? WKAudiovisualMediaTypeAll
  83. : WKAudiovisualMediaTypeNone;
  84. wkWebViewConfig.dataDetectorTypes = _dataDetectorTypes;
  85. #else
  86. wkWebViewConfig.mediaPlaybackRequiresUserAction = _mediaPlaybackRequiresUserAction;
  87. #endif
  88. _webView = [[WKWebView alloc] initWithFrame:self.bounds configuration: wkWebViewConfig];
  89. _webView.scrollView.delegate = self;
  90. _webView.UIDelegate = self;
  91. _webView.navigationDelegate = self;
  92. _webView.scrollView.scrollEnabled = _scrollEnabled;
  93. _webView.scrollView.pagingEnabled = _pagingEnabled;
  94. _webView.scrollView.bounces = _bounces;
  95. _webView.allowsLinkPreview = _allowsLinkPreview;
  96. [_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:nil];
  97. _webView.allowsBackForwardNavigationGestures = _allowsBackForwardNavigationGestures;
  98. if (_userAgent) {
  99. _webView.customUserAgent = _userAgent;
  100. }
  101. #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
  102. if ([_webView.scrollView respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) {
  103. _webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  104. }
  105. #endif
  106. [self addSubview:_webView];
  107. [self setHideKeyboardAccessoryView: _savedHideKeyboardAccessoryView];
  108. [self visitSource];
  109. }
  110. }
  111. - (void)removeFromSuperview
  112. {
  113. if (_webView) {
  114. [_webView.configuration.userContentController removeScriptMessageHandlerForName:MessageHanderName];
  115. [_webView removeObserver:self forKeyPath:@"estimatedProgress"];
  116. [_webView removeFromSuperview];
  117. _webView = nil;
  118. }
  119. [super removeFromSuperview];
  120. }
  121. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
  122. if ([keyPath isEqual:@"estimatedProgress"] && object == self.webView) {
  123. if(_onLoadingProgress){
  124. NSMutableDictionary<NSString *, id> *event = [self baseEvent];
  125. [event addEntriesFromDictionary:@{@"progress":[NSNumber numberWithDouble:self.webView.estimatedProgress]}];
  126. _onLoadingProgress(event);
  127. }
  128. }else{
  129. [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
  130. }
  131. }
  132. - (void)setBackgroundColor:(UIColor *)backgroundColor
  133. {
  134. _savedBackgroundColor = backgroundColor;
  135. if (_webView == nil) {
  136. return;
  137. }
  138. CGFloat alpha = CGColorGetAlpha(backgroundColor.CGColor);
  139. self.opaque = _webView.opaque = (alpha == 1.0);
  140. _webView.scrollView.backgroundColor = backgroundColor;
  141. _webView.backgroundColor = backgroundColor;
  142. }
  143. /**
  144. * This method is called whenever JavaScript running within the web view calls:
  145. * - window.webkit.messageHandlers.[MessageHanderName].postMessage
  146. */
  147. - (void)userContentController:(WKUserContentController *)userContentController
  148. didReceiveScriptMessage:(WKScriptMessage *)message
  149. {
  150. if (_onMessage != nil) {
  151. NSMutableDictionary<NSString *, id> *event = [self baseEvent];
  152. [event addEntriesFromDictionary: @{@"data": message.body}];
  153. _onMessage(event);
  154. }
  155. }
  156. - (void)setSource:(NSDictionary *)source
  157. {
  158. if (![_source isEqualToDictionary:source]) {
  159. _source = [source copy];
  160. if (_webView != nil) {
  161. [self visitSource];
  162. }
  163. }
  164. }
  165. - (void)setContentInset:(UIEdgeInsets)contentInset
  166. {
  167. _contentInset = contentInset;
  168. [RCTView autoAdjustInsetsForView:self
  169. withScrollView:_webView.scrollView
  170. updateOffset:NO];
  171. }
  172. - (void)refreshContentInset
  173. {
  174. [RCTView autoAdjustInsetsForView:self
  175. withScrollView:_webView.scrollView
  176. updateOffset:YES];
  177. }
  178. - (void)visitSource
  179. {
  180. // Check for a static html source first
  181. NSString *html = [RCTConvert NSString:_source[@"html"]];
  182. if (html) {
  183. NSURL *baseURL = [RCTConvert NSURL:_source[@"baseUrl"]];
  184. if (!baseURL) {
  185. baseURL = [NSURL URLWithString:@"about:blank"];
  186. }
  187. [_webView loadHTMLString:html baseURL:baseURL];
  188. return;
  189. }
  190. NSURLRequest *request = [RCTConvert NSURLRequest:_source];
  191. // Because of the way React works, as pages redirect, we actually end up
  192. // passing the redirect urls back here, so we ignore them if trying to load
  193. // the same url. We'll expose a call to 'reload' to allow a user to load
  194. // the existing page.
  195. if ([request.URL isEqual:_webView.URL]) {
  196. return;
  197. }
  198. if (!request.URL) {
  199. // Clear the webview
  200. [_webView loadHTMLString:@"" baseURL:nil];
  201. return;
  202. }
  203. [_webView loadRequest:request];
  204. }
  205. -(void)setHideKeyboardAccessoryView:(BOOL)hideKeyboardAccessoryView
  206. {
  207. if (_webView == nil) {
  208. _savedHideKeyboardAccessoryView = hideKeyboardAccessoryView;
  209. return;
  210. }
  211. if (_savedHideKeyboardAccessoryView == false) {
  212. return;
  213. }
  214. UIView* subview;
  215. for (UIView* view in _webView.scrollView.subviews) {
  216. if([[view.class description] hasPrefix:@"WK"])
  217. subview = view;
  218. }
  219. if(subview == nil) return;
  220. NSString* name = [NSString stringWithFormat:@"%@_SwizzleHelperWK", subview.class.superclass];
  221. Class newClass = NSClassFromString(name);
  222. if(newClass == nil)
  223. {
  224. newClass = objc_allocateClassPair(subview.class, [name cStringUsingEncoding:NSASCIIStringEncoding], 0);
  225. if(!newClass) return;
  226. Method method = class_getInstanceMethod([_SwizzleHelperWK class], @selector(inputAccessoryView));
  227. class_addMethod(newClass, @selector(inputAccessoryView), method_getImplementation(method), method_getTypeEncoding(method));
  228. objc_registerClassPair(newClass);
  229. }
  230. object_setClass(subview, newClass);
  231. }
  232. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  233. {
  234. scrollView.decelerationRate = _decelerationRate;
  235. }
  236. - (void)setScrollEnabled:(BOOL)scrollEnabled
  237. {
  238. _scrollEnabled = scrollEnabled;
  239. _webView.scrollView.scrollEnabled = scrollEnabled;
  240. }
  241. - (void)postMessage:(NSString *)message
  242. {
  243. NSDictionary *eventInitDict = @{@"data": message};
  244. NSString *source = [NSString
  245. stringWithFormat:@"document.dispatchEvent(new MessageEvent('message', %@));",
  246. RCTJSONStringify(eventInitDict, NULL)
  247. ];
  248. [self evaluateJS: source thenCall: nil];
  249. }
  250. - (void)layoutSubviews
  251. {
  252. [super layoutSubviews];
  253. // Ensure webview takes the position and dimensions of RNCWKWebView
  254. _webView.frame = self.bounds;
  255. }
  256. - (NSMutableDictionary<NSString *, id> *)baseEvent
  257. {
  258. NSDictionary *event = @{
  259. @"url": _webView.URL.absoluteString ?: @"",
  260. @"title": _webView.title,
  261. @"loading" : @(_webView.loading),
  262. @"canGoBack": @(_webView.canGoBack),
  263. @"canGoForward" : @(_webView.canGoForward)
  264. };
  265. return [[NSMutableDictionary alloc] initWithDictionary: event];
  266. }
  267. #pragma mark - WKNavigationDelegate methods
  268. /**
  269. * alert
  270. */
  271. - (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
  272. {
  273. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:message preferredStyle:UIAlertControllerStyleAlert];
  274. [alert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  275. completionHandler();
  276. }]];
  277. [[self topViewController] presentViewController:alert animated:YES completion:NULL];
  278. }
  279. /**
  280. * confirm
  281. */
  282. - (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL))completionHandler{
  283. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:message preferredStyle:UIAlertControllerStyleAlert];
  284. [alert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  285. completionHandler(YES);
  286. }]];
  287. [alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  288. completionHandler(NO);
  289. }]];
  290. [[self topViewController] presentViewController:alert animated:YES completion:NULL];
  291. }
  292. /**
  293. * prompt
  294. */
  295. - (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString *))completionHandler{
  296. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:prompt preferredStyle:UIAlertControllerStyleAlert];
  297. [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  298. textField.textColor = [UIColor lightGrayColor];
  299. textField.placeholder = defaultText;
  300. }];
  301. [alert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  302. completionHandler([[alert.textFields lastObject] text]);
  303. }]];
  304. [[self topViewController] presentViewController:alert animated:YES completion:NULL];
  305. }
  306. /**
  307. * topViewController
  308. */
  309. -(UIViewController *)topViewController{
  310.    UIViewController *controller = [self topViewControllerWithRootViewController:[self getCurrentWindow].rootViewController];
  311.    return controller;
  312. }
  313. /**
  314. * topViewControllerWithRootViewController
  315. */
  316. -(UIViewController *)topViewControllerWithRootViewController:(UIViewController *)viewController{
  317. if (viewController==nil) return nil;
  318. if (viewController.presentedViewController!=nil) {
  319. return [self topViewControllerWithRootViewController:viewController.presentedViewController];
  320. } else if ([viewController isKindOfClass:[UITabBarController class]]){
  321. return [self topViewControllerWithRootViewController:[(UITabBarController *)viewController selectedViewController]];
  322. } else if ([viewController isKindOfClass:[UINavigationController class]]){
  323. return [self topViewControllerWithRootViewController:[(UINavigationController *)viewController visibleViewController]];
  324. } else {
  325. return viewController;
  326. }
  327. }
  328. /**
  329. * getCurrentWindow
  330. */
  331. -(UIWindow *)getCurrentWindow{
  332. UIWindow *window = [UIApplication sharedApplication].keyWindow;
  333. if (window.windowLevel!=UIWindowLevelNormal) {
  334. for (UIWindow *wid in [UIApplication sharedApplication].windows) {
  335. if (window.windowLevel==UIWindowLevelNormal) {
  336. window = wid;
  337. break;
  338. }
  339. }
  340. }
  341. return window;
  342. }
  343. /**
  344. * Decides whether to allow or cancel a navigation.
  345. * @see https://fburl.com/42r9fxob
  346. */
  347. - (void) webView:(WKWebView *)webView
  348. decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction
  349. decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
  350. {
  351. static NSDictionary<NSNumber *, NSString *> *navigationTypes;
  352. static dispatch_once_t onceToken;
  353. dispatch_once(&onceToken, ^{
  354. navigationTypes = @{
  355. @(WKNavigationTypeLinkActivated): @"click",
  356. @(WKNavigationTypeFormSubmitted): @"formsubmit",
  357. @(WKNavigationTypeBackForward): @"backforward",
  358. @(WKNavigationTypeReload): @"reload",
  359. @(WKNavigationTypeFormResubmitted): @"formresubmit",
  360. @(WKNavigationTypeOther): @"other",
  361. };
  362. });
  363. WKNavigationType navigationType = navigationAction.navigationType;
  364. NSURLRequest *request = navigationAction.request;
  365. if (_onShouldStartLoadWithRequest) {
  366. NSMutableDictionary<NSString *, id> *event = [self baseEvent];
  367. [event addEntriesFromDictionary: @{
  368. @"url": (request.URL).absoluteString,
  369. @"navigationType": navigationTypes[@(navigationType)]
  370. }];
  371. if (![self.delegate webView:self
  372. shouldStartLoadForRequest:event
  373. withCallback:_onShouldStartLoadWithRequest]) {
  374. decisionHandler(WKNavigationResponsePolicyCancel);
  375. return;
  376. }
  377. }
  378. if (_onLoadingStart) {
  379. // We have this check to filter out iframe requests and whatnot
  380. BOOL isTopFrame = [request.URL isEqual:request.mainDocumentURL];
  381. if (isTopFrame) {
  382. NSMutableDictionary<NSString *, id> *event = [self baseEvent];
  383. [event addEntriesFromDictionary: @{
  384. @"url": (request.URL).absoluteString,
  385. @"navigationType": navigationTypes[@(navigationType)]
  386. }];
  387. _onLoadingStart(event);
  388. }
  389. }
  390. // Allow all navigation by default
  391. decisionHandler(WKNavigationResponsePolicyAllow);
  392. }
  393. /**
  394. * Called when an error occurs while the web view is loading content.
  395. * @see https://fburl.com/km6vqenw
  396. */
  397. - (void) webView:(WKWebView *)webView
  398. didFailProvisionalNavigation:(WKNavigation *)navigation
  399. withError:(NSError *)error
  400. {
  401. if (_onLoadingError) {
  402. if ([error.domain isEqualToString:NSURLErrorDomain] && error.code == NSURLErrorCancelled) {
  403. // NSURLErrorCancelled is reported when a page has a redirect OR if you load
  404. // a new URL in the WebView before the previous one came back. We can just
  405. // ignore these since they aren't real errors.
  406. // http://stackoverflow.com/questions/1024748/how-do-i-fix-nsurlerrordomain-error-999-in-iphone-3-0-os
  407. return;
  408. }
  409. if ([error.domain isEqualToString:@"WebKitErrorDomain"] && error.code == 102) {
  410. // Error code 102 "Frame load interrupted" is raised by the WKWebView
  411. // when the URL is from an http redirect. This is a common pattern when
  412. // implementing OAuth with a WebView.
  413. return;
  414. }
  415. NSMutableDictionary<NSString *, id> *event = [self baseEvent];
  416. [event addEntriesFromDictionary:@{
  417. @"didFailProvisionalNavigation": @YES,
  418. @"domain": error.domain,
  419. @"code": @(error.code),
  420. @"description": error.localizedDescription,
  421. }];
  422. _onLoadingError(event);
  423. }
  424. [self setBackgroundColor: _savedBackgroundColor];
  425. }
  426. - (void)evaluateJS:(NSString *)js
  427. thenCall: (void (^)(NSString*)) callback
  428. {
  429. [self.webView evaluateJavaScript: js completionHandler: ^(id result, NSError *error) {
  430. if (error == nil) {
  431. if (callback != nil) {
  432. callback([NSString stringWithFormat:@"%@", result]);
  433. }
  434. } else {
  435. RCTLogError(@"Error evaluating injectedJavaScript: This is possibly due to an unsupported return type. Try adding true to the end of your injectedJavaScript string.");
  436. }
  437. }];
  438. }
  439. /**
  440. * Called when the navigation is complete.
  441. * @see https://fburl.com/rtys6jlb
  442. */
  443. - (void) webView:(WKWebView *)webView
  444. didFinishNavigation:(WKNavigation *)navigation
  445. {
  446. if (_messagingEnabled) {
  447. #if RCT_DEV
  448. // Implementation inspired by Lodash.isNative.
  449. NSString *isPostMessageNative = @"String(String(window.postMessage) === String(Object.hasOwnProperty).replace('hasOwnProperty', 'postMessage'))";
  450. [self evaluateJS: isPostMessageNative thenCall: ^(NSString *result) {
  451. if (! [result isEqualToString:@"true"]) {
  452. RCTLogError(@"Setting onMessage on a WebView overrides existing values of window.postMessage, but a previous value was defined");
  453. }
  454. }];
  455. #endif
  456. NSString *source = [NSString stringWithFormat:
  457. @"(function() {"
  458. "window.originalPostMessage = window.postMessage;"
  459. "window.postMessage = function(data) {"
  460. "window.webkit.messageHandlers.%@.postMessage(String(data));"
  461. "};"
  462. "})();",
  463. MessageHanderName
  464. ];
  465. [self evaluateJS: source thenCall: nil];
  466. }
  467. if (_injectedJavaScript) {
  468. [self evaluateJS: _injectedJavaScript thenCall: ^(NSString *jsEvaluationValue) {
  469. NSMutableDictionary *event = [self baseEvent];
  470. event[@"jsEvaluationValue"] = jsEvaluationValue;
  471. if (self.onLoadingFinish) {
  472. self.onLoadingFinish(event);
  473. }
  474. }];
  475. } else if (_onLoadingFinish) {
  476. _onLoadingFinish([self baseEvent]);
  477. }
  478. [self setBackgroundColor: _savedBackgroundColor];
  479. }
  480. - (void)injectJavaScript:(NSString *)script
  481. {
  482. [self evaluateJS: script thenCall: nil];
  483. }
  484. - (void)goForward
  485. {
  486. [_webView goForward];
  487. }
  488. - (void)goBack
  489. {
  490. [_webView goBack];
  491. }
  492. - (void)reload
  493. {
  494. /**
  495. * When the initial load fails due to network connectivity issues,
  496. * [_webView reload] doesn't reload the webpage. Therefore, we must
  497. * manually call [_webView loadRequest:request].
  498. */
  499. NSURLRequest *request = [RCTConvert NSURLRequest:self.source];
  500. if (request.URL && !_webView.URL.absoluteString.length) {
  501. [_webView loadRequest:request];
  502. }
  503. else {
  504. [_webView reload];
  505. }
  506. }
  507. - (void)stopLoading
  508. {
  509. [_webView stopLoading];
  510. }
  511. - (void)setBounces:(BOOL)bounces
  512. {
  513. _bounces = bounces;
  514. _webView.scrollView.bounces = bounces;
  515. }
  516. @end