Нема описа

RNCWKWebView.m 19KB

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