feat(ios): Add support for `limitsNavigationsToAppBoundDomains` (#1662)

* Add support for iOS-specific prop `limitsNavigationsToAppBoundDomains`

* Add check for `limitsNavigationsToAppBoundDomains` property

Turns out that @available is simply bugged right
now in Xcode and will pretty much always return
`true`. Adding a check for the property actually
existing as well will avoid iOS <14 crashing horribly.

* Improve documentation

Co-authored-by: Thibault Malbranche <thibault.malbranche@epitech.eu>
This commit is contained in:
Ivari Tölp 2021-03-17 01:29:40 +02:00 committed by GitHub
parent 2aa8cee5ee
commit 7decc5cff1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 0 deletions

View File

@ -76,6 +76,10 @@
@property (nonatomic, assign) WKContentMode contentMode;
#endif
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000 /* iOS 14 */
@property (nonatomic, assign) BOOL limitsNavigationsToAppBoundDomains;
#endif
+ (void)setClientAuthenticationCredential:(nullable NSURLCredential*)credential;
+ (void)setCustomCertificatesForHost:(nullable NSDictionary *)certificates;
- (void)postMessage:(NSString *_Nullable)message;

View File

@ -245,6 +245,16 @@ static NSDictionary* customCertificatesForHost;
}
#endif
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000 /* iOS 14 */
if (@available(iOS 14.0, *)) {
if ([wkWebViewConfig respondsToSelector:@selector(limitsNavigationsToAppBoundDomains)]) {
if (_limitsNavigationsToAppBoundDomains) {
wkWebViewConfig.limitsNavigationsToAppBoundDomains = YES;
}
}
}
#endif
// Shim the HTML5 history API:
[wkWebViewConfig.userContentController addScriptMessageHandler:[[RNCWeakScriptMessageDelegate alloc] initWithDelegate:self]
name:HistoryShimName];

View File

@ -89,6 +89,10 @@ RCT_EXPORT_VIEW_PROPERTY(automaticallyAdjustsScrollIndicatorInsets, BOOL)
RCT_EXPORT_VIEW_PROPERTY(contentMode, WKContentMode)
#endif
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000 /* iOS 14 */
RCT_EXPORT_VIEW_PROPERTY(limitsNavigationsToAppBoundDomains, BOOL)
#endif
/**
* Expose methods to enable messaging the webview.
*/

View File

@ -73,6 +73,7 @@ This document lays out the current public properties and methods for the React N
- [`pullToRefreshEnabled`](Reference.md#pullToRefreshEnabled)
- [`ignoreSilentHardwareSwitch`](Reference.md#ignoreSilentHardwareSwitch)
- [`onFileDownload`](Reference.md#onFileDownload)
- [`limitsNavigationsToAppBoundDomains`](Reference.md#limitsNavigationsToAppBoundDomains)
- [`autoManageStatusBarEnabled`](Reference.md#autoManageStatusBarEnabled)
- [`setSupportMultipleWindows`](Reference.md#setSupportMultipleWindows)
@ -1314,6 +1315,25 @@ Example:
---
### `limitsNavigationsToAppBoundDomains`[](#props-index)<!-- Link generated with jump2header -->
If true indicates to WebKit that a WKWebView will only navigate to app-bound domains. Only applicable for iOS 14 or greater.
Once set, any attempt to navigate away from an app-bound domain will fail with the error “App-bound domain failure.”
Applications can specify up to 10 “app-bound” domains using a new Info.plist key `WKAppBoundDomains`. For more information see [App-Bound Domains](https://webkit.org/blog/10882/app-bound-domains/).
| Type | Required | Platform |
| ------- | -------- | -------- |
| boolean | No | iOS |
Example:
```jsx
<WebView limitsNavigationsToAppBoundDomains={true} />
```
---
### `autoManageStatusBarEnabled`
If set to `true`, the status bar will be automatically hidden/shown by WebView, specifically when full screen video is being watched. If `false`, WebView will not manage the status bar at all. The default value is `true`.

View File

@ -332,6 +332,7 @@ export interface IOSNativeWebViewProps extends CommonNativeWebViewProps {
injectedJavaScriptForMainFrameOnly?: boolean;
injectedJavaScriptBeforeContentLoadedForMainFrameOnly?: boolean;
onFileDownload?: (event: FileDownloadEvent) => void;
limitsNavigationsToAppBoundDomains?: boolean;
}
export interface MacOSNativeWebViewProps extends CommonNativeWebViewProps {
@ -614,6 +615,17 @@ export interface IOSWebViewProps extends WebViewSharedProps {
* If not provided, the default is to let the webview try to render the file.
*/
onFileDownload?: (event: FileDownloadEvent) => void;
/**
* A Boolean value which, when set to `true`, indicates to WebKit that a WKWebView
* will only navigate to app-bound domains. Once set, any attempt to navigate away
* from an app-bound domain will fail with the error App-bound domain failure.
*
* Applications can specify up to 10 app-bound domains using a new
* Info.plist key `WKAppBoundDomains`.
* @platform ios
*/
limitsNavigationsToAppBoundDomains?: boolean;
}
export interface MacOSWebViewProps extends WebViewSharedProps {