|
6 | 6 | */ |
7 | 7 |
|
8 | 8 | #import "RNCWebViewImpl.h" |
| 9 | +#import "RNCAssetSchemeHandler.h" |
9 | 10 | #import <React/RCTConvert.h> |
10 | 11 | #import <React/RCTAutoInsetsProtocol.h> |
11 | 12 | #import "RNCWKProcessPoolManager.h" |
@@ -181,6 +182,8 @@ - (instancetype)initWithFrame:(CGRect)frame |
181 | 182 | _injectedJavaScriptBeforeContentLoaded = nil; |
182 | 183 | _injectedJavaScriptBeforeContentLoadedForMainFrameOnly = YES; |
183 | 184 | _enableApplePay = NO; |
| 185 | + _scrollsToTop = YES; |
| 186 | + _dragInteractionEnabled = YES; |
184 | 187 | #if TARGET_OS_IOS |
185 | 188 | _savedStatusBarStyle = RCTSharedApplication().statusBarStyle; |
186 | 189 | _savedStatusBarHidden = RCTSharedApplication().statusBarHidden; |
@@ -509,6 +512,11 @@ - (WKWebViewConfiguration *)setUpWkWebViewConfig |
509 | 512 | wkWebViewConfig.applicationNameForUserAgent = [NSString stringWithFormat:@"%@ %@", wkWebViewConfig.applicationNameForUserAgent, _applicationNameForUserAgent]; |
510 | 513 | } |
511 | 514 |
|
| 515 | + // Register custom URL scheme handler to serve app bundle assets (fonts, etc.) |
| 516 | + // from WKWebView pages loaded with about:blank origin, which can't access file:// URLs. |
| 517 | + RNCAssetSchemeHandler *assetHandler = [[RNCAssetSchemeHandler alloc] init]; |
| 518 | + [wkWebViewConfig setURLSchemeHandler:assetHandler forURLScheme:@"rw-asset"]; |
| 519 | + |
512 | 520 | return wkWebViewConfig; |
513 | 521 | } |
514 | 522 |
|
@@ -545,6 +553,7 @@ - (void)didMoveToWindow |
545 | 553 | } |
546 | 554 |
|
547 | 555 | _webView.scrollView.directionalLockEnabled = _directionalLockEnabled; |
| 556 | + _webView.scrollView.scrollsToTop = _scrollsToTop; |
548 | 557 | #endif // !TARGET_OS_OSX |
549 | 558 | _webView.allowsLinkPreview = _allowsLinkPreview; |
550 | 559 | [_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:nil]; |
@@ -740,6 +749,11 @@ - (void)setBackgroundColor:(RCTUIColor *)backgroundColor |
740 | 749 | #endif // !TARGET_OS_OSX |
741 | 750 | } |
742 | 751 |
|
| 752 | +- (void)setTintColor:(UIColor *)tintColor |
| 753 | +{ |
| 754 | + _webView.tintColor = tintColor; |
| 755 | +} |
| 756 | + |
743 | 757 | #if !TARGET_OS_OSX |
744 | 758 | - (void)setContentInsetAdjustmentBehavior:(UIScrollViewContentInsetAdjustmentBehavior)behavior |
745 | 759 | { |
@@ -1106,6 +1120,25 @@ - (void)setIndicatorStyle:(NSString *)indicatorStyle |
1106 | 1120 | _webView.scrollView.indicatorStyle = UIScrollViewIndicatorStyleDefault; |
1107 | 1121 | } |
1108 | 1122 | } |
| 1123 | + |
| 1124 | +- (void)setScrollsToTop:(BOOL)scrollsToTop |
| 1125 | +{ |
| 1126 | + _scrollsToTop = scrollsToTop; |
| 1127 | + _webView.scrollView.scrollsToTop = scrollsToTop; |
| 1128 | +} |
| 1129 | + |
| 1130 | +- (void)setDragInteractionEnabled:(BOOL)dragInteractionEnabled |
| 1131 | +{ |
| 1132 | + _dragInteractionEnabled = dragInteractionEnabled; |
| 1133 | + if (@available(iOS 11.0, *)) { |
| 1134 | + for (id interaction in _webView.scrollView.interactions) { |
| 1135 | + if ([interaction isKindOfClass:[UIDragInteraction class]]) { |
| 1136 | + ((UIDragInteraction *)interaction).enabled = dragInteractionEnabled; |
| 1137 | + } |
| 1138 | + } |
| 1139 | + } |
| 1140 | +} |
| 1141 | + |
1109 | 1142 | #endif // !TARGET_OS_OSX |
1110 | 1143 |
|
1111 | 1144 | - (void)postMessage:(NSString *)message |
|
0 commit comments