mirror of
https://github.com/status-im/react-native-webview.git
synced 2026-08-31 03:31:05 +00:00
feat(WKWebview): Add 'userAgent' property to the iOS WKWebView. (#112)
* Add 'userAgent' property to the iOS WKWebView * Update 'userAgent' reference docs.
This commit is contained in:
committed by
Thibault Malbranche
parent
24572d01a3
commit
2ec5fa514e
+2
-2
@@ -332,11 +332,11 @@ Boolean value to enable third party cookies in the `WebView`. Used on Android Lo
|
||||
|
||||
### `userAgent`
|
||||
|
||||
Sets the user-agent for the `WebView`.
|
||||
Sets the user-agent for the `WebView`. This will only work for iOS if you are using WKWebView, not UIWebView (see https://developer.apple.com/documentation/webkit/wkwebview/1414950-customuseragent).
|
||||
|
||||
| Type | Required | Platform |
|
||||
| ------ | -------- | -------- |
|
||||
| string | No | Android |
|
||||
| string | No | Android, iOS WKWebView |
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
|
||||
@property (nonatomic, assign) BOOL automaticallyAdjustContentInsets;
|
||||
@property (nonatomic, assign) BOOL hideKeyboardAccessoryView;
|
||||
@property (nonatomic, assign) BOOL allowsBackForwardNavigationGestures;
|
||||
@property (nonatomic, copy) NSString *userAgent;
|
||||
|
||||
- (void)postMessage:(NSString *)message;
|
||||
- (void)injectJavaScript:(NSString *)script;
|
||||
|
||||
+3
-1
@@ -103,7 +103,9 @@ static NSString *const MessageHanderName = @"ReactNative";
|
||||
_webView.scrollView.bounces = _bounces;
|
||||
[_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:nil];
|
||||
_webView.allowsBackForwardNavigationGestures = _allowsBackForwardNavigationGestures;
|
||||
|
||||
if (_userAgent) {
|
||||
_webView.customUserAgent = _userAgent;
|
||||
}
|
||||
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
|
||||
if ([_webView.scrollView respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) {
|
||||
_webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
||||
|
||||
@@ -45,6 +45,7 @@ RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets)
|
||||
RCT_EXPORT_VIEW_PROPERTY(automaticallyAdjustContentInsets, BOOL)
|
||||
RCT_EXPORT_VIEW_PROPERTY(hideKeyboardAccessoryView, BOOL)
|
||||
RCT_EXPORT_VIEW_PROPERTY(allowsBackForwardNavigationGestures, BOOL)
|
||||
RCT_EXPORT_VIEW_PROPERTY(userAgent, NSString)
|
||||
|
||||
/**
|
||||
* Expose methods to enable messaging the webview.
|
||||
|
||||
@@ -271,6 +271,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
|
||||
}
|
||||
hideKeyboardAccessoryView={this.props.hideKeyboardAccessoryView}
|
||||
allowsBackForwardNavigationGestures={this.props.allowsBackForwardNavigationGestures}
|
||||
userAgent={this.props.userAgent}
|
||||
onLoadingStart={this._onLoadingStart}
|
||||
onLoadingFinish={this._onLoadingFinish}
|
||||
onLoadingError={this._onLoadingError}
|
||||
|
||||
@@ -229,6 +229,10 @@ export type IOSWebViewProps = $ReadOnly<{|
|
||||
* back-forward list navigations.
|
||||
*/
|
||||
allowsBackForwardNavigationGestures?: ?boolean,
|
||||
/**
|
||||
* The custom user agent string.
|
||||
*/
|
||||
userAgent?: ?string,
|
||||
|}>;
|
||||
|
||||
export type AndroidWebViewProps = $ReadOnly<{|
|
||||
|
||||
Reference in New Issue
Block a user