Skip to content

Commit

Permalink
[android][ios] Update react-native-webview to 11.13.0 (expo#14301)
Browse files Browse the repository at this point in the history
# Why

update vendored module for sdk 43
close [ENG-1892](https://linear.app/expo/issue/ENG-1892/upgrade-react-native-webview)

# How

- fix `tools/src/vendoring/config/expoGoConfig.ts` breaking where the initialized selector should be `initWithExperienceStableLegacyId:scopeKey:easProjectId:kernelServiceDelegate:params:`.
  related changes
  expo#13461
  expo#14265 
- `et update-vendored-module -m react-native-webview -c v11.13.0`
- add `androidx.webkit` gradle dependency: react-native-webview/react-native-webview@19980d8#diff-197b190e4a3512994d2cebed8aff5479ff88e136b8cc7a4b148ec9c3945bd65aR139

# Test Plan

- [x] expo go android unversioned + NCL webview component test
- [x] expo go android versioned + NCL webview component test
- [x] expo go ios unversioned + NCL webview component test
- [x] expo go ios versioned + NCL webview component test

# Checklist

- [x] Documentation is up to date to reflect these changes (eg: https://docs.expo.io and README.md).
- [x] This diff will work correctly for `expo build` (eg: updated `@expo/xdl`).
  • Loading branch information
Kudo authored Sep 8, 2021
1 parent b928618 commit a0d64e1
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Package-specific changes not released in any SDK will be added here just before

- Updated `react-native-shared-element` from `0.7.0` to `0.8.2`. ([#14245](https://github.com/expo/expo/pull/14245) by [@IjzerenHein](https://github.com/IjzerenHein))
- Updated `firebase` from `8.2.3` to `8.10.0`. ([#14259](https://github.com/expo/expo/pull/14259) by [@IjzerenHein](https://github.com/IjzerenHein))
- Updated `react-native-webview` from `11.6.2` to `11.13.0`. ([#14301](https://github.com/expo/expo/pull/14301) by [@kudo](https://github.com/kudo))

### 🛠 Breaking changes

Expand Down
3 changes: 3 additions & 0 deletions android/expoview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ dependencies {
// stripe-react-native
implementation 'com.stripe:stripe-android:16.10.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0'

// react-native-webview
implementation "androidx.webkit:webkit:1.4.0"
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
Expand All @@ -45,6 +46,8 @@
import androidx.annotation.RequiresApi;
import androidx.core.content.ContextCompat;
import androidx.core.util.Pair;
import androidx.webkit.WebSettingsCompat;
import androidx.webkit.WebViewFeature;

import com.facebook.common.logging.FLog;
import com.facebook.react.modules.core.PermissionAwareActivity;
Expand Down Expand Up @@ -252,6 +255,16 @@ public void setJavaScriptEnabled(WebView view, boolean enabled) {
view.getSettings().setJavaScriptEnabled(enabled);
}

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

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

@ReactProp(name = "setSupportMultipleWindows")
public void setSupportMultipleWindows(WebView view, boolean enabled){
view.getSettings().setSupportMultipleWindows(enabled);
Expand Down Expand Up @@ -343,6 +356,11 @@ public void setOverScrollMode(WebView view, String overScrollModeString) {
view.setOverScrollMode(overScrollMode);
}

@ReactProp(name = "nestedScrollEnabled")
public void setNestedScrollEnabled(WebView view, boolean enabled) {
((RNCWebView) view).setNestedScrollEnabled(enabled);
}

@ReactProp(name = "thirdPartyCookiesEnabled")
public void setThirdPartyCookiesEnabled(WebView view, boolean enabled) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Expand Down Expand Up @@ -593,6 +611,27 @@ public void setOnScroll(WebView view, boolean hasScrollEvent) {
((RNCWebView) view).setHasScrollEvent(hasScrollEvent);
}

@ReactProp(name = "forceDarkOn")
public void setForceDarkOn(WebView view, boolean enabled) {
// Only Android 10+ support dark mode
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
// Switch WebView dark mode
if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {
int forceDarkMode = enabled ? WebSettingsCompat.FORCE_DARK_ON : WebSettingsCompat.FORCE_DARK_OFF;
WebSettingsCompat.setForceDark(view.getSettings(), forceDarkMode);
}

// Set how WebView content should be darkened.
// PREFER_WEB_THEME_OVER_USER_AGENT_DARKENING: checks for the "color-scheme" <meta> tag.
// If present, it uses media queries. If absent, it applies user-agent (automatic)
// More information about Force Dark Strategy can be found here:
// https://developer.android.com/reference/androidx/webkit/WebSettingsCompat#setForceDarkStrategy(android.webkit.WebSettings)
if (enabled && WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK_STRATEGY)) {
WebSettingsCompat.setForceDarkStrategy(view.getSettings(), WebSettingsCompat.DARK_STRATEGY_PREFER_WEB_THEME_OVER_USER_AGENT_DARKENING);
}
}
}

@Override
protected void addEventEmitters(ThemedReactContext reactContext, WebView view) {
// Do not register default touch emitter and let WebView implementation handle touches
Expand Down Expand Up @@ -1405,6 +1444,7 @@ protected static class RNCWebView extends WebView implements LifecycleEventListe
protected boolean sendContentSizeChangeEvents = false;
private OnScrollDispatchHelper mOnScrollDispatchHelper;
protected boolean hasScrollEvent = false;
protected boolean nestedScrollEnabled = false;
protected ProgressChangedFilter progressChangedFilter;

/**
Expand All @@ -1431,6 +1471,10 @@ public void setHasScrollEvent(boolean hasScrollEvent) {
this.hasScrollEvent = hasScrollEvent;
}

public void setNestedScrollEnabled(boolean nestedScrollEnabled) {
this.nestedScrollEnabled = nestedScrollEnabled;
}

@Override
public void onHostResume() {
// do nothing
Expand All @@ -1446,6 +1490,14 @@ public void onHostDestroy() {
cleanupCallbacksAndDestroy();
}

@Override
public boolean onTouchEvent(MotionEvent event) {
if (this.nestedScrollEnabled) {
requestDisallowInterceptTouchEvent(true);
}
return super.onTouchEvent(event);
}

@Override
protected void onSizeChanged(int w, int h, int ow, int oh) {
super.onSizeChanged(w, h, ow, oh);
Expand Down
2 changes: 1 addition & 1 deletion apps/bare-expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"react-native-svg": "12.1.1",
"react-native-unimodules": "~0.15.0-alpha.0",
"react-native-view-shot": "3.1.2",
"react-native-webview": "11.6.2",
"react-native-webview": "11.13.0",
"test-suite": "*"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion apps/native-component-list/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
"react-native-unimodules": "~0.15.0-alpha.0",
"react-native-view-shot": "3.1.2",
"react-native-web": "~0.17.1",
"react-native-webview": "11.6.2",
"react-native-webview": "11.13.0",
"react-navigation": "^4.4.0",
"react-navigation-shared-element": "^3.1.2",
"react-navigation-stack": "^2.8.2",
Expand Down
4 changes: 2 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2328,7 +2328,7 @@ PODS:
- React-jsi (= 0.64.2)
- React-perflogger (= 0.64.2)
- React-jsinspector (0.64.2)
- react-native-webview (11.6.2):
- react-native-webview (11.13.0):
- React-Core
- React-perflogger (0.64.2)
- React-RCTActionSheet (0.64.2):
Expand Down Expand Up @@ -4201,7 +4201,7 @@ SPEC CHECKSUMS:
React-jsi: 67747b9722f6dab2ffe15b011bcf6b3f2c3f1427
React-jsiexecutor: 80c46bd381fd06e418e0d4f53672dc1d1945c4c3
React-jsinspector: cc614ec18a9ca96fd275100c16d74d62ee11f0ae
react-native-webview: 193d233c29eacce1f42ca2637dab7ba79c25a6de
react-native-webview: 133a6a5149f963259646e710b4545c67ef35d7c9
React-perflogger: 25373e382fed75ce768a443822f07098a15ab737
React-RCTActionSheet: af7796ba49ffe4ca92e7277a5d992d37203f7da5
React-RCTAnimation: 6a2e76ab50c6f25b428d81b76a5a45351c4d77aa
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@interface RNCWKProcessPoolManager : NSObject

+ (instancetype)sharedManager;
+ (instancetype) sharedManager;
- (WKProcessPool *)sharedProcessPoolForScopeKey:(NSString *)scopeKey;

@end
10 changes: 7 additions & 3 deletions ios/vendored/unversioned/react-native-webview/apple/RNCWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,7 @@ - (void)didMoveToWindow
[_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:nil];
_webView.allowsBackForwardNavigationGestures = _allowsBackForwardNavigationGestures;

if (_userAgent) {
_webView.customUserAgent = _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 = _savedContentInsetAdjustmentBehavior;
Expand Down Expand Up @@ -701,6 +699,12 @@ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
}
#endif // !TARGET_OS_OSX

- (void)setUserAgent:(NSString*)userAgent
{
_userAgent = userAgent;
_webView.customUserAgent = userAgent;
}

- (void)setScrollEnabled:(BOOL)scrollEnabled
{
_scrollEnabled = scrollEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ - (RCTUIView *)view
RCT_EXPORT_VIEW_PROPERTY(allowsBackForwardNavigationGestures, BOOL)
RCT_EXPORT_VIEW_PROPERTY(incognito, BOOL)
RCT_EXPORT_VIEW_PROPERTY(pagingEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(userAgent, NSString)
RCT_EXPORT_VIEW_PROPERTY(applicationNameForUserAgent, NSString)
RCT_EXPORT_VIEW_PROPERTY(cacheEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(allowsLinkPreview, BOOL)
Expand Down Expand Up @@ -137,6 +136,10 @@ - (RCTUIView *)view
view.useSharedProcessPool = json == nil ? true : [RCTConvert BOOL: json];
}

RCT_CUSTOM_VIEW_PROPERTY(userAgent, NSString, RNCWebView) {
view.userAgent = [RCTConvert NSString: json];
}

RCT_CUSTOM_VIEW_PROPERTY(scrollEnabled, BOOL, RNCWebView) {
view.scrollEnabled = json == nil ? true : [RCTConvert BOOL: json];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-webview",
"version": "11.6.2",
"version": "11.13.0",
"summary": "React Native WebView component for iOS, Android, macOS, and Windows",
"license": "MIT",
"authors": "Jamon Holmgren <[email protected]>",
Expand All @@ -11,7 +11,7 @@
},
"source": {
"git": "https://github.com/react-native-webview/react-native-webview.git",
"tag": "v11.6.2"
"tag": "v11.13.0"
},
"source_files": "apple/**/*.{h,m}",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/expo/bundledNativeModules.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"react-native-svg": "12.1.1",
"react-native-unimodules": "~0.15.0-alpha.0",
"react-native-view-shot": "3.1.2",
"react-native-webview": "11.6.2",
"react-native-webview": "11.13.0",
"sentry-expo": "^4.0.0",
"unimodules-app-loader": "~2.3.0-alpha.0",
"unimodules-image-loader-interface": "~6.1.0",
Expand Down
30 changes: 16 additions & 14 deletions tools/src/vendoring/config/expoGoConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const config: VendoringTargetConfig = {
paths: 'RNCWKProcessPoolManager.h',
find: '- (WKProcessPool *)sharedProcessPool;',
replaceWith:
'- (WKProcessPool *)sharedProcessPoolForExperienceScopeKey:(NSString *)experienceScopeKey;',
'- (WKProcessPool *)sharedProcessPoolForScopeKey:(NSString *)scopeKey;',
},
{
paths: 'RNCWKProcessPoolManager.m',
Expand All @@ -111,48 +111,50 @@ const config: VendoringTargetConfig = {
return self;
}
- (WKProcessPool *)sharedProcessPoolForExperienceScopeKey:(NSString *)experienceScopeKey
- (WKProcessPool *)sharedProcessPoolForScopeKey:(NSString *)scopeKey
{
if (!experienceScopeKey) {
if (!scopeKey) {
return [self sharedProcessPool];
}
if (!_pools[experienceScopeKey]) {
_pools[experienceScopeKey] = [[WKProcessPool alloc] init];
if (!_pools[scopeKey]) {
_pools[scopeKey] = [[WKProcessPool alloc] init];
}
return _pools[experienceScopeKey];
return _pools[scopeKey];
}
`,
},
{
paths: 'RNCWebView.h',
find: /@interface RNCWebView : RCTView/,
replaceWith: '$&\n@property (nonatomic, strong) NSString *experienceScopeKey;',
replaceWith: '$&\n@property (nonatomic, strong) NSString *scopeKey;',
},
{
paths: 'RNCWebView.m',
find: /(\[\[RNCWKProcessPoolManager sharedManager\] sharedProcessPool)]/,
replaceWith: '$1ForExperienceScopeKey:self.experienceScopeKey]',
replaceWith: '$1ForScopeKey:self.scopeKey]',
},
{
paths: 'RNCWebViewManager.m',
find: /@implementation RNCWebViewManager\s*{/,
replaceWith: '$&\n NSString *_experienceScopeKey;',
replaceWith: '$&\n NSString *_scopeKey;',
},
{
paths: 'RNCWebViewManager.m',
find: '*webView = [RNCWebView new];',
replaceWith:
'*webView = [RNCWebView new];\n webView.experienceScopeKey = _experienceScopeKey;',
'*webView = [RNCWebView new];\n webView.scopeKey = _scopeKey;',
},
{
paths: 'RNCWebViewManager.m',
find: /RCT_EXPORT_MODULE\(\)/,
replaceWith: `- (instancetype)initWithExperienceScopeKey:(NSString *)experienceScopeKey
kernelServiceDelegate:(id)kernelServiceInstance
params:(NSDictionary *)params
replaceWith: `- (instancetype)initWithExperienceStableLegacyId:(NSString *)experienceStableLegacyId
scopeKey:(NSString *)scopeKey
easProjectId:(NSString *)easProjectId
kernelServiceDelegate:(id)kernelServiceInstance
params:(NSDictionary *)params
{
if (self = [super init]) {
_experienceScopeKey = experienceScopeKey;
_scopeKey = scopeKey;
}
return self;
}`,
Expand Down

0 comments on commit a0d64e1

Please sign in to comment.