Skip to content

Commit

Permalink
Merge tag 'v11.2.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
ouabing committed Mar 16, 2021
2 parents 44d9abe + 4c71ff2 commit 0ec9180
Show file tree
Hide file tree
Showing 26 changed files with 2,666 additions and 3,560 deletions.
2 changes: 1 addition & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"projectName": "react-native-webview",
"projectOwner": "react-native-community",
"projectOwner": "react-native-webview",
"repoType": "github",
"repoHost": "https://github.com",
"files": [
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v1
- uses: actions/stale@v3.0.14
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like _still searching for solutions_ and if you found one, please open a pull request! You have 7 days until this gets closed automatically'
stale-pr-message: 'Hello 👋, this PR has been opened for more than 2 months with no activity on it. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically'
exempt-issue-label: 'Keep opened'
exempt-pr-label: 'Keep opened'
remove-stale-when-updated: true
6 changes: 2 additions & 4 deletions .github/workflows/windows-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ jobs:
node-version: '12.9.1'

- name: Setup MSBuild
uses: microsoft/[email protected]
with:
vs-version: 16.5
uses: microsoft/[email protected]

- name: Check node modules cache
uses: actions/cache@v1
Expand Down Expand Up @@ -58,4 +56,4 @@ jobs:
run: Start-Process PowerShell -ArgumentList "yarn appium"

- name: Run tests
run: yarn test:windows
run: yarn test:windows
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# React Native WebView - a Modern, Cross-Platform WebView for React Native

[![star this repo](http://githubbadges.com/star.svg?user=react-native-community&repo=react-native-webview&style=flat)](https://github.com/react-native-community/react-native-webview)
[![star this repo](http://githubbadges.com/star.svg?user=react-native-webview&repo=react-native-webview&style=flat)](https://github.com/react-native-webview/react-native-webview)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
[![All Contributors](https://img.shields.io/badge/all_contributors-16-orange.svg?style=flat-square)](#contributors)
[![Known Vulnerabilities](https://snyk.io/test/github/react-native-community/react-native-webview/badge.svg?style=flat-square)](https://snyk.io/test/github/react-native-community/react-native-webview)
[![Known Vulnerabilities](https://snyk.io/test/github/react-native-webview/react-native-webview/badge.svg?style=flat-square)](https://snyk.io/test/github/react-native-webview/react-native-webview)
[![NPM Version](https://img.shields.io/npm/v/react-native-webview.svg?style=flat-square)](https://www.npmjs.com/package/react-native-webview)
[![Lean Core Extracted](https://img.shields.io/badge/Lean%20Core-Extracted-brightgreen.svg?style=flat-square)][lean-core-issue]

Expand Down Expand Up @@ -37,19 +37,20 @@ This project follows [semantic versioning](https://semver.org/). We do not hesit

Current Version: ![version](https://img.shields.io/npm/v/react-native-webview.svg)

- [10.0.0](https://github.com/react-native-community/react-native-webview/releases/tag/v10.0.0) - Android Gradle plugin is only required when opening the project stand-alone
- [9.0.0](https://github.com/react-native-community/react-native-webview/releases/tag/v9.0.0) - props updates to injectedJavaScript are no longer immutable.
- [8.0.0](https://github.com/react-native-community/react-native-webview/releases/tag/v8.0.0) - onNavigationStateChange now triggers with hash url changes
- [7.0.1](https://github.com/react-native-community/react-native-webview/releases/tag/v7.0.1) - Removed UIWebView
- [6.0.**2**](https://github.com/react-native-community/react-native-webview/releases/tag/v6.0.2) - Update to AndroidX. Make sure to enable it in your project's `android/gradle.properties`. See [Getting Started Guide](docs/Getting-Started.md).
- [5.0.**1**](https://github.com/react-native-community/react-native-webview/releases/tag/v5.0.0) - Refactored the old postMessage implementation for communication from webview to native.
- [4.0.0](https://github.com/react-native-community/react-native-webview/releases/tag/v4.0.0) - Added cache (enabled by default).
- [3.0.0](https://github.com/react-native-community/react-native-webview/releases/tag/v3.0.0) - WKWebview: Add shared process pool so cookies and localStorage are shared across webviews in iOS (enabled by default).
- [2.0.0](https://github.com/react-native-community/react-native-webview/releases/tag/v2.0.0) - First release this is a replica of the core webview component
- [11.0.0](https://github.com/react-native-webview/react-native-webview/releases/tag/v11.0.0) - Android setSupportMultipleWindows.
- [10.0.0](https://github.com/react-native-webview/react-native-webview/releases/tag/v10.0.0) - Android Gradle plugin is only required when opening the project stand-alone
- [9.0.0](https://github.com/react-native-webview/react-native-webview/releases/tag/v9.0.0) - props updates to injectedJavaScript are no longer immutable.
- [8.0.0](https://github.com/react-native-webview/react-native-webview/releases/tag/v8.0.0) - onNavigationStateChange now triggers with hash url changes
- [7.0.1](https://github.com/react-native-webview/react-native-webview/releases/tag/v7.0.1) - Removed UIWebView
- [6.0.**2**](https://github.com/react-native-webview/react-native-webview/releases/tag/v6.0.2) - Update to AndroidX. Make sure to enable it in your project's `android/gradle.properties`. See [Getting Started Guide](docs/Getting-Started.md).
- [5.0.**1**](https://github.com/react-native-webview/react-native-webview/releases/tag/v5.0.0) - Refactored the old postMessage implementation for communication from webview to native.
- [4.0.0](https://github.com/react-native-webview/react-native-webview/releases/tag/v4.0.0) - Added cache (enabled by default).
- [3.0.0](https://github.com/react-native-webview/react-native-webview/releases/tag/v3.0.0) - WKWebview: Add shared process pool so cookies and localStorage are shared across webviews in iOS (enabled by default).
- [2.0.0](https://github.com/react-native-webview/react-native-webview/releases/tag/v2.0.0) - First release this is a replica of the core webview component

**Upcoming:**

- this.webView.postMessage() removal (never documented and less flexible than injectJavascript) -> [how to migrate](https://github.com/react-native-community/react-native-webview/issues/809)
- this.webView.postMessage() removal (never documented and less flexible than injectJavascript) -> [how to migrate](https://github.com/react-native-webview/react-native-webview/issues/809)
- Kotlin rewrite
- Maybe Swift rewrite

Expand Down Expand Up @@ -78,7 +79,7 @@ For more, read the [API Reference](./docs/Reference.md) and [Guide](./docs/Guide

## Contributing

See [Contributing.md](https://github.com/react-native-community/react-native-webview/blob/master/docs/Contributing.md)
See [Contributing.md](https://github.com/react-native-webview/react-native-webview/blob/master/docs/Contributing.md)

## Contributors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.Message;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Log;
Expand Down Expand Up @@ -189,6 +190,7 @@ protected WebView createViewInstance(ThemedReactContext reactContext) {
settings.setBuiltInZoomControls(true);
settings.setDisplayZoomControls(false);
settings.setDomStorageEnabled(true);
settings.setSupportMultipleWindows(true);

settings.setAllowFileAccess(false);
settings.setAllowContentAccess(false);
Expand Down Expand Up @@ -254,6 +256,11 @@ public void setJavaScriptEnabled(WebView view, boolean enabled) {
view.getSettings().setJavaScriptEnabled(enabled);
}

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

@ReactProp(name = "showsHorizontalScrollIndicator")
public void setShowsHorizontalScrollIndicator(WebView view, boolean enabled) {
view.setHorizontalScrollBarEnabled(enabled);
Expand Down Expand Up @@ -737,8 +744,25 @@ public void onShowCustomView(View view, CustomViewCallback callback) {
}

mVideoView.setBackgroundColor(Color.BLACK);
getRootView().addView(mVideoView, FULLSCREEN_LAYOUT_PARAMS);
mWebView.setVisibility(View.GONE);

// since RN's Modals interfere with the View hierarchy
// we will decide which View to Hide if the hierarchy
// does not match (i.e., the webview is within a Modal)
// NOTE: We could use mWebView.getRootView() instead of getRootView()
// but that breaks the Modal's styles and layout, so we need this to render
// in the main View hierarchy regardless.
ViewGroup rootView = getRootView();
rootView.addView(mVideoView, FULLSCREEN_LAYOUT_PARAMS);

// Different root views, we are in a Modal
if(rootView.getRootView() != mWebView.getRootView()){
mWebView.getRootView().setVisibility(View.GONE);
}

// Same view hierarchy (no Modal), just hide the webview then
else{
mWebView.setVisibility(View.GONE);
}

WritableMap eventData = Arguments.createMap();
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
Expand All @@ -752,18 +776,28 @@ public void onHideCustomView() {
return;
}

mVideoView.setVisibility(View.GONE);
getRootView().removeView(mVideoView);
mCustomViewCallback.onCustomViewHidden();
// same logic as above
ViewGroup rootView = getRootView();

mVideoView = null;
mCustomViewCallback = null;
if(rootView.getRootView() != mWebView.getRootView()){
mWebView.getRootView().setVisibility(View.VISIBLE);
}

mWebView.setVisibility(View.VISIBLE);
// Same view hierarchy (no Modal)
else{
mWebView.setVisibility(View.VISIBLE);
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mReactContext.getCurrentActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}

rootView.removeView(mVideoView);
mCustomViewCallback.onCustomViewHidden();

mVideoView = null;
mCustomViewCallback = null;

mReactContext.getCurrentActivity().setRequestedOrientation(initialRequestedOrientation);

WritableMap eventData = Arguments.createMap();
Expand Down Expand Up @@ -891,7 +925,7 @@ public void onReceivedSslError(final WebView webView, final SslErrorHandler hand
// This is desired behavior. We later use these values to determine whether the request is a top-level navigation or a subresource request.
String topWindowUrl = webView.getUrl();
String failingUrl = error.getUrl();

// Cancel request after obtaining top-level URL.
// If request is cancelled before obtaining top-level URL, undesired behavior may occur.
// Undesired behavior: Return value of WebView.getUrl() may be the current URL instead of the failing URL.
Expand Down Expand Up @@ -1089,6 +1123,17 @@ public RNCWebChromeClient(ReactContext reactContext, WebView webView) {
this.mWebView = webView;
}

@Override
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {

final WebView newWebView = new WebView(view.getContext());
final WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(newWebView);
resultMsg.sendToTarget();

return true;
}

@Override
public boolean onConsoleMessage(ConsoleMessage message) {
if (ReactBuildConfig.DEBUG) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected enum ShouldOverrideCallbackState {
DO_NOT_OVERRIDE,
}

private int nextLockIdentifier = 0;
private int nextLockIdentifier = 1;
private final HashMap<Integer, AtomicReference<ShouldOverrideCallbackState>> shouldOverrideLocks = new HashMap<>();

public synchronized Pair<Integer, AtomicReference<ShouldOverrideCallbackState>> getNewLock() {
Expand Down
1 change: 1 addition & 0 deletions apple/RNCWebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
@property (nonatomic, assign) BOOL javaScriptEnabled;
@property (nonatomic, assign) BOOL javaScriptCanOpenWindowsAutomatically;
@property (nonatomic, assign) BOOL allowFileAccessFromFileURLs;
@property (nonatomic, assign) BOOL allowUniversalAccessFromFileURLs;
@property (nonatomic, assign) BOOL allowsLinkPreview;
@property (nonatomic, assign) BOOL showsHorizontalScrollIndicator;
@property (nonatomic, assign) BOOL showsVerticalScrollIndicator;
Expand Down
48 changes: 42 additions & 6 deletions apple/RNCWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ @implementation RNCWebView
BOOL _savedKeyboardDisplayRequiresUserAction;

// Workaround for StatusBar appearance bug for iOS 12
// https://github.com/react-native-community/react-native-webview/issues/62
// https://github.com/react-native-webview/react-native-webview/issues/62
BOOL _isFullScreenVideoOpen;
#if !TARGET_OS_OSX
UIStatusBarStyle _savedStatusBarStyle;
Expand All @@ -109,6 +109,9 @@ @implementation RNCWebView
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
UIScrollViewContentInsetAdjustmentBehavior _savedContentInsetAdjustmentBehavior;
#endif
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* __IPHONE_13_0 */
BOOL _savedAutomaticallyAdjustsScrollIndicatorInsets;
#endif
}

- (instancetype)initWithFrame:(CGRect)frame
Expand Down Expand Up @@ -140,6 +143,10 @@ - (instancetype)initWithFrame:(CGRect)frame
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
_savedContentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
#endif
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* __IPHONE_13_0 */
_savedAutomaticallyAdjustsScrollIndicatorInsets = NO;
#endif

}

#if !TARGET_OS_OSX
Expand All @@ -165,7 +172,7 @@ - (instancetype)initWithFrame:(CGRect)frame
name:UIKeyboardWillShowNotification object:nil];

// Workaround for StatusBar appearance bug for iOS 12
// https://github.com/react-native-community/react-native-webview/issues/62
// https://github.com/react-native-webview/react-native-webview/issues/62
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(showFullScreenVideoStatusBars)
name:UIWindowDidBecomeVisibleNotification
Expand Down Expand Up @@ -206,6 +213,9 @@ - (WKWebViewConfiguration *)setUpWkWebViewConfig
prefs.javaScriptEnabled = NO;
_prefsUsed = YES;
}
if (_allowUniversalAccessFromFileURLs) {
[wkWebViewConfig setValue:@TRUE forKey:@"allowUniversalAccessFromFileURLs"];
}
if (_allowFileAccessFromFileURLs) {
[prefs setValue:@TRUE forKey:@"allowFileAccessFromFileURLs"];
_prefsUsed = YES;
Expand Down Expand Up @@ -282,7 +292,7 @@ - (void)didMoveToWindow
_webView.scrollView.scrollEnabled = _scrollEnabled;
_webView.scrollView.pagingEnabled = _pagingEnabled;
//For UIRefreshControl to work correctly, the bounces should always be true
_webView.scrollView.bounces = _pullToRefreshEnabled || _bounces;
_webView.scrollView.bounces = _pullToRefreshEnabled || _bounces;
_webView.scrollView.showsHorizontalScrollIndicator = _showsHorizontalScrollIndicator;
_webView.scrollView.showsVerticalScrollIndicator = _showsVerticalScrollIndicator;
_webView.scrollView.directionalLockEnabled = _directionalLockEnabled;
Expand All @@ -299,6 +309,11 @@ - (void)didMoveToWindow
_webView.scrollView.contentInsetAdjustmentBehavior = _savedContentInsetAdjustmentBehavior;
}
#endif
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* __IPHONE_13_0 */
if (@available(iOS 13.0, *)) {
_webView.scrollView.automaticallyAdjustsScrollIndicatorInsets = _savedAutomaticallyAdjustsScrollIndicatorInsets;
}
#endif

[self addSubview:_webView];
[self setHideKeyboardAccessoryView: _savedHideKeyboardAccessoryView];
Expand All @@ -316,6 +331,7 @@ - (void)setAllowsBackForwardNavigationGestures:(BOOL)allowsBackForwardNavigation
- (void)removeFromSuperview
{
if (_webView) {
[_webView.configuration.userContentController removeScriptMessageHandlerForName:HistoryShimName];
[_webView.configuration.userContentController removeScriptMessageHandlerForName:MessageHandlerName];
[_webView removeObserver:self forKeyPath:@"estimatedProgress"];
[_webView removeFromSuperview];
Expand Down Expand Up @@ -445,7 +461,17 @@ - (void)setContentInsetAdjustmentBehavior:(UIScrollViewContentInsetAdjustmentBeh
}
}
#endif

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* __IPHONE_13_0 */
- (void)setAutomaticallyAdjustsScrollIndicatorInsets:(BOOL)automaticallyAdjustsScrollIndicatorInsets{
_savedAutomaticallyAdjustsScrollIndicatorInsets = automaticallyAdjustsScrollIndicatorInsets;
if (_webView == nil) {
return;
}
if ([_webView.scrollView respondsToSelector:@selector(setAutomaticallyAdjustsScrollIndicatorInsets:)]) {
_webView.scrollView.automaticallyAdjustsScrollIndicatorInsets = automaticallyAdjustsScrollIndicatorInsets;
}
}
#endif
/**
* This method is called whenever JavaScript running within the web view calls:
* - window.webkit.messageHandlers[MessageHandlerName].postMessage
Expand Down Expand Up @@ -518,6 +544,16 @@ - (void)visitSource
}
[_webView loadHTMLString:html baseURL:baseURL];
return;
}
//Add cookie for subsequent resource requests sent by page itself, if cookie was set in headers on WebView
NSString *headerCookie = [RCTConvert NSString:_source[@"headers"][@"cookie"]];
if(headerCookie) {
NSDictionary *headers = [NSDictionary dictionaryWithObjectsAndKeys:headerCookie,@"Set-Cookie",nil];
NSURL *urlString = [NSURL URLWithString:_source[@"uri"]];
NSArray *httpCookies = [NSHTTPCookie cookiesWithResponseHeaderFields:headers forURL:urlString];
for (NSHTTPCookie *httpCookie in httpCookies) {
[_webView.configuration.websiteDataStore.httpCookieStore setCookie:httpCookie completionHandler:nil];
}
}

NSURLRequest *request = [self requestForSource:_source];
Expand Down Expand Up @@ -1155,7 +1191,7 @@ - (void)pullToRefresh:(UIRefreshControl *)refreshControl
- (void)setPullToRefreshEnabled:(BOOL)pullToRefreshEnabled
{
_pullToRefreshEnabled = pullToRefreshEnabled;

if (pullToRefreshEnabled) {
[self addPullToRefreshControl];
} else {
Expand Down Expand Up @@ -1356,7 +1392,7 @@ - (NSURLRequest *)requestForSource:(id)json {
if (_sharedCookiesEnabled) {
if (@available(iOS 11.0, *)) {
// see WKWebView initialization for added cookies
} else {
} else if (request != nil) {
NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:request.URL];
NSDictionary<NSString *, NSString *> *cookieHeader = [NSHTTPCookie requestHeaderFieldsWithCookies:cookies];
NSMutableURLRequest *mutableRequest = [request mutableCopy];
Expand Down
Loading

0 comments on commit 0ec9180

Please sign in to comment.