Skip to content

Commit

Permalink
feat(webview): Allow javascript to open windows automatically (#1409 by
Browse files Browse the repository at this point in the history
@trcoffman)

[skip ci]
  • Loading branch information
trcoffman committed May 28, 2020
1 parent 3cbf149 commit 91df544
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,11 @@ public void setMediaPlaybackRequiresUserAction(WebView view, boolean requires) {
view.getSettings().setMediaPlaybackRequiresUserGesture(requires);
}

@ReactProp(name = "javaScriptCanOpenWindowsAutomatically")
public void setJavaScriptCanOpenWindowsAutomatically(WebView view, boolean enabled) {
view.getSettings().setJavaScriptCanOpenWindowsAutomatically(enabled);
}

@ReactProp(name = "allowFileAccessFromFileURLs")
public void setAllowFileAccessFromFileURLs(WebView view, boolean allow) {
view.getSettings().setAllowFileAccessFromFileURLs(allow);
Expand Down
1 change: 1 addition & 0 deletions apple/RNCWebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
@property (nonatomic, copy) NSString * _Nullable applicationNameForUserAgent;
@property (nonatomic, assign) BOOL cacheEnabled;
@property (nonatomic, assign) BOOL javaScriptEnabled;
@property (nonatomic, assign) BOOL javaScriptCanOpenWindowsAutomatically;
@property (nonatomic, assign) BOOL allowFileAccessFromFileURLs;
@property (nonatomic, assign) BOOL allowsLinkPreview;
@property (nonatomic, assign) BOOL showsHorizontalScrollIndicator;
Expand Down
4 changes: 4 additions & 0 deletions apple/RNCWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ - (WKWebViewConfiguration *)setUpWkWebViewConfig
[prefs setValue:@TRUE forKey:@"allowFileAccessFromFileURLs"];
_prefsUsed = YES;
}
if (_javaScriptCanOpenWindowsAutomatically) {
[prefs setValue:@TRUE forKey:@"javaScriptCanOpenWindowsAutomatically"];
_prefsUsed = YES;
}
if (_prefsUsed) {
wkWebViewConfig.preferences = prefs;
}
Expand Down
1 change: 1 addition & 0 deletions apple/RNCWebViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ - (RCTUIView *)view
RCT_EXPORT_VIEW_PROPERTY(injectedJavaScriptForMainFrameOnly, BOOL)
RCT_EXPORT_VIEW_PROPERTY(injectedJavaScriptBeforeContentLoadedForMainFrameOnly, BOOL)
RCT_EXPORT_VIEW_PROPERTY(javaScriptEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(javaScriptCanOpenWindowsAutomatically, BOOL)
RCT_EXPORT_VIEW_PROPERTY(allowFileAccessFromFileURLs, BOOL)
RCT_EXPORT_VIEW_PROPERTY(allowsInlineMediaPlayback, BOOL)
RCT_EXPORT_VIEW_PROPERTY(mediaPlaybackRequiresUserAction, BOOL)
Expand Down
11 changes: 11 additions & 0 deletions docs/Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ This document lays out the current public properties and methods for the React N
- [`decelerationRate`](Reference.md#decelerationrate)
- [`domStorageEnabled`](Reference.md#domstorageenabled)
- [`javaScriptEnabled`](Reference.md#javascriptenabled)
- [`javaScriptCanOpenWindowsAutomatically`](Reference.md#javascriptcanopenwindowsautomatically)
- [`androidHardwareAccelerationDisabled`](Reference.md#androidHardwareAccelerationDisabled)
- [`mixedContentMode`](Reference.md#mixedcontentmode)
- [`thirdPartyCookiesEnabled`](Reference.md#thirdpartycookiesenabled)
Expand Down Expand Up @@ -732,6 +733,16 @@ Boolean value to enable JavaScript in the `WebView`. The default value is `true`

---

### `javaScriptCanOpenWindowsAutomatically`

A Boolean value indicating whether JavaScript can open windows without user interaction. The default value is `false`.

| Type | Required |
| ---- | -------- |
| bool | No |

---

### `androidHardwareAccelerationDisabled`

Boolean value to disable Hardware Acceleration in the `WebView`. Used on Android only as Hardware Acceleration is a feature only for Android. The default value is `false`.
Expand Down
7 changes: 7 additions & 0 deletions src/WebViewTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export interface CommonNativeWebViewProps extends ViewProps {
incognito?: boolean;
injectedJavaScript?: string;
injectedJavaScriptBeforeContentLoaded?: string;
javaScriptCanOpenWindowsAutomatically?: boolean;
mediaPlaybackRequiresUserAction?: boolean;
messagingEnabled: boolean;
onScroll?: (event: NativeScrollEvent) => void;
Expand Down Expand Up @@ -821,6 +822,12 @@ export interface WebViewSharedProps extends ViewProps {
*/
javaScriptEnabled?: boolean;

/**
* A Boolean value indicating whether JavaScript can open windows without user interaction.
* The default value is `false`.
*/
javaScriptCanOpenWindowsAutomatically?: boolean;

/**
* Stylesheet object to set the style of the container view.
*/
Expand Down

0 comments on commit 91df544

Please sign in to comment.