From a0d64e1d86fafa3b3a72908dda0e51f8bd066359 Mon Sep 17 00:00:00 2001 From: Kudo Chien Date: Wed, 8 Sep 2021 10:26:58 +0800 Subject: [PATCH] [android][ios] Update react-native-webview to 11.13.0 (#14301) # 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 #13461 #14265 - `et update-vendored-module -m react-native-webview -c v11.13.0` - add `androidx.webkit` gradle dependency: https://github.com/react-native-webview/react-native-webview/commit/19980d888d66554875f3ac64b3e8a35bd7ad998b#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`). --- CHANGELOG.md | 1 + android/expoview/build.gradle | 3 ++ .../components/webview/RNCWebViewManager.java | 52 +++++++++++++++++++ apps/bare-expo/package.json | 2 +- apps/native-component-list/package.json | 2 +- ios/Podfile.lock | 4 +- .../apple/RNCWKProcessPoolManager.h | 2 +- .../react-native-webview/apple/RNCWebView.m | 10 ++-- .../apple/RNCWebViewManager.m | 5 +- .../react-native-webview.podspec.json | 4 +- packages/expo/bundledNativeModules.json | 2 +- tools/src/vendoring/config/expoGoConfig.ts | 30 ++++++----- 12 files changed, 91 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5626068a1d3328..f9ec3a7e11e61e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/android/expoview/build.gradle b/android/expoview/build.gradle index 5907d954afff62..a86b26ffce550d 100644 --- a/android/expoview/build.gradle +++ b/android/expoview/build.gradle @@ -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" } diff --git a/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/components/webview/RNCWebViewManager.java b/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/components/webview/RNCWebViewManager.java index 30b02c66419620..f7de01c0f0e565 100644 --- a/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/components/webview/RNCWebViewManager.java +++ b/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/components/webview/RNCWebViewManager.java @@ -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; @@ -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; @@ -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); @@ -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) { @@ -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" 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 @@ -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; /** @@ -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 @@ -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); diff --git a/apps/bare-expo/package.json b/apps/bare-expo/package.json index 152df6496d7d68..1ac3a39a89143c 100644 --- a/apps/bare-expo/package.json +++ b/apps/bare-expo/package.json @@ -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": { diff --git a/apps/native-component-list/package.json b/apps/native-component-list/package.json index 51a11fdcd52e4f..6c2b40e922e849 100644 --- a/apps/native-component-list/package.json +++ b/apps/native-component-list/package.json @@ -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", diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 61695f42b3774a..65e8ed5299ada3 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -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): @@ -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 diff --git a/ios/vendored/unversioned/react-native-webview/apple/RNCWKProcessPoolManager.h b/ios/vendored/unversioned/react-native-webview/apple/RNCWKProcessPoolManager.h index 6bfe648086f5ed..49ad20915f5e14 100644 --- a/ios/vendored/unversioned/react-native-webview/apple/RNCWKProcessPoolManager.h +++ b/ios/vendored/unversioned/react-native-webview/apple/RNCWKProcessPoolManager.h @@ -9,7 +9,7 @@ @interface RNCWKProcessPoolManager : NSObject -+ (instancetype)sharedManager; ++ (instancetype) sharedManager; - (WKProcessPool *)sharedProcessPoolForScopeKey:(NSString *)scopeKey; @end diff --git a/ios/vendored/unversioned/react-native-webview/apple/RNCWebView.m b/ios/vendored/unversioned/react-native-webview/apple/RNCWebView.m index 1495032451fe0b..e8f1005a78ad34 100644 --- a/ios/vendored/unversioned/react-native-webview/apple/RNCWebView.m +++ b/ios/vendored/unversioned/react-native-webview/apple/RNCWebView.m @@ -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; @@ -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; diff --git a/ios/vendored/unversioned/react-native-webview/apple/RNCWebViewManager.m b/ios/vendored/unversioned/react-native-webview/apple/RNCWebViewManager.m index 5acc7a045c10c5..f3dd25646e6af1 100644 --- a/ios/vendored/unversioned/react-native-webview/apple/RNCWebViewManager.m +++ b/ios/vendored/unversioned/react-native-webview/apple/RNCWebViewManager.m @@ -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) @@ -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]; } diff --git a/ios/vendored/unversioned/react-native-webview/react-native-webview.podspec.json b/ios/vendored/unversioned/react-native-webview/react-native-webview.podspec.json index 51d65359bd9eb9..4dadfe204c2b14 100644 --- a/ios/vendored/unversioned/react-native-webview/react-native-webview.podspec.json +++ b/ios/vendored/unversioned/react-native-webview/react-native-webview.podspec.json @@ -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 ", @@ -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": { diff --git a/packages/expo/bundledNativeModules.json b/packages/expo/bundledNativeModules.json index b7f577f2e1d1bd..a1e2771793cc43 100644 --- a/packages/expo/bundledNativeModules.json +++ b/packages/expo/bundledNativeModules.json @@ -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", diff --git a/tools/src/vendoring/config/expoGoConfig.ts b/tools/src/vendoring/config/expoGoConfig.ts index 4d43497c67d309..cc4afa40f7c868 100644 --- a/tools/src/vendoring/config/expoGoConfig.ts +++ b/tools/src/vendoring/config/expoGoConfig.ts @@ -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', @@ -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; }`,